xunit.net

How to unit test ActionFilterAttribute

半世苍凉 提交于 2020-04-05 17:48:32
问题 I'm looking to test an ActionFilterAttribute in a .NET Core 2.0 API project and wondering the best way to go about it. Note, I'm not trying to test this through a controller action, merely test the ActionFilterAttribute itself. How might I go about testing this: public class ValidateModelAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { if (!context.ModelState.IsValid) { context.Result = new BadRequestObjectResult(context.ModelState);

Unable to find testhost.dll. Please publish your test project and retry

大城市里の小女人 提交于 2020-03-17 09:49:12
问题 I have a simple dotnet core class library with a single XUnit test method: TestLib.csproj: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.SDK" Version="15.9.0" /> <PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit.runner.console" Version="2.4.1"> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

Testing user if he has a specific authority using AuthorizeAsync() in Xunit-Unit Testing

烂漫一生 提交于 2020-01-21 08:46:27
问题 The question has been Updated for better explanation to the issue I have, Simply I have this controller, [Authorize] public class IdeaManagementController : Controller { private IIdeaManagementService _ideaManagementService; private ITenantService _tenantService; private ITagService _tagService; private IEmployeeIdeaCategoryService _ideaManagementCategoryService; private static PbdModule _modul = PbdModule.IdeaManagement; IAuthorizationService _authorizationService; public

How to handle exceptions thrown by Tasks in xUnit .net's Assert.Throws<T>?

試著忘記壹切 提交于 2020-01-21 02:37:05
问题 The following asynchronous xUnit.net test with a lambda marked with the async modifier fails by reporting that no exception was thrown: [Theory, AutoWebData] public async Task SearchWithNullQueryThrows( SearchService sut, CancellationToken dummyToken) { // Fixture setup // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(async () => await sut.SearchAsync(null, dummyToken)); // Teardown } To make sure that an ArgumentNullException is actually thrown I explicitly used a

How can I run xUnit Unit Tests with VS2015 Preview?

纵饮孤独 提交于 2020-01-13 07:41:52
问题 I added the "xUnit.net runner for Visual Studio" v0.99.8 via Extensions Manager, but when I open the Test Explorer window, it does not seem to pick up any of my unit tests. Also, the Resharper 9 EAP does which is the only version of Resharper that supports VS2015 does seem yet to have the plugin for xUnit Test Runner. How then, can I run xUnit Unit Tests in VS2015 Preview? 回答1: You can find the answer here: http://blogs.msdn.com/b/webdev/archive/2014/11/12/announcing-asp-net-features-in

Running unit tests in TFS/VSO Build vNext using xUnit adapter

给你一囗甜甜゛ 提交于 2020-01-10 02:20:29
问题 I am trying to run our xUnit tests using the xUnit test adapter in Visual Studio Online's Build vNext platform. As stipulated in this article, we need to provide a custom test adapter path pointing to xunit.runner.visualstudio.testadapter.dll . But this package is restored by NuGet to a global packages folder, namely C:\Users\{user}\.dnx\packages ? How am I to reference this folder in the build step? We are using VS 2015 and DNX projects. EDIT: I even tried pointing to the package path DLL

Pass complex parameters to [Theory]

本秂侑毒 提交于 2020-01-08 14:03:32
问题 Xunit has a nice feature: you can create one test with a Theory attribute and put data in InlineData attributes, and xUnit will generate many tests, and test them all. I want to have something like this, but the parameters to my method are not 'simple data' (like string , int , double ), but a list of my class: public static void WriteReportsToMemoryStream( IEnumerable<MyCustomClass> listReport, MemoryStream ms, StreamWriter writer) { ... } 回答1: There are many xxxxData attributes in XUnit.

Pass complex parameters to [Theory]

老子叫甜甜 提交于 2020-01-08 14:02:11
问题 Xunit has a nice feature: you can create one test with a Theory attribute and put data in InlineData attributes, and xUnit will generate many tests, and test them all. I want to have something like this, but the parameters to my method are not 'simple data' (like string , int , double ), but a list of my class: public static void WriteReportsToMemoryStream( IEnumerable<MyCustomClass> listReport, MemoryStream ms, StreamWriter writer) { ... } 回答1: There are many xxxxData attributes in XUnit.

How do I start kestrel from a test?

前提是你 提交于 2020-01-06 11:56:27
问题 I'm setting up regression testing for my ASP.NET 5 project using beta8. When I setup the test fixtures I want to fire up kestrel so that I could run selenium tests against it without the need for any external web server. How do I do this? It's basically something like this: public class RegressionTests : IDisposable { public RegressionTests() { // Start kestrel } [Fact] public void Test1() { Assert.True(true); // more tests... } public void Dispose() { // Shutdown kestrel } } This is what I

How do I start kestrel from a test?

こ雲淡風輕ζ 提交于 2020-01-06 11:55:39
问题 I'm setting up regression testing for my ASP.NET 5 project using beta8. When I setup the test fixtures I want to fire up kestrel so that I could run selenium tests against it without the need for any external web server. How do I do this? It's basically something like this: public class RegressionTests : IDisposable { public RegressionTests() { // Start kestrel } [Fact] public void Test1() { Assert.True(true); // more tests... } public void Dispose() { // Shutdown kestrel } } This is what I