public void BeginLifetimeScope_CreatesLifetimeScopeForCurrentTenant() { var strategy = new StubTenantIdentificationStrategy() { TenantId = "tenant1" }; var mtc = new MultitenantContainer(strategy, new ContainerBuilder().Build()); mtc.ConfigureTenant("tenant1", b => b.RegisterType<StubDependency1Impl2>().As<IStubDependency1>().InstancePerLifetimeScope()); var tenantScope = mtc.GetCurrentTenantScope(); var tenantDependency = tenantScope.Resolve<IStubDependency1>(); using (var nestedScope = mtc.BeginLifetimeScope()) { var nestedDependency = nestedScope.Resolve<IStubDependency1>(); Assert.AreNotSame(tenantDependency, nestedDependency, "The dependency should be registered, but the scope should resolve a new instance."); } }
public void ComponentRegistry_ReturnsRegistryFromCurrentTenantLifetimeScope() { var strategy = new StubTenantIdentificationStrategy() { TenantId = "tenant1" }; var mtc = new MultitenantContainer(strategy, new ContainerBuilder().Build()); var scope = mtc.GetCurrentTenantScope(); Assert.AreSame(scope.ComponentRegistry, mtc.ComponentRegistry, "The ComponentRegistry property should behave based on context."); }
public void GetCurrentTenantScope_TenantNotFound() { var strategy = new StubTenantIdentificationStrategy() { TenantId = "tenant1", IdentificationSuccess = false }; var mtc = new MultitenantContainer(strategy, new ContainerBuilder().Build()); var current = mtc.GetCurrentTenantScope(); var tenant = mtc.GetTenantScope(null); Assert.AreSame(tenant, current, "The current scope should be the default tenant scope for the unidentified tenant."); }
public void GetCurrentTenantScope_ChangesByContext() { var strategy = new StubTenantIdentificationStrategy() { TenantId = "tenant1" }; var mtc = new MultitenantContainer(strategy, new ContainerBuilder().Build()); var tenant1a = mtc.GetCurrentTenantScope(); strategy.TenantId = "tenant2"; var tenant2 = mtc.GetCurrentTenantScope(); strategy.TenantId = "tenant1"; var tenant1b = mtc.GetCurrentTenantScope(); Assert.AreSame(tenant1a, tenant1b, "Every time a specific tenant context is seen, the same current scope should be returned."); Assert.AreNotSame(tenant1a, tenant2, "When different tenant contexts are seen, different tenant scopes should be returned."); }