protected virtual void InitializeConfiguration(string assemblyDirectory)
        {
            ApplicationAssemblyLoaderFilter filter = ApplicationAssemblyLoaderFilter.Instance;

            // TODO: Duplicates logic from AssemblyFinder? The DLL searching part below can probably be removed.
            List <Assembly> assemblies = new List <Assembly>();
            DirectoryInfo   dir        = new DirectoryInfo(assemblyDirectory);

            foreach (FileInfo file in dir.GetFiles("*.dll"))
            {
                Assembly asm = Assembly.LoadFile(file.FullName);
                if (filter.ShouldConsiderAssembly(asm.GetName()) && filter.ShouldIncludeAssembly(asm))
                {
                    assemblies.Add(asm);
                }
            }
            DomainObjectsConfiguration.SetCurrent(
                new FakeDomainObjectsConfiguration(DomainObjectsConfiguration.Current.MappingLoader, GetPersistenceConfiguration(), new QueryConfiguration()));

            var rootAssemblyFinder = new FixedRootAssemblyFinder(assemblies.Select(a => new RootAssembly(a, false)).ToArray());

            var assemblyLoader = new FilteringAssemblyLoader(filter);
            ITypeDiscoveryService typeDiscoveryService =
                new AssemblyFinderTypeDiscoveryService(new AssemblyFinder(rootAssemblyFinder, assemblyLoader));

            var mappingReflector       = new MappingReflector(typeDiscoveryService);
            var persistenceModelLoader =
                new PersistenceModelLoader(new StorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage));
            var mappingConfiguration = new MappingConfiguration(mappingReflector, persistenceModelLoader);

            MappingConfiguration.SetCurrent(mappingConfiguration);
        }
        public void Initialize()
        {
            DomainObjectsConfiguration domainObjectsConfiguration = new DomainObjectsConfiguration();

            Assert.That(domainObjectsConfiguration.MappingLoader, Is.Not.Null);
            Assert.That(domainObjectsConfiguration.Storage, Is.Not.Null);
        }
 public virtual void TestFixtureSetUp()
 {
     DomainObjectsConfiguration.SetCurrent(TestMappingConfiguration.Instance.GetDomainObjectsConfiguration());
     MappingConfiguration.SetCurrent(TestMappingConfiguration.Instance.GetMappingConfiguration());
     ConfigurationWrapper.SetCurrent(null);
     FakeMappingConfiguration.Reset();
 }
 public override void TestFixtureSetUp()
 {
     base.TestFixtureSetUp();
     DomainObjectsConfiguration.SetCurrent(TableInheritanceConfiguration.Instance.GetDomainObjectsConfiguration());
     MappingConfiguration.SetCurrent(StandardConfiguration.Instance.GetMappingConfiguration());
     ConfigurationWrapper.SetCurrent(null);
 }
Example #5
0
        public void SetUp()
        {
            try
            {
                var providers = new ProviderCollection <StorageProviderDefinition>();
                providers.Add(new RdbmsProviderDefinition("TheStorageProvider", new SqlStorageObjectFactory(), TestDomainConnectionString));
                var storageConfiguration = new StorageConfiguration(providers, providers["TheStorageProvider"]);

                DomainObjectsConfiguration.SetCurrent(new FakeDomainObjectsConfiguration(storage: storageConfiguration));

                SqlConnection.ClearAllPools();

                var scriptGenerator = new ScriptGenerator(
                    pd => pd.Factory.CreateSchemaScriptBuilder(pd),
                    new RdbmsStorageEntityDefinitionProvider(),
                    new ScriptToStringConverter());
                var scripts = scriptGenerator.GetScripts(MappingConfiguration.Current.GetTypeDefinitions()).Single();

                var masterAgent = new DatabaseAgent(MasterConnectionString);
                masterAgent.ExecuteBatchFile("Database\\CreateDB.sql", false, DatabaseConfiguration.GetReplacementDictionary());

                var databaseAgent = new DatabaseAgent(TestDomainConnectionString);
                databaseAgent.ExecuteBatchString(scripts.SetUpScript, true);
            }
            catch (Exception e)
            {
                Console.WriteLine("SetUpFixture failed: " + e);
                Console.WriteLine();
                throw;
            }
        }
