myquay / MultiTenant.AspNetCore

Multi-tenancy support for ASP.NET Core 8
MIT License
16 stars 4 forks source link

Integration testing #6

Open brettwinters opened 1 week ago

brettwinters commented 1 week ago

Hi @myquay

How do I mock a service in a tenant container?

For example, suppose:

.AddMultiTenancy...
    .WithTenantedServices((services, tenant) => {
           services.AddSingleton<SomeService>();
    });

Then in my integration tests when I usually want to mock a service, for example:

hostBuilder.ConfigureServices(s => s.AddSingleton<ISomeService>(_ => someServiceMock.Object));

But since it's in its own container which is resolved internally, this does not return someServiceMock but instead the real service.

I was thinking of mocking the MultiTenantServiceProviderFactory but it's internal...

myquay commented 1 day ago

Hi @brettwinters,

This is a really good question; I'll need to set aside some time to look into this one for you. I don't have anything more to add at this point but it's on my radar :)

Thanks, Michael