Replies: 1 comment 1 reply
-
I've added sample tests in this repository. Pure.DI is not a DI container, but a source code generator. All code is generated at compile time. It's the same with tests. In the example you will find integration tests, I guess your question is more related to them. This example generates a test composition based on settings from the Lib library: private void Setup() =>
DI.Setup(nameof(MyServiceTests))
// Based on the Composition setup from the Lib namespace
.DependsOn("Lib.Composition")
// Overrides some instances using mocks
.Bind<IOutput>().To(_ => _output.Object)
.Bind<IInput>().To(_ => _input.Object)
// Exposing a test instance as the composition root
.Root<IService>("Service"); In the test composition, some of the objects are replaced by Mocks. And the test object is defined as the root of the composition. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In a regular ASP.NET project, for example, you can set up your DI via
Startup.cs
:and in the test project, you can do this to override the configured DI for the main project (see here):
Is there a way to do something similar with this library? I have tried the following:
Main project (has no knowledge of test project):
Test project (references main project):
Inspecting the
Composition
instance and stepping through the code during debugging shows that the test setup isn't overriding the original as I'd like. Is there an approach I should use?Beta Was this translation helpful? Give feedback.
All reactions