xunit.net

Moq, unit test using xUnit framework and testing a function returning an object

江枫思渺然 提交于 2019-12-13 07:48:36
问题 I have a repository public class StudentsPersonalDetailsRepository : IStudentPersonalDetailsRepository { private readonly StudentManagementSystemEntities _studentsDbContext; private readonly ILogger _logger; public StudentsPersonalDetailsRepository(StudentManagementSystemEntities context, ILogger<IStudentPersonalDetailsRepository> logger) { _studentsDbContext = context; _logger = logger; } public IQueryable<StudentPersonalDetails> StudentPersonalDetails => _studentsDbContext

How to pass service config to the Xunit project Test controller?

心不动则不痛 提交于 2019-12-13 03:33:08
问题 I have below setup currently. Startup Class : Startup.cs public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.Configure<AzureStorageConfig>(Configuration.GetSection("AzureStorageConfig")); services.AddTransient<IAzureService, AzureService>(); } //other config settings ... } Class: AzureStorageConfig //store the azure account

how ClassData attribute passes data to a test method

三世轮回 提交于 2019-12-13 00:20:01
问题 I am very confused about how [ClassData] attribute works, it's just so weird to me, below is my code: // I just include basic code, some code such as explicitly implement GetEnumerator() of IEnumerable and Product class are not included for abbreviation [Serializable] public class ProductTestData : IEnumerable<object[]> { public IEnumerator<object[]> GetEnumerator() { yield return new IEnumerable<Product>[] { GetPricesUnder50() }; yield return new IEnumerable<Product>[] { GetPricesOver50() };

.NET Core Xunit - IActionResult' does not contain a definition for 'StatusCode'

佐手、 提交于 2019-12-12 20:58:13
问题 I have an API written in .NET Core and using xUnit to test those. I have my method in API as: [HttpDelete("api/{id}")] public async Task<IActionResult> DeleteUserId(string id) { try { //deleting from db } catch (Exception ex) { return StatusCode(500, ex.Message); } } I want to write a unit test when null/empty id passed to this method. I have my test case as: [Fact] public void DeleteUserId_Test() { //populate db and controller here var response= _myController.DeleteUserId(""); //trying to

Attribute cannot be repeated in C++/CLI but OK in C#?

回眸只為那壹抹淺笑 提交于 2019-12-12 14:31:06
问题 I'm getting error C3095: 'Xunit::Extensions::InlineDataAttribute': attribute cannot be repeated in C++/CLI code but not C#. xUnit.net looks like the answer to my prayers - a modern unit test framework with GUI working with C++/CLI. However, using their approach to parameterised testing gives me the error C3095 as shown below. Any ideas? I'm using the latest xUnit.net 1.6 with Visual Studio 2008SP1. using namespace Xunit; using namespace Xunit::Extensions; public ref class

Using XUnit with Visual Studio Online

徘徊边缘 提交于 2019-12-12 08:59:27
问题 I've setup my build as below using the build definition. I'm using XUnit and locally my tests are discovered and run. I've tested the glob **\*spec*.dll and it finds all my test dlls and the build log shows that those dlls are in fact built. However in the build log I get Run VS Test Runner No test found. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again. Which seems to suggest it is trying to use the MSTest test runner

how often should the entire suite of a system's unit tests be run?

倖福魔咒の 提交于 2019-12-12 08:28:54
问题 Generally, I'm still very much a unit testing neophyte. BTW, you may also see this question on other forums like xUnit.net, et cetera, because it's an important question to me. I apoligize in advance for my cross posting; your opinions are very important to me and not everyone in this forum belongs to the other forums too. I was looking at a large decade old legacy system which has had over 700 unit tests written recently (700 is just a small beginning). The tests happen to be written in

Unable to create new service: ChromeDriverService

馋奶兔 提交于 2019-12-11 15:28:27
问题 I have globally installed Selenium Standalone: npm install selenium-standalone -g selenium-standalone install --singleDriverInstall=chrome I have also bastardised the code from this page into this dotnet core / XUnit test: using System.Threading; using System; using Xunit; using OpenQA.Selenium; using OpenQA.Selenium.Remote; using OpenQA.Selenium.Chrome; using System.Diagnostics; namespace XunitTestLib.Unit { public class BasicBrowserTest : IDisposable { public Process _process; public

How To Run Xunit in VisualStudioOnline Build

浪子不回头ぞ 提交于 2019-12-11 12:02:59
问题 I've VS2015 RC project in my visual studio online account. In this project the tests are written with xunit. In the project I've added the following nuget packages <package id="xunit" version="2.1.0-beta3-build3029" targetFramework="net46" userInstalled="true" /> <package id="xunit.abstractions" version="2.0.0" targetFramework="net46" userInstalled="true" /> <package id="xunit.assert" version="2.1.0-beta3-build3029" targetFramework="net46" userInstalled="true" /> <package id="xunit.core"

How do I run in-memory integration tests using xUnit.net and ASP.NET 5?

大憨熊 提交于 2019-12-11 11:26:54
问题 I've already got unit tests working fine, but would like to do in memory hosting and use HttpClient for integration tests. Can't seem to find to much information about this for ASP.NET 5. 回答1: Ended up using the following package instead of Kestrel: Microsoft.AspNet.TestHost package Example how I use it against my app: [Fact] public async void GetShouldReturnTwoValues() { var server = TestServer.Create(app => { var env = app.ApplicationServices.GetRequiredService<IHostingEnvironment>(); new