Example #6
0
        public static void Initialize()
        {
            ProviderCollection <StorageProviderDefinition> providers = new ProviderCollection <StorageProviderDefinition>();

            providers.Add(new RdbmsProviderDefinition("PerformanceTestDomain", new SqlStorageObjectFactory(), ConnectionString));
            StorageConfiguration storageConfiguration = new StorageConfiguration(providers, providers["PerformanceTestDomain"]);

            DomainObjectsConfiguration.SetCurrent(new FakeDomainObjectsConfiguration(storage: storageConfiguration));


            var rootAssemblyFinder = new FixedRootAssemblyFinder(new RootAssembly(typeof(StandardConfiguration).Assembly, true));
            var assemblyLoader     = new FilteringAssemblyLoader(ApplicationAssemblyLoaderFilter.Instance);
            var assemblyFinder     = new CachingAssemblyFinderDecorator(new AssemblyFinder(rootAssemblyFinder, assemblyLoader));
            ITypeDiscoveryService typeDiscoveryService = new AssemblyFinderTypeDiscoveryService(assemblyFinder);
            MappingConfiguration  mappingConfiguration = new MappingConfiguration(
                new MappingReflector(
                    typeDiscoveryService,
                    new ClassIDProvider(),
                    new ReflectionBasedMemberInformationNameResolver(),
                    new PropertyMetadataReflector(),
                    new DomainModelConstraintProvider(),
                    MappingReflector.CreateDomainObjectCreator()),
                new PersistenceModelLoader(new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage)));

            MappingConfiguration.SetCurrent(mappingConfiguration);
        }
        public override void SetUp()
        {
            base.SetUp();

            DomainObjectsConfiguration.SetCurrent(SchemaGenerationConfiguration.Instance.GetDomainObjectsConfiguration());
            MappingConfiguration.SetCurrent(SchemaGenerationConfiguration.Instance.GetMappingConfiguration());
        }
        protected TestMappingConfiguration()
        {
            ProviderCollection <StorageProviderDefinition> storageProviderDefinitionCollection = StorageProviderDefinitionObjectMother.CreateTestDomainStorageProviders();

            _storageConfiguration = new StorageConfiguration(
                storageProviderDefinitionCollection, storageProviderDefinitionCollection[MappingReflectionTestBase.DefaultStorageProviderID]);
            _storageConfiguration.StorageGroups.Add(new StorageGroupElement(new TestDomainAttribute(), MappingReflectionTestBase.c_testDomainProviderID));
            _storageConfiguration.StorageGroups.Add(
                new StorageGroupElement(new StorageProviderStubAttribute(), MappingReflectionTestBase.c_unitTestStorageProviderStubID));
            _storageConfiguration.StorageGroups.Add(
                new StorageGroupElement(new TableInheritanceTestDomainAttribute(), TableInheritanceMappingTest.TableInheritanceTestDomainProviderID));

            _mappingLoaderConfiguration = new MappingLoaderConfiguration();
            _queryConfiguration         = new QueryConfiguration("QueriesForStandardMapping.xml");
            DomainObjectsConfiguration.SetCurrent(
                new FakeDomainObjectsConfiguration(_mappingLoaderConfiguration, _storageConfiguration, _queryConfiguration));

            var typeDiscoveryService = GetTypeDiscoveryService();

            _mappingConfiguration = new MappingConfiguration(
                MappingReflectorObjectMother.CreateMappingReflector(typeDiscoveryService),
                new PersistenceModelLoader(new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage)));
            MappingConfiguration.SetCurrent(_mappingConfiguration);

            _domainObjectIDs = new DomainObjectIDs();
        }
 public override void SetUp()
 {
     base.SetUp();
     DomainObjectsConfiguration.SetCurrent(TableInheritanceConfiguration.Instance.GetDomainObjectsConfiguration());
     MappingConfiguration.SetCurrent(TableInheritanceConfiguration.Instance.GetMappingConfiguration());
     ConfigurationWrapper.SetCurrent(null);
     _transactionScope = ClientTransaction.CreateRootTransaction().EnterDiscardingScope();
 }
        public override void SetUp()
        {
            base.SetUp();

            DomainObjectsConfiguration.SetCurrent(StandardConfiguration.Instance.GetDomainObjectsConfiguration());
            MappingConfiguration.SetCurrent(StandardConfiguration.Instance.GetMappingConfiguration());
            ConfigurationWrapper.SetCurrent(null);
        }
        public override void TestFixtureTearDown()
        {
            DomainObjectsConfiguration.SetCurrent(null);
            MappingConfiguration.SetCurrent(null);
            ConfigurationWrapper.SetCurrent(null);

            base.TestFixtureTearDown();
        }
        public void GetAndSet()
        {
            IDomainObjectsConfiguration configuration =
                new FakeDomainObjectsConfiguration(new MappingLoaderConfiguration(), new StorageConfiguration(), new QueryConfiguration());

            DomainObjectsConfiguration.SetCurrent(configuration);

            Assert.That(DomainObjectsConfiguration.Current, Is.SameAs(configuration));
        }
        protected virtual void InitializeConfiguration()
        {
            DomainObjectsConfiguration.SetCurrent(
                new FakeDomainObjectsConfiguration(
                    DomainObjectsConfiguration.Current.MappingLoader, GetPersistenceConfiguration(), new QueryConfiguration()));

            MappingConfiguration.SetCurrent(
                new MappingConfiguration(
                    DomainObjectsConfiguration.Current.MappingLoader.CreateMappingLoader(),
                    new PersistenceModelLoader(new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage))));
        }
        public void Initialize_WithMixedStorageObjectFactory()
        {
            using (TempFile configFile = new TempFile())
            {
                SetUpConfigurationWrapper(
                    ConfigurationFactory.LoadConfigurationFromFile(
                        configFile, ResourceManager.GetDomainObjectsConfigurationWithMixedStorageObjectFactory()));

                DomainObjectsConfiguration domainObjectsConfiguration = new DomainObjectsConfiguration();

                Assert.That(Mixin.Get <FakeMixin> (domainObjectsConfiguration.Storage.DefaultStorageProviderDefinition.Factory), Is.Not.Null);
            }
        }
        public void Initialize_WithResolvedInterfaceStorageObjectFactory()
        {
            using (TempFile configFile = new TempFile())
            {
                SetUpConfigurationWrapper(
                    ConfigurationFactory.LoadConfigurationFromFile(
                        configFile, ResourceManager.GetDomainObjectsConfigurationWithResolvedInterfaceStorageObjectFactory()));

                DomainObjectsConfiguration domainObjectsConfiguration = new DomainObjectsConfiguration();

                Assert.That(domainObjectsConfiguration.Storage.DefaultStorageProviderDefinition.Factory, Is.TypeOf <CustomStorageObjectFactory>());
                Assert.That(domainObjectsConfiguration.Storage.StorageGroups, Is.Empty);
            }
        }
        public virtual void SetUp()
        {
            DomainObjectsConfiguration.SetCurrent(TestMappingConfiguration.Instance.GetDomainObjectsConfiguration());
            MappingConfiguration.SetCurrent(TestMappingConfiguration.Instance.GetMappingConfiguration());
            ConfigurationWrapper.SetCurrent(null);

            ClassIDProviderStub = MockRepository.GenerateStub <IClassIDProvider>();
            DomainModelConstraintProviderStub = MockRepository.GenerateStub <IDomainModelConstraintProvider>();
            DomainObjectCreatorStub           = MockRepository.GenerateStub <IDomainObjectCreator>();
            PropertyMetadataProvider          = new PropertyMetadataReflector();

            MappingObjectFactory = new ReflectionBasedMappingObjectFactory(
                Configuration.NameResolver, ClassIDProviderStub, PropertyMetadataProvider, DomainModelConstraintProviderStub, DomainObjectCreatorStub);
        }
