xunit

Unit test WebApi2 passing header values

萝らか妹 提交于 2019-12-06 10:53:38
问题 I am working on a project using WebApi2. With my test project I am using Moq and XUnit. So far testing an api has been pretty straight forward to do a GET like [Fact()] public void GetCustomer() { var id = 2; _customerMock.Setup(c => c.FindSingle(id)) .Returns(FakeCustomers() .Single(cust => cust.Id == id)); var result = new CustomersController(_customerMock.Object).Get(id); var negotiatedResult = result as OkContentActionResult<Customer>; Assert.NotNull(negotiatedResult); Assert.IsType

Change pytest testsuite name in xml report

ぃ、小莉子 提交于 2019-12-06 08:52:49
问题 Because we started same tests with different interface, then take all reports and send them to jenkins. It's difficult to recognise with what interface we have errors. Before we use nose, it has parameter "--xunit-testsuite-name", has pytest analog? I want to change name of test suite in reports testsuite errors="0" failures="0" name=" pytest " skips="0" tests="12" time="103.702" to testsuite errors="0" failures="0" name=" inteface1 " skips="0" tests="12" time="103.702" 回答1: You can add a

Running (x)Unit Tests on TFS Build Pipeline

梦想与她 提交于 2019-12-06 07:02:11
I am merely a beginner and still trying to learn about TFS and its continuous integration workflow. Having that said, this could as well be a stupid question to ask as I might be missing on a simple detail, though any help or advice would be highly appreciated. So, I have a fairly simple Unit Test example written using .NET Core 2.0, which I would like to run as a test task on our TFS Server's CI Build pipeline. It pretty much looks something like this: using Microsoft.VisualStudio.TestTools.UnitTesting; namespace MyUnitTest { [TestClass] public class MyUnitTest { [TestMethod] public void

Lambda expression as inline data in xUnit

让人想犯罪 __ 提交于 2019-12-06 04:41:59
I'm pretty new to xUnit and here's what I'd like to achieve: [Theory] [InlineData((Config y) => y.Param1)] [InlineData((Config y) => y.Param2)] public void HasConfiguration(Func<Config, string> item) { var configuration = serviceProvider.GetService<GenericConfig>(); var x = item(configuration.Config1); // Config1 is of type Config Assert.True(!string.IsNullOrEmpty(x)); } Basically, I have a GenericConfig object which contains Config and other kind of configurations, but I need to check that every single parameter is valid. Since they're all string, I wanted to simplify using [InlineData]

xunit.runner.visualstudio not working on Visual Studio 2013 Update 4

夙愿已清 提交于 2019-12-06 04:39:01
I got the following constellation: Machine 1: - Windows 8.1 - Visual Studio 2013 Update 3. - XUnit Test Runner installed via "Tools" / "Extensions" Machine 2: - Windows Server 2012 (Hyper V Virtual Box) - Visual Studio 2013 Update 4 I've loaded a project, which I've created on Machine 1, on Machine 2. The project already contained Unit Tests which ran perfectly on Machine 1. The installation of the XUnit Testrunner via "Tools" / "Extensions" got unavailable recently. Therefore I installed the package xunit.runner.visualstudio as a Nuget Package into my solution on machine 2. After I rebuilt my

Instantiating IOptions<> in xunit

本秂侑毒 提交于 2019-12-06 02:17:41
问题 I'm trying to write an xunit test for a class (in a .net Core project) that looks something like: public Class FoodStore:IFoodStore { FoodList foodItems; public FoodStore(IOptions<FoodList> foodItems) { this.foodItems = foodItems; } public bool IsFoodItemPresentInList(string foodItemId) { //Logic to search from Food List } }` Note: FoodList is actually a json file, containing data, that is loaded and configured in the Startup class. How can I write an xunit test with appropriate dependency

Mocking DbEntityEntry

安稳与你 提交于 2019-12-06 00:17:57
I am writing unit tests for my Generic Repository layer but i have some problems with DbEntityEntry . My Update method is like below. public virtual void Update(TEntity entityToUpdate) { var entity = dbSet.Find(context.Entry<ITrackedEntity>(entityToUpdate).Entity.Id); context.Entry(entity).CurrentValues.SetValues(entityToUpdate); } As you can see, context.Entry<TEntity>(TEntity entity) method is invoked by caller. So while unit tests this code throws null exception. I had tried to mock context.Entry method but i couldn't because i couldn't provide return value. My current test method is below

Breaking the build in TeamCity if .NET Core unit tests running under Docker have code-coverage less than 90%

给你一囗甜甜゛ 提交于 2019-12-05 23:16:25
I have recently been looking at Docker, and how I can use TeamCity to run .NET Core unit tests in Docker containers as part of my build pipe-line. I add this as the final line in my Dockerfile to be able to run tests: ENTRYPOINT ["dotnet", "test", "--verbosity=normal"] These Dockerfiles are then referenced in compose files which TeamCity builds and runs using docker-compose in the command line. I have this working successfully now. Next challenge is to break the build if unit/integration test coverage is less than 90% - or some other value - no arguments about this please! I'm successfully

Dependency injection in Xunit project

不想你离开。 提交于 2019-12-05 21:24:25
问题 I am working on an ASP.Net Core MVC Web application. My Solution contains 2 projects: One for the application and a second project, dedicated to unit tests. I have added a reference to the application project in the Tests project. What I want to do now is to write a class in the Tests project which will communicate with the database through entity framework. What I was doing in my application project was to access to my DbContext class through constructor dependency injection. But I cannot do

placing asp.net 5 tests in separate assembly

三世轮回 提交于 2019-12-05 20:30:01
I use Microsoft.AspNet.TestHost to host xunit integration tests. As Long as the tests are in the very same Project as the asp.net-5-solution everything works as it should. But I'd like to place the tests into a separate assembly, to separate them from the solution. But when I try to run the tests in the separate solution I get an error, TestServer can't find the views. Bsoft.Buchhaltung.Tests.LoginTests.SomeTest [FAIL] System.InvalidOperationException : The view 'About' was not found. The following locations were searched: /Views/Home/About.cshtml /Views/Shared/About.cshtml. I guess the