xunit

ASP.Net Core unit testing async controller [duplicate]

元气小坏坏 提交于 2019-12-02 00:35:23
This question already has an answer here: How to mock an async repository with Entity Framework Core 4 answers 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 product5 = new Product { ProductId = 5, ProductName = "Product 5" }; var data = new List<Product> { product1, product2, product3

How to run XUnit test using data from a CSV file

混江龙づ霸主 提交于 2019-12-01 21:28:00
Is there a way to run a data driven XUnit test using a CSV file as the data source? I've tried Cavity.Data.XUnit , but it's no longer compatible with the newest version of XUnit . So far, I've only been able to achieve this using Excel files, but I need to change them to CSV instead. Any help is greatly appreciated. An example: [Theory] [ExcelData(@"Settings\TestFileParam.xls", "Select url, username, password, from TestData")] //^Replace with a CSV file instead public void Tester_Method(string url, string username, string password) { //Code reading the data from CSV Assert.True(something); }

Handle netstandard1.6 with xUnit

风流意气都作罢 提交于 2019-12-01 16:41:40
问题 I am looking to use a test framework for a netstandard1.6 library. I tried to follow and edit Getting started with xUnit.net (.NET Core / ASP.NET Core) without success. Follow the xUnit's tutorial with a dotnetcore lib on VS 2015 Update 3 RTM with my project.json file to reproduce the error. project.json : { "version": "1.0.0-*", "testRunner": "xunit", "dependencies": { "NETStandard.Library": "1.6.0", "xunit": "2.2.0-beta2-build3300", "dotnet-test-xunit": "2.2.0-preview2-build1029" },

How to Unit Test with ActionResult<T>?

会有一股神秘感。 提交于 2019-12-01 16:19:13
I have a xUnit test like: [Fact] public async void GetLocationsCountAsync_WhenCalled_ReturnsLocationsCount() { _locationsService.Setup(s => s.GetLocationsCountAsync("123")).ReturnsAsync(10); var controller = new LocationsController(_locationsService.Object, null) { ControllerContext = { HttpContext = SetupHttpContext().Object } }; var actionResult = await controller.GetLocationsCountAsync(); actionResult.Value.Should().Be(10); VerifyAll(); } Source is /// <summary> /// Get the current number of locations for a user. /// </summary> /// <returns>A <see cref="int"></see>.</returns> /// <response

Visual Studio 2015 Test Explorer does not see XUnit dnx traits

人盡茶涼 提交于 2019-12-01 16:09:23
The Visual Studio 2015 Test Explorer does not recognize my test traits. When I add this to a test in a DNX project: [Trait("Category", "Test")] the test still shows up in the Test Explorer under the No Traits group (when grouping tests by Traits). Looks like this is already logged as an issue: VS 2015 Bugs - Traits and Project Grouping in Test Explorer #485 来源: https://stackoverflow.com/questions/32258618/visual-studio-2015-test-explorer-does-not-see-xunit-dnx-traits

How to Unit Test with ActionResult<T>?

偶尔善良 提交于 2019-12-01 15:26:20
问题 I have a xUnit test like: [Fact] public async void GetLocationsCountAsync_WhenCalled_ReturnsLocationsCount() { _locationsService.Setup(s => s.GetLocationsCountAsync("123")).ReturnsAsync(10); var controller = new LocationsController(_locationsService.Object, null) { ControllerContext = { HttpContext = SetupHttpContext().Object } }; var actionResult = await controller.GetLocationsCountAsync(); actionResult.Value.Should().Be(10); VerifyAll(); } Source is /// <summary> /// Get the current number

.NET Core 1.0 - How to run “All tests in Solution” with xUnit command line

走远了吗. 提交于 2019-12-01 13:58:54
问题 The Getting started with xUnit.net (.NET Core / ASP.NET Core) page describes how to run tests with dotnet test command line. It states that it requires a specific project.json , where we add xunit dependencies and test runner: "testRunner": "xunit", "dependencies": { "xunit": "2.1.0", "dotnet-test-xunit": "1.0.0-rc2-build10015" } If I try calling it from the parent directory: C:\git\Project\test [master ≡]> dotnet test dotnet-test Error: 0 : System.InvalidOperationException: C:\git\Project

XUnit DI through overridden Startup file (.net core)

流过昼夜 提交于 2019-12-01 06:53:18
I have build a WebAPI and apart from my tests running on Postman I would like to implement some Integration/Unit tests. Now my business logic is very thin, most of the time its more of CRUD actions, therefore I wanted to start with testing my Controllers. I have a basic setup. Repository pattern (interfaces), Services (business logic) and Controllers. The flow goes Controller (DI Service) -> Service (DI Repo) -> Repo Action! So what I did was override my Startup file to change into a in memory database and the rest should be fine (I would assume) Services are added, repos are added and now I

XUnit DI through overridden Startup file (.net core)

懵懂的女人 提交于 2019-12-01 05:59:06
问题 I have build a WebAPI and apart from my tests running on Postman I would like to implement some Integration/Unit tests. Now my business logic is very thin, most of the time its more of CRUD actions, therefore I wanted to start with testing my Controllers. I have a basic setup. Repository pattern (interfaces), Services (business logic) and Controllers. The flow goes Controller (DI Service) -> Service (DI Repo) -> Repo Action! So what I did was override my Startup file to change into a in

In F# how do you pass a collection to xUnit's InlineData attribute

江枫思渺然 提交于 2019-11-30 20:09:40
I would like to be about to use a list, array, and/or seq as a parameter to xUnit's InlineData. In C# I can do this: using Xunit; //2.1.0 namespace CsTests { public class Tests { [Theory] [InlineData(new[] {1, 2})] public void GivenCollectionItMustPassItToTest(int[] coll) { Assert.Equal(coll, coll); } } } In F# I have this: namespace XunitTests module Tests = open Xunit //2.1.0 [<Theory>] [<InlineData(8)>] [<InlineData(42)>] let ``given a value it must give it to the test`` (value : int) = Assert.Equal(value, value) [<Theory>] [<InlineData([1; 2])>] let ``given a list it should be able to pass