Example #17
0
        public void UnknownQueryDefinitionInQueryConfiguration()
        {
            QueryDefinition unknownQueryDefinition = new QueryDefinition("UnknownQuery", TestDomainStorageProviderDefinition, "select 42", QueryType.Scalar);

            DomainObjectsConfiguration.Current.Query.QueryDefinitions.Add(unknownQueryDefinition);

            using (MemoryStream stream = new MemoryStream())
            {
                Serialize(stream, unknownQueryDefinition);
                DomainObjectsConfiguration.SetCurrent(
                    new FakeDomainObjectsConfiguration(
                        DomainObjectsConfiguration.Current.MappingLoader, DomainObjectsConfiguration.Current.Storage, new QueryConfiguration()));

                Deserialize(stream);
            }
        }
        public void Initialize_WithConfigurationHavingMinimumSettings()
        {
            using (TempFile configFile = new TempFile())
            {
                SetUpConfigurationWrapper(ConfigurationFactory.LoadConfigurationFromFile(configFile, ResourceManager.GetDomainObjectsConfigurationWithMinimumSettings()));

                DomainObjectsConfiguration domainObjectsConfiguration = new DomainObjectsConfiguration();

                Assert.That(domainObjectsConfiguration.MappingLoader, Is.Not.Null);
                Assert.That(domainObjectsConfiguration.Storage, Is.Not.Null);
                Assert.That(domainObjectsConfiguration.Storage.DefaultStorageProviderDefinition, Is.Not.Null);
                Assert.That(domainObjectsConfiguration.Storage.DefaultStorageProviderDefinition.Factory, Is.TypeOf <SqlStorageObjectFactory>());
                Assert.That(domainObjectsConfiguration.Storage.StorageProviderDefinitions.Count, Is.EqualTo(1));
                Assert.That(domainObjectsConfiguration.Storage.StorageGroups, Is.Empty);
            }
        }
        public void Initialize_WithConfigurationHavingCustomMappingLoader()
        {
            using (TempFile configFile = new TempFile())
            {
                SetUpConfigurationWrapper(ConfigurationFactory.LoadConfigurationFromFile(configFile, ResourceManager.GetDomainObjectsConfigurationWithFakeMappingLoader()));

                DomainObjectsConfiguration domainObjectsConfiguration = new DomainObjectsConfiguration();

                Assert.That(domainObjectsConfiguration.MappingLoader, Is.Not.Null);
                Assert.That(domainObjectsConfiguration.MappingLoader.MappingLoaderType, Is.SameAs(typeof(FakeMappingLoader)));

                Assert.That(domainObjectsConfiguration.Storage, Is.Not.Null);
                Assert.That(domainObjectsConfiguration.Storage.DefaultStorageProviderDefinition, Is.Not.Null);
                Assert.That(domainObjectsConfiguration.Storage.StorageProviderDefinitions.Count, Is.EqualTo(1));
                Assert.That(domainObjectsConfiguration.Storage.StorageGroups, Is.Empty);
            }
        }
