예제 #1
0
        public void MultitenantTests_Configure_Validate_Valid()
        {
            var container = new StashboxContainer();

            container.Register <IA, A>();

            var md = new TenantDistributor(container);

            md.ConfigureTenant("A", c => c.Register <D>());

            md.Validate();
        }
예제 #2
0
        public void MultitenantTests_Configure_Validate_Root_And_Tenants_Throws()
        {
            var container = new StashboxContainer();

            container.Register <D>();

            var md = new TenantDistributor(container);

            md.ConfigureTenant("A", c => c.Register <D>());

            var exception = Assert.Throws <AggregateException>(() => md.Validate());

            Assert.Equal(2, exception.InnerExceptions.Count);
        }
예제 #3
0
        public void MultitenantTests_Configure_Dep()
        {
            var container = new StashboxContainer();

            container.Register <D>();
            container.Register <IA, A>();

            var md = new TenantDistributor(container);

            md.ConfigureTenant("A", c => c.Register <IA, B>());

            var tenant = md.GetTenant("A");

            Assert.IsType <A>(container.Resolve <D>().Ia);
            Assert.IsType <B>(md.GetTenant("A").Resolve <D>().Ia);
        }
예제 #4
0
        public async Task MultitenantTests_Dispose_Async_Tenant()
        {
            var container = new StashboxContainer(c => c.WithDisposableTransientTracking());

            var md = new TenantDistributor(container);

            md.ConfigureTenant("C", c => c.Register <IA, C>());
            var tenant = md.GetTenant("C");

            var inst = (C)tenant.Resolve <IA>();

            await md.DisposeAsync();

            Assert.True(inst.Disposed);
            Assert.Throws <ObjectDisposedException>(() => container.Resolve <IA>());
            Assert.Throws <ObjectDisposedException>(() => tenant.Resolve <IA>());
        }