xunit

.net core projects code coverage visual studio 2017

梦想的初衷 提交于 2019-12-02 18:08: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 to report code coverage. Question 2 : Also when I right clicked to debug 1 of my unit test. It

Likeness - polishing and packaging

Deadly 提交于 2019-12-02 12:01:22
问题 I'm using Ploeh.SemanticComparison 's Likeness as a way to effectively express intended outputs of a mapping process (as described in Mark Seemann's excellent Advanced Unit Testing course on PluralSight). I'm testing some data has mapped correctly, which looks like this: [Theory, AutoData] static void ShouldYieldIdentifierUpdatedEvent( Vendor sut, string name, string version, Guid id ) { var result = sut.SyncProduct( name, version, id ); var expected = new { ProductId = id, Name = name,

How to use Microsoft.Extensions.Configuration.IConiguration in my XUnit unit testing

寵の児 提交于 2019-12-02 06:04:29
问题 In my Asp.net Core 2.0 application, I am trying to unit test my data service layer (.Net Standard Class Library) that uses the Microsoft.Extensions.Configuration.IConfiguration dependency injection. I am using XUnit and don't know how to pass IConfiguration from my unit test class. I tried the following implementation and getting the error Message: The following constructor parameters did not have matching fixture data: IConfiguration configuration. I am really new to the testing frameworks

.Net core testing with Xunit

懵懂的女人 提交于 2019-12-02 04:44:51
问题 This is the first time I am writing test case and I am not sort of stuck and not sure how to proceed further. I have the following API. In the below sample I have 2 endpoints which I want to perform testing. public class ValuesController : Controller { //This interface is used to setup dynamo db and connection to aws private IDynamoDbClientInitialization _clientAccessor; private static string dynamoDbTable = string.Empty; public ValuesController(IOptions<Dictionary<string, string>>

Likeness - polishing and packaging

梦想与她 提交于 2019-12-02 04:15:00
I'm using Ploeh.SemanticComparison 's Likeness as a way to effectively express intended outputs of a mapping process (as described in Mark Seemann's excellent Advanced Unit Testing course on PluralSight ). I'm testing some data has mapped correctly, which looks like this: [Theory, AutoData] static void ShouldYieldIdentifierUpdatedEvent( Vendor sut, string name, string version, Guid id ) { var result = sut.SyncProduct( name, version, id ); var expected = new { ProductId = id, Name = name, Version = version }; expected.AsSource().OfLikeness<NewMappingsEvent>() .Without( y => y

How can I use IConfiguration from my integration tests?

本小妞迷上赌 提交于 2019-12-02 03:34:16
问题 I have an API, and I'm trying to make some integration tests for it with XUnit. Here's my API controller constructor: public class MyController : Controller { readonly IMyRepository _myRepository; public MyController(IMyRepository myRepository) { _myRepository = myRepository; } public async Task<IActionResult> GetUser(Guid userId) { try { return Ok(await _my.GetUser(userId)); } catch (Exception ex) { return StatusCode(500, "An error occurred while handling your request."); } } } My API

How to use Microsoft.Extensions.Configuration.IConiguration in my XUnit unit testing

穿精又带淫゛_ 提交于 2019-12-02 03:07:27
In my Asp.net Core 2.0 application, I am trying to unit test my data service layer (.Net Standard Class Library) that uses the Microsoft.Extensions.Configuration.IConfiguration dependency injection. I am using XUnit and don't know how to pass IConfiguration from my unit test class. I tried the following implementation and getting the error Message: The following constructor parameters did not have matching fixture data: IConfiguration configuration. I am really new to the testing frameworks and don't even know if dependency injection can be used as I am trying to do in my code snippet. My Unit

ASP.Net Core unit testing async controller [duplicate]

99封情书 提交于 2019-12-02 02:13:57
问题 This question already has answers here : How to mock an async repository with Entity Framework Core (4 answers) Closed 4 months ago . I have this test: [Fact] public async void Can_Paginate() { //fake data var product1 = new Product { ProductId = 1, ProductName = "P1" }; var product2 = new Product { ProductId = 2, ProductName = "Product 2" }; var product3 = new Product { ProductId = 3, ProductName = "Product 3" }; var product4 = new Product { ProductId = 4, ProductName = "Product 4" }; var

xUnit async tests shows up as “External” in VS2015

橙三吉。 提交于 2019-12-02 01:57:41
I have problems with all my async xUnit tests showing up as External in the Test Explorer in VS2015. They will still run when calling Run All in the test explorer, but as they are considered external almost all of the VS2015 integration does not work, e.g. the navigation (click in test explorer to get to test) is not working, the Run/Debug Tests in the context menu never triggers the test, test status icons doesn't show and Code Lens won't find these tests. The async tests are using the following pattern: [Fact] public async Task AsyncTestMethod() { // Arrange var sot = new Sot(); var result =

.Net core testing with Xunit

▼魔方 西西 提交于 2019-12-02 01:41:48
This is the first time I am writing test case and I am not sort of stuck and not sure how to proceed further. I have the following API. In the below sample I have 2 endpoints which I want to perform testing. public class ValuesController : Controller { //This interface is used to setup dynamo db and connection to aws private IDynamoDbClientInitialization _clientAccessor; private static string dynamoDbTable = string.Empty; public ValuesController(IOptions<Dictionary<string, string>> appSettings, IDynamoDbClientInitialization clientAccessor) { var vals = appSettings.Value; dynamoDbTable = vals[