Example #20
0
        public void SetUp()
        {
            try
            {
                var serviceLocator = DefaultServiceLocator.Create();
                serviceLocator.RegisterSingle <ISecurityProvider> (() => new NullSecurityProvider());
                serviceLocator.RegisterSingle <IPrincipalProvider> (() => new NullPrincipalProvider());
                ServiceLocator.SetLocatorProvider(() => serviceLocator);

                var providers = new ProviderCollection <StorageProviderDefinition>();
                providers.Add(new RdbmsProviderDefinition("SecurityManager", new SecurityManagerSqlStorageObjectFactory(), TestDomainConnectionString));
                var storageConfiguration = new StorageConfiguration(providers, providers["SecurityManager"]);
                storageConfiguration.StorageGroups.Add(new StorageGroupElement(new SecurityManagerStorageGroupAttribute(), "SecurityManager"));

                DomainObjectsConfiguration.SetCurrent(new FakeDomainObjectsConfiguration(storage: storageConfiguration));

                var rootAssemblyFinder = new FixedRootAssemblyFinder(new RootAssembly(typeof(BaseSecurityManagerObject).Assembly, true));
                var assemblyLoader     = new FilteringAssemblyLoader(ApplicationAssemblyLoaderFilter.Instance);
                var assemblyFinder     = new CachingAssemblyFinderDecorator(new AssemblyFinder(rootAssemblyFinder, assemblyLoader));
                ITypeDiscoveryService typeDiscoveryService = new AssemblyFinderTypeDiscoveryService(assemblyFinder);

                MappingConfiguration.SetCurrent(
                    new MappingConfiguration(
                        new MappingReflector(
                            typeDiscoveryService,
                            new ClassIDProvider(),
                            new ReflectionBasedMemberInformationNameResolver(),
                            new PropertyMetadataReflector(),
                            new DomainModelConstraintProvider(),
                            MappingReflector.CreateDomainObjectCreator()),
                        new PersistenceModelLoader(new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage))));

                SqlConnection.ClearAllPools();

                DatabaseAgent masterAgent = new DatabaseAgent(MasterConnectionString);
                masterAgent.ExecuteBatchFile("SecurityManagerCreateDB.sql", false, DatabaseConfiguration.GetReplacementDictionary());
                DatabaseAgent databaseAgent = new DatabaseAgent(TestDomainConnectionString);
                databaseAgent.ExecuteBatchFile("SecurityManagerSetupDB.sql", true);
                databaseAgent.ExecuteBatchFile("SecurityManagerSetupConstraints.sql", true);
                databaseAgent.ExecuteBatchFile("SecurityManagerSetupDBSpecialTables.sql", true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #21
0
        public void SetUp()
        {
            try
            {
                var providers = new ProviderCollection <StorageProviderDefinition>();
                providers.Add(new RdbmsProviderDefinition(StubStorageProvider.StorageProviderID, new StubStorageFactory(), "NonExistingRdbms"));
                var storageConfiguration = new StorageConfiguration(providers, providers[StubStorageProvider.StorageProviderID]);
                DomainObjectsConfiguration.SetCurrent(new FakeDomainObjectsConfiguration(storage: storageConfiguration));

                Dev.Null = MappingConfiguration.Current;
            }
            catch (Exception ex)
            {
                Console.WriteLine("SetUpFixture failed: " + ex);
                Console.WriteLine();
                throw;
            }
        }
        public void Initialize_WithUnresolvedInterfaceStorageObjectFactory()
        {
            using (TempFile configFile = new TempFile())
            {
                SetUpConfigurationWrapper(
                    ConfigurationFactory.LoadConfigurationFromFile(
                        configFile, ResourceManager.GetDomainObjectsConfigurationWithUnresolvedInterfaceStorageObjectFactory()));

                DomainObjectsConfiguration domainObjectsConfiguration = new DomainObjectsConfiguration();

                Assert.That(
                    () => domainObjectsConfiguration.Storage.DefaultStorageProviderDefinition,
                    Throws.TypeOf <ConfigurationErrorsException>().With.Message.StringStarting(
                        "The factory type 'Remotion.Data.DomainObjects.UnitTests.Configuration.DomainObjectsConfigurationTest+IUnresolvedCustomStorageObjectFactory' "
                        + "specified in the configuration of the 'Test' StorageProvider definition cannot be instantiated because it is abstract. Either "
                        + "register an implementation of 'IUnresolvedCustomStorageObjectFactory' in the configured service locator, or specify a non-abstract "
                        + "type."));
            }
        }
        public void Initialize_WithConfigurationHavingCustomSectionGroupName()
        {
            using (TempFile configFile = new TempFile())
            {
                System.Configuration.Configuration configuration =
                    ConfigurationFactory.LoadConfigurationFromFile(configFile, ResourceManager.GetDomainObjectsConfigurationWithCustomSectionGroupName());
                SetUpConfigurationWrapper(configuration);

                DomainObjectsConfiguration domainObjectsConfiguration = (DomainObjectsConfiguration)configuration.GetSectionGroup("domainObjects");
                // For ReSharper's sake
                Assertion.IsNotNull(domainObjectsConfiguration);

                Assert.That(domainObjectsConfiguration.SectionGroupName, Is.EqualTo("domainObjects"));
                Assert.That(domainObjectsConfiguration.MappingLoader, Is.Not.Null);
                Assert.That(domainObjectsConfiguration.Storage, Is.Not.Null);
                Assert.That(domainObjectsConfiguration.Storage.DefaultStorageProviderDefinition, Is.Not.Null);
                Assert.That(domainObjectsConfiguration.Storage.StorageProviderDefinitions.Count, Is.EqualTo(1));
                Assert.That(domainObjectsConfiguration.Storage.StorageGroups, Is.Empty);
            }
        }
        public void SetUp()
        {
            try
            {
                ProviderCollection <StorageProviderDefinition> providers = new ProviderCollection <StorageProviderDefinition>();
                providers.Add(new RdbmsProviderDefinition("Development.Data.DomainObjects", new SqlStorageObjectFactory(), "ConnectionString"));
                StorageConfiguration storageConfiguration = new StorageConfiguration(providers, providers["Development.Data.DomainObjects"]);

                DomainObjectsConfiguration.SetCurrent(
                    new FakeDomainObjectsConfiguration(
                        new MappingLoaderConfiguration(),
                        storageConfiguration,
                        new QueryConfiguration()));

                var rootAssemblyFinder = new FixedRootAssemblyFinder(new RootAssembly(typeof(TestDomainObject).Assembly, true));
                var assemblyLoader     = new FilteringAssemblyLoader(ApplicationAssemblyLoaderFilter.Instance);
                var assemblyFinder     = new CachingAssemblyFinderDecorator(new AssemblyFinder(rootAssemblyFinder, assemblyLoader));
                ITypeDiscoveryService typeDiscoveryService = new AssemblyFinderTypeDiscoveryService(assemblyFinder);

                MappingConfiguration.SetCurrent(
                    new MappingConfiguration(
                        new MappingReflector(
                            typeDiscoveryService,
                            new ClassIDProvider(),
                            new ReflectionBasedMemberInformationNameResolver(),
                            new PropertyMetadataReflector(),
                            new DomainModelConstraintProvider(),
                            new ThrowingDomainObjectCreator()),
                        new PersistenceModelLoader(new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage))));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public void GetMappingLoader_SameInstanceTwice()
        {
            DomainObjectsConfiguration domainObjectsConfiguration = new DomainObjectsConfiguration();

            Assert.That(domainObjectsConfiguration.MappingLoader, Is.SameAs(domainObjectsConfiguration.MappingLoader));
        }
        public void GetStorage_SameInstanceTwice()
        {
            DomainObjectsConfiguration domainObjectsConfiguration = new DomainObjectsConfiguration();

            Assert.That(domainObjectsConfiguration.Storage, Is.SameAs(domainObjectsConfiguration.Storage));
        }
 public void SetUp()
 {
     DomainObjectsConfiguration.SetCurrent(null);
 }