コード例 #1
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;
            }
        }
        public void ExecuteScriptForThirdStorageProvider()
        {
            DatabaseAgent.SetConnectionString(SchemaGenerationConnectionString3);

            var scripts = _extendedScriptGenerator.GetScripts(MappingConfiguration.GetTypeDefinitions())
                          .Single(s => s.StorageProviderDefinition == SchemaGenerationThirdStorageProviderDefinition);

            DatabaseAgent.ExecuteBatchString(scripts.TearDownScript + scripts.SetUpScript, false, DatabaseConfiguration.GetReplacementDictionary());
        }
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();

            var createDBScript = ResourceUtility.GetResourceString(GetType(), "TestData.SchemaGeneration_CreateDB.sql");

            var masterAgent = new DatabaseAgent(MasterConnectionString);

            masterAgent.ExecuteBatchString(createDBScript, false, DatabaseConfiguration.GetReplacementDictionary());
        }
コード例 #4
0
        public static void SetupDatabase()
        {
            ConnectionStringSettings connectionSettings = ConfigurationManager.ConnectionStrings["Master"];

            if (connectionSettings == null)
            {
                throw new InvalidOperationException("Master connection configuration not found. Cannot set up database.");
            }

            var connectionString = DatabaseConfiguration.ReplaceDatasource(connectionSettings.ConnectionString);
            var databaseAgent    = new DatabaseAgent(connectionString);

            var commandBatch = File.ReadAllText("Database/Northwnd.sql");

            commandBatch = commandBatch.Replace("C:\\Databases", DatabaseConfiguration.DatabaseDirectory);

            databaseAgent.ExecuteBatchString(commandBatch, false);
        }