xunit

xunit test for IFormFile field in Asp.net Core

风流意气都作罢 提交于 2019-12-22 06:42:13
问题 I have an Asp.net Core method with below definition. [HttpPost] public IActionResult Upload(IFormFile file) { if (file == null || file.Length == 0) throw new Exception("file should not be null"); var originalFileName = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); file.SaveAs("your_file_full_address"); } I want to create XUnit Test for this function, how could I mock IFormFile ? Update: Controller: [HttpPost] public async Task<ActionResult> Post(IFormFile

Separate In Memory Databases EF7

北战南征 提交于 2019-12-22 05:47:05
问题 Is there any way to create a separate (isolated) instance of an EF7 In Memory Database? I am using the In Memory Database in Entity Framework 7 in my unit tests written in xUnit. I would like to be able to run the tests in parallel but this isn't really possible since it seems like the same in memory database is used for all the tests. What I would like is for each test to have its on isolated in memory database that isn't shared with the other tests that run in parallel. 回答1: In EF Core you

Running xunit.net tests in VSTS

泄露秘密 提交于 2019-12-22 04:16:21
问题 I have an issue running xunit.net tests in VSTS . When running the Build plan, the Test assemblies step produces the following log: 2017-03-21T12:11:39.3302859Z ##[section]Starting: Test Assemblies 2017-03-21T12:11:39.3382932Z ============================================================================== 2017-03-21T12:11:39.3382932Z Task : Visual Studio Test 2017-03-21T12:11:39.3382932Z Description : Run tests with Visual Studio test runner 2017-03-21T12:11:39.3382932Z Version : 1.0.84 2017

Xunit Unit Tests will not run

杀马特。学长 韩版系。学妹 提交于 2019-12-22 01:27:16
问题 I am completely stuck on this issue. So my team has a unit test project in a services test project. The tests are discovered in the test explorer pane however when I try and run the tests I get these errors: 'Multiple test adapters with the same uri 'executor://xunit/VsTestRunner2' were found. Ignoring adapter 'Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner'. Please uninstall the conflicting adapter(s) to avoid this warning' '[xUnit.net 00:00:00.0251250] Skipping: (could not find

CasperJs + jenkins : when a test fails, how to retrieve all information on this test

徘徊边缘 提交于 2019-12-21 12:39:03
问题 Well , I would like to know how to get back the information of a test failed in jenkins. Here the result of my folder (fr) (it displays 22 min. but in parallel it's 3min) : Here the description of the test failed -jenkins- : Here the description of the test failed -casper- : So my problem is jenkins displays only the message of the test failed, and I would like to have also useful information as line and code (in fact there is the console output but it's not convenient-> I've changed my mine,

VS2015 Code Coverage not working with tests in ASP.NET Core 1.0 (formerly known as ASP.NET 5)

谁都会走 提交于 2019-12-21 10:33:29
问题 I have a an ASP.NET Core 1.0 (previously known as ASP.NET 5) solution with a couple of Class Library (Package)'s and an ASP.NET MVC6 project. I have a test library using the new XUnit 2.0 which supports Core 1.0. However, for some reason my code coverage is producing zero results when running it on all of my tests which are passing. By default, ASP.NET Core 1.0 projects are built in-memory by the runtime and no artifacts are persisted to disk. So in the settings I enabled "Produce all outputs

How to test for exceptions thrown using xUnit, SubSpec and FakeItEasy

回眸只為那壹抹淺笑 提交于 2019-12-21 03:33:36
问题 I’m using xUnit, SubSpec and FakeItEasy for my unit tests. I’ve so far created some positive unit tests like the following: "Given a Options presenter" .Context(() => presenter = new OptionsPresenter(view, A<IOptionsModel>.Ignored, service)); "with the Initialize method called to retrieve the option values" .Do(() => presenter.Initialize()); "expect the view not to be null" .Observation(() => Assert.NotNull(view)); "expect the view AutoSave property to be true" .Observation(() => Assert.True

xUnit Equivelant of MSTest's Assert.Inconclusive

元气小坏坏 提交于 2019-12-21 03:14:12
问题 What is the xUnit equivalent of the following MSTest code: Assert.Inconclusive("Reason"); This gives a yellow test result instead of the usual green or red. I want to assert that the test could not be run due to certain conditions and that the test should be re-run after those conditions have been met. 回答1: One way is to use the Skip parameter within the Fact or Theory attributes. [Fact(Skip = "It's not ready yet")] public void ReplaceTokensUnfinished() { var original = ""; var expected = "";

How to run setup code only once in an xUnit.net test

放肆的年华 提交于 2019-12-20 16:54:06
问题 I'm trying to setup my tests using Xunit. I have a requirement to delete all images in a folder start of the tests, and then each method does some image resizing and saves a copy of it's output to the folder. The folder should only be emptied once, and then each method will save their own image into the folder. When I use IUseFixture<T> , the ClearVisualTestResultFolder function is still being called before every test, so I only end up with one image in the folder. public class Fixture {

.net core projects code coverage visual studio 2017

。_饼干妹妹 提交于 2019-12-20 09:15:57
问题 I am using Visual Studio Enterprise 2017 to develop my .net core projects. My solution also has some unit test projects and I want to view my current Code coverage. When I clicked Test -> Analyze Code Coverage -> All tests. All my unit tests ran but in Code Coverage Results it only reported code coverage for my unit test projects which doesn't make any sense to me. Question 1 : Do you guys experience the same issue with me? Any solution for this? I also need to set up build definition in VSTS