Beispiel #1
0
        public virtual void TestInitialize(bool useTestDatabase = false)
        {
            ConfigurationModule.ConfigurationFilePath = TestConfiguration.Configuration.Path;
            File.Delete(TestConfiguration.Configuration.Path);
            ContainerProvider = new TestContainerProvider();
            ContainerProvider.Builder.RegisterModule <DefaultServiceModule>();
            ContainerProvider.Builder.RegisterGeneric(typeof(NullLogger <>)).As(typeof(ILogger <>));
            if (useTestDatabase)
            {
                ContainerProvider.Builder.RegisterModule <TestDataModule>();
            }
            else
            {
                ContainerProvider.Builder.RegisterModule <InMemoryDataModule>();
            }
            var keePassConfiguration = Container.Resolve <KeePassConfiguration>();

            keePassConfiguration.Path = TestConfiguration.KeePass.Path;

            var keePassPasswordValueProvider = Container.Resolve <IKeePassPasswordProvider>();

            keePassPasswordValueProvider.RegisterPassword(TestConfiguration.KeePass.Password);

            var configurationService = Container.Resolve <IConfigurationProvider>();

            configurationService.ApplicationConfiguration.DatabaseConfiguration.DatabasePath =
                TestConfiguration.Database.Path;

            DataContext = Container.Resolve <DbContext>();
            DataContext.Database.Migrate();
        }
Beispiel #2
0
        public void FixtureSetup()
        {
            this.testContainerProvider = new TestContainerProvider(new TestedPeristenceModelsSource());
            this.nhSessionHelper       = new NhSessionHelper(this.NhConfiguration);
            this.fixture = FixtureFactory.Build();

            this.PrepareFixture();
        }
        public void FactoryCanCreateDomainService()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<FakeDomainService>();

            var containerProvider = new TestContainerProvider(builder.Build());
            var factory = new AutofacDomainServiceFactory(containerProvider);
            var service = factory.CreateDomainService(typeof(FakeDomainService), null);

            Assert.IsInstanceOf<FakeDomainService>(service);
        }
        public void FactoryCanCreateDomainService()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <FakeDomainService>();

            var containerProvider = new TestContainerProvider(builder.Build());
            var factory           = new AutofacDomainServiceFactory(containerProvider);
            var service           = factory.CreateDomainService(typeof(FakeDomainService), null);

            Assert.IsType <FakeDomainService>(service);
        }
        public void FactoryCanDisposeDomainService()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<FakeDomainService>();
            FakeDomainService service;
            var containerProvider = new TestContainerProvider(builder.Build());
            var factory = new AutofacDomainServiceFactory(containerProvider);
            service = (FakeDomainService)factory.CreateDomainService(typeof(FakeDomainService), null);
            factory.ReleaseDomainService(service);
            Assert.IsFalse(service.IsDisposed);

            containerProvider.EndRequestLifetime();
            Assert.IsTrue(service.IsDisposed);
        }
        public void FactoryCanDisposeDomainService()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <FakeDomainService>();
            FakeDomainService service;
            var containerProvider = new TestContainerProvider(builder.Build());
            var factory           = new AutofacDomainServiceFactory(containerProvider);

            service = (FakeDomainService)factory.CreateDomainService(typeof(FakeDomainService), null);
            factory.ReleaseDomainService(service);
            Assert.False(service.IsDisposed);

            containerProvider.EndRequestLifetime();
            Assert.True(service.IsDisposed);
        }
Beispiel #7
0
        public void ContainerProvider_Dispose_Disposes()
        {
            TestContainerProvider containerProvider;

            using (containerProvider = new TestContainerProvider())
            {
                Assert.IsTrue(!GetDisposedValue(containerProvider));
            }

            try
            {
                Assert.IsTrue(GetDisposedValue(containerProvider));
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is ObjectDisposedException);
            }
        }