Skip to content

Can the TestCluster be used to obtain items from the service collection? #8732

Answered by runenilsenoe
macfma01 asked this question in Q&A
Discussion options

You must be logged in to vote

Indeed by passing config inheriting ISiloConfigurator.
There you can either mock or use the service directly

public sealed class ClusterFixture : IDisposable
{
    public TestCluster Cluster { get; } = new TestClusterBuilder()
        .AddSiloBuilderConfigurator<TestSiloConfigurations>()
        .Build();
    public ClusterFixture() => Cluster.Deploy();
    void IDisposable.Dispose() => Cluster.StopAllSilos();
}
public class TestSiloConfigurations : ISiloConfigurator
{
    public void Configure(ISiloBuilder siloBuilder)
    {
        siloBuilder.ConfigureServices(x =>
        {
            x.AddSingleton<IService,Service>();
            x.AddSingleton(new Mock<IService>().Object);
       …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by macfma01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants