Tag: mocking
-
Mocking FunctionContext GetLogger using Durable Functions Isolated Worker
Although you can inject your ILogger<T> into the constructor of your function, sometimes you may want to use the FunctionContext from your trigger method. Mocking this for testing can be a bit tricky. Consider the following function: We want to write tests for our class. For this to be testable, we’ll need to somehow mock…
-
Better assertions when verifying Moq’d methods have been called
Moq, according to its GitHub page, is “The most popular and friendly mocking framework for .NET”. Mocking frameworks allow you to create a ‘fake’ version of a dependency (typically an interface, or abstract class). With this fake, you can then instruct the methods return values, or invoke behaviour. Alternatively you can assert the methods were called,…
-
Asserting multiple properties of argument with FakeItEasy
More often than not, I want to assert that my dependency has been called with a parameter that matches more than one condition. Let’s say we have a method that calls ICustomerService.Add method. We want to assert the Add method was called with a Customer that matches a few conditions. The way we’d typically achieve…
-
Unit tests failing when run all together with FakeItEasy
While running my tests, I noticed that if I ran my test suite all together, some would fail, giving the exception: API restriction: The assembly has already loaded from a different location This issue was happening both in ReSharper test runner, and using the NUnit test runner Debugging, the exception was being thrown on my…