I have 4 tests spread across 3 test classes. If I run each test one by one they all can succeed. But running all (parallel I think?) they all fail except the first one fired?
My tests require the same setup, so I have a fixture which all tests are set up with:
public class CompositionRootFixture
{
public Container Container { get; private set; } // Simple Injector Container
public CompositionRootFixture()
{
Container = new Container();
/* code removed for clearity */
Container.Verify();
}
}
And is used in my test classes like so:
public class CommandProcessorTests : IClassFixture<CompositionRootFixture>
{
private readonly CompositionRootFixture _fixture;
public CommandProcessorTests(CompositionRootFixture fixture)
{
_fixture = fixture;
}
[Fact]
public async Task TestExecutingUsingContainerForResolution()
{
var commands = _fixture.Container.GetInstance<IExecuteCommands>();
var command = new FakeCommandWithoutValidator();
await commands.Execute(command);
Assert.Equal("faked", command.ReturnValue);
}
}
I have a hard time figuring out how to use the IClassFixture<T>
and the documentation is not very helpful in setting this up. I am using the latest XUnit 2.0.0-beta5-build2785.
Failed description:
---- System.InvalidOperationException : The configuration is invalid. Creating the instance for type IHandleCommand<FakeCommandWithoutValidator> failed. The registered delegate for type IHandleCommand<FakeCommandWithoutValidator> threw an exception. The configuration is invalid. The type HandleFakeCommandWithoutValidator is directly or indirectly depending on itself.
-------- SimpleInjector.ActivationException : The registered delegate for type IHandleCommand<FakeCommandWithoutValidator> threw an exception. The configuration is invalid. The type HandleFakeCommandWithoutValidator is directly or indirectly depending on itself.
------------ SimpleInjector.ActivationException : The configuration is invalid. The type HandleFakeCommandWithoutValidator is directly or indirectly depending on itself.
---- The following constructor parameters did not have matching fixture data: CompositionRootFixture fixture
Your container is leveraging a singleton which maintains state throughout the duration of the all tests being executed.
Initialize this singleton before each test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With