Ejemplo n.º 1
0
        public void DatabasesAreDeployed()
        {
            var dbDeployer = new TestDatabaseDeployer();

            var config = new TestConfig();

            var con1 =
                new ConnectionContext
            {
                Provider         = DbProviderFactories.GetFactory("System.Data.Sqlclient"),
                Name             = "con1",
                ProviderName     = "System.Data.SqlClient",
                ConnectionString = "1"
            };

            config.Connections["con1"] = con1;

            var con2 =
                new ConnectionContext
            {
                Provider         = DbProviderFactories.GetFactory("System.Data.Sqlclient"),
                Name             = "con1",
                ProviderName     = "System.Data.SqlClient",
                ConnectionString = "2"
            };

            config.Connections["con2"] = con2;

            //config.DatabaseDeployments.Add(new DatabaseDeployment
            //{
            //    ConnectionContext = config.Connections["con1"],
            //    DatabaseDeployer = dbDeployer,
            //    DatabaseProjectBuildConfiguration = "buildconfig1",
            //    CreateUniqueDatabaseName = true,
            //    DatabaseProjectFileName = "ssdt.csproj",
            //    DropDatabaseOnExit = true
            //});

            //config.DatabaseDeployments.Add(new DatabaseDeployment
            //{
            //    ConnectionContext = config.Connections["con2"],
            //    DatabaseDeployer = dbDeployer,
            //    DatabaseProjectBuildConfiguration = "buildconfig2",
            //    CreateUniqueDatabaseName = false,
            //    DatabaseProjectFileName = "ssdt2.csproj",
            //    DropDatabaseOnExit = false

            //});

            var setup = new Setup(config);

            setup.Initialize();

            // get unique database should be invoked once for first deployment
            Assert.AreEqual(1, dbDeployer.GetUniqueDatabaseName_connections.Count);
            Assert.AreSame(con1, dbDeployer.GetUniqueDatabaseName_connections[0]);

            // for unique database, the connection should be replaced in the config with the connection with the unique databasename in it
            Assert.AreNotSame(con1, config.Connections["con1"]);
            //Assert.AreNotSame(con1, config.DatabaseDeployments[0].ConnectionContext);
            //Assert.AreSame(config.Connections["con1"], config.DatabaseDeployments[0].ConnectionContext);
            //Assert.AreEqual("Initial Catalog=uniquedbname", config.Connections["con1"].ConnectionString);
            //Assert.AreSame(con2, config.Connections["con2"]);
            //Assert.AreSame(con2, config.DatabaseDeployments[1].ConnectionContext);

            //// deploy db should be invoked twice for both deployments
            //Assert.AreEqual(2, dbDeployer.DeployDatabase_databaseDeployments.Count);
            //Assert.AreNotSame(con1, dbDeployer.DeployDatabase_databaseDeployments[0]); // must be replaced for unique db
            //Assert.AreSame(config.DatabaseDeployments[0], dbDeployer.DeployDatabase_databaseDeployments[0]);
            //Assert.AreSame(config.DatabaseDeployments[1], dbDeployer.DeployDatabase_databaseDeployments[1]);
        }
Ejemplo n.º 2
0
        public void DatabasesAreDropped()
        {
            var dbDeployer = new TestDatabaseDeployer();

            var config = new TestConfig();

            var con1 =
                new ConnectionContext
            {
                Provider         = DbProviderFactories.GetFactory("System.Data.Sqlclient"),
                Name             = "con1",
                ProviderName     = "System.Data.SqlClient",
                ConnectionString = "1"
            };

            config.Connections["con1"] = con1;

            var con2 =
                new ConnectionContext
            {
                Provider         = DbProviderFactories.GetFactory("System.Data.Sqlclient"),
                Name             = "con1",
                ProviderName     = "System.Data.SqlClient",
                ConnectionString = "2"
            };

            config.Connections["con2"] = con2;

            config.DatabaseDeployments.Add(new DatabaseDeployment
            {
                ConnectionContext = config.Connections["con1"],
                DatabaseDeployer  = dbDeployer,
                DatabaseProjectBuildConfiguration = "buildconfig1",
                CreateUniqueDatabaseName          = true,
                DatabaseProjectFileName           = "ssdt.csproj",
                DropDatabaseOnExit = true
            });

            config.DatabaseDeployments.Add(new DatabaseDeployment
            {
                ConnectionContext = config.Connections["con2"],
                DatabaseDeployer  = dbDeployer,
                DatabaseProjectBuildConfiguration = "buildconfig2",
                CreateUniqueDatabaseName          = false,
                DatabaseProjectFileName           = "ssdt2.csproj",
                DropDatabaseOnExit = true
            });

            config.DatabaseDeployments.Add(new DatabaseDeployment
            {
                ConnectionContext = config.Connections["con2"],
                DatabaseDeployer  = dbDeployer,
                DatabaseProjectBuildConfiguration = "buildconfig2",
                CreateUniqueDatabaseName          = false,
                DatabaseProjectFileName           = "ssdt2.csproj",
                DropDatabaseOnExit = false
            });

            var setup = new Setup(config);

            setup.Initialize();

            Assert.AreEqual(0, dbDeployer.DropDatabase_connections.Count);

            setup.Dispose();

            Assert.AreEqual(2, dbDeployer.DropDatabase_connections.Count);
            Assert.AreSame(config.Connections["con1"], dbDeployer.DropDatabase_connections[0]);
            Assert.AreSame(config.Connections["con2"], dbDeployer.DropDatabase_connections[1]);
        }