xunit

How to use FakeItEasy to assert a method was not called

▼魔方 西西 提交于 2019-12-14 02:16:47
问题 I want to assert that nothing was dispatched , a.k.a. _dispatcher.Dispatch was not called . interface being faked/mocked: interface IDispatcher { void Dispatch<T>(T command, Stuff stuff = null, TimeSpan? timeout = null, int? retries = null) where T : Command; } In the test body: _dispatcher = A.Fake<IDispatcher>(); // do stuff A.CallTo(() => _dispatcher.Dispatch(A<Command>.Ignored, A<Stuff>.Ignored, A<TimeSpan?>.Ignored, A<int?>.Ignored)).MustNotHaveHappened(); This test passes when something

Using Ninject with mocks in F#

♀尐吖头ヾ 提交于 2019-12-13 18:36:03
问题 This question is part of larger question that can be found here As in out production code we use Ninject and constructor injection our services tend to look like this public class Service : IService { private readonly IRepository _repository; public Service(IRepository repository) { _repository = repository; } public Task<IEnumerable<SelectOption>> GetAlLogicOptions() { return _repository.GetOptionsAsync(); } } how ever list of constructor parameters may and will change over time. This is the

How to run xUnit test DLL in Commandline without building the project

拈花ヽ惹草 提交于 2019-12-13 12:25:11
问题 I have a project in .NET Core and have built tests using xUnit. Now I wanted to run the test in deployment process. What I have done so far: I used this command in commandline: dotnet test [project address] ... it is working but the problem is that this command get the .csproj file and not the dll . I installed and used xunit.runner.console but its not working with .NET Core projects. I used dotnet xunit command, this one also not helped while I cannot give it the dll it is also using the

NullReferenceException in UnitTest using Verifyable on an async Method [duplicate]

故事扮演 提交于 2019-12-13 08:30:12
问题 This question already has answers here : How can I tell Moq to return a Task? (4 answers) Using Moq to mock an asynchronous method for a unit test (3 answers) Closed 12 months ago . I just had a problem with setting up a Unit Test using xUnit and Moq . My Testee The Method TestMethod() contains the Logic, I want to test. It is async and though returns a Task public class Testee { private readonly IDoSomething _doSomething; public Testee(IDoSomething doSomething) { _doSomething = doSomething;

Specification Testing with EF - The ObjectContext instance has been disposed

让人想犯罪 __ 提交于 2019-12-13 05:19:27
问题 I have the following SpecFlow scenario: [When(@"the registration is submitted")] public void WhenTheRegistrationIsSubmitted() { //var controller = _kernel.Get<AccountController>(); var factory = new HockeyDbContextFactory(); var userRepository = new Repository<User>(factory); var cryptoService = new CryptoService(); var roleRepository = new Repository<Role>(factory); var playerService = new Mock<IPlayerService>(); var leagueService = new Mock<ILeagueService>(); var userService = new

Catch an error as exception

倖福魔咒の 提交于 2019-12-13 03:58:32
问题 Given the following code: <?php class Language { private $code; public function __construct(string $code) { $this->code = $code; } } $lang = new Language(); I will get an ArgumentCountError like this: Uncaught ArgumentCountError: Too few arguments Now I would like to test and ensure this beahviour with a phpUnit unit test like this one: class LanguageTest { public function testLanguageConstructorWillRequireACode() { $language = new Language(); $this->expectException(MissingArgumentException:

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

.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

XUnit test project with only 1 Main method: “Program has more than one entry point defined.”

瘦欲@ 提交于 2019-12-12 10:39:54
问题 I converted a vNext format .NET xUnit test project (with project.json) to the new .csproj format in Visual Studio 2017 RC and started getting the below error. Most of the online answers to this error say "You have two Main methods; get rid of one." This seems like an obvious solution, but this project has only one Main method. Error: CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. Project.Name C:\path\to\Program.cs

xunit test Fact multiple times

六眼飞鱼酱① 提交于 2019-12-12 09:29:53
问题 I have some methods that rely on some random calculations to make a suggestion and I need to run the Fact several times to make sure is ok. I could include a for loop inside the fact i want to test but because there are several test where I want to do this I was lookup for a cleaner approach, something like this Repeat attribute in junit: http://www.codeaffine.com/2013/04/10/running-junit-tests-repeatedly-without-loops/ Can I easily implement something like this in xunit? 回答1: You'll have to