/// <summary>
        /// Initializes a new instance of the <see cref="CompareSchemas"/> class.
        /// </summary>
        /// <param name="baseSchema">The base schema.</param>
        /// <param name="compareSchema">The compare schema.</param>
        public CompareSchemas(DatabaseSchema baseSchema, DatabaseSchema compareSchema)
        {
            //argument null
            if (baseSchema == null) baseSchema = new DatabaseSchema(null, null);
            if (compareSchema == null) compareSchema = new DatabaseSchema(null, null);

            _compareSchema = compareSchema;
            _baseSchema = baseSchema;

            SqlType sqlType = FindSqlType(compareSchema) ?? FindSqlType(baseSchema) ?? SqlType.SqlServer;

            _writer = new ComparisonWriter(sqlType);
        }
        public void WhenViewAdded()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareViews(sb, writer);

            var baseViews = new List<DatabaseView>();
            var compareViews = new List<DatabaseView> { CreateView() };

            //act
            target.Execute(baseViews, compareViews);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(result.Contains("CREATE VIEW"));
        }
        public void WhenTablesIdentical()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareTables(sb, writer);

            var baseTables = new List<DatabaseTable> { CreateTable() };
            var compareTables = new List<DatabaseTable> { CreateTable() };

            //act
            target.Execute(baseTables, compareTables);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(string.IsNullOrEmpty(result));
        }
        public void WhenProcedureAdded()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareProcedures(sb, writer);

            var baseProcedures = new List<DatabaseStoredProcedure>();
            var compareProcedures = new List<DatabaseStoredProcedure> { CreateProcedure() };

            //act
            target.Execute(baseProcedures, compareProcedures);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(result.Contains("CREATE PROCEDURE"));
        }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompareSchemas"/> class.
        /// </summary>
        /// <param name="baseSchema">The base schema.</param>
        /// <param name="compareSchema">The compare schema.</param>
        public CompareSchemas(DatabaseSchema baseSchema, DatabaseSchema compareSchema)
        {
            //argument null
            if (baseSchema == null)
            {
                baseSchema = new DatabaseSchema(null, null);
            }
            if (compareSchema == null)
            {
                compareSchema = new DatabaseSchema(null, null);
            }

            _compareSchema = compareSchema;
            _baseSchema    = baseSchema;

            SqlType sqlType = FindSqlType(compareSchema) ?? FindSqlType(baseSchema) ?? SqlType.SqlServer;

            _writer = new ComparisonWriter(sqlType);
        }
        public void WhenViewChanged()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareViews(sb, writer);

            var baseViews = new List<DatabaseView> { CreateView() };
            var view = CreateView();
            const string orderByName = " ORDER BY NAME";
            view.Sql += orderByName;
            var compareViews = new List<DatabaseView> { view };

            //act
            target.Execute(baseViews, compareViews);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(result.Contains("DROP VIEW"));
            Assert.IsTrue(result.Contains("CREATE VIEW"));
            Assert.IsTrue(result.Contains(orderByName));
        }
        public void WheProcedureChanged()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareProcedures(sb, writer);

            var baseProcedures = new List<DatabaseStoredProcedure> { CreateProcedure() };
            var sproc = CreateProcedure();
            const string orderByName = " ORDER BY NAME";
            sproc.Sql += orderByName;
            var compareProcedures = new List<DatabaseStoredProcedure> { sproc };

            //act
            target.Execute(baseProcedures, compareProcedures);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(result.Contains("DROP PROCEDURE"));
            Assert.IsTrue(result.Contains("CREATE PROCEDURE"));
            Assert.IsTrue(result.Contains(orderByName));
        }
        public void WhenTablePrimaryKeyChanged()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareTables(sb, writer);

            var baseTables = new List<DatabaseTable> { CreateTable() };
            var table = CreateTable().AddColumn("D", DbType.Int32).Table;
            table.PrimaryKey.Columns.Clear();
            table.PrimaryKey.Columns.Add("D");//the primary key is D, not A
            var compareTables = new List<DatabaseTable> { table };

            //act
            target.Execute(baseTables, compareTables);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] ADD [D] INT"), "add the new column");
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] DROP CONSTRAINT [PK_TEST]"), "drop the old pk");
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] ADD CONSTRAINT [PK_TEST] PRIMARY KEY ([D])"), "add the new pk");
        }
        public void WhenTableUniqueConstraintChanged()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareTables(sb, writer);

            var baseTable = CreateTable();
            baseTable.FindColumn("B").AddUniqueKey("UK_TEST");
            var baseTables = new List<DatabaseTable> { baseTable };
            var compareTable = CreateTable().AddColumn("D", DbType.Int32).Table;
            compareTable.FindColumn("D").AddUniqueKey("UK_TEST");
            var compareTables = new List<DatabaseTable> { compareTable };

            //act
            target.Execute(baseTables, compareTables);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] ADD [D] INT"), "add the new column");
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] DROP CONSTRAINT [UK_TEST]"), "drop the old unique key");
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] ADD CONSTRAINT [UK_TEST] UNIQUE ([D])"), "add the new unique key");
        }
 public CompareTriggers(IList<CompareResult> results, ComparisonWriter writer)
 {
     _results = results;
     _writer = writer;
 }
Beispiel #11
0
 public CompareConstraints(StringBuilder sb, ComparisonWriter writer)
 {
     _sb     = sb;
     _writer = writer;
 }
Beispiel #12
0
 public ComparePackages(StringBuilder sb, ComparisonWriter writer)
 {
     _sb     = sb;
     _writer = writer;
 }
 public ComparePackages(IList<CompareResult> results, ComparisonWriter writer)
 {
     _results = results;
     _writer = writer;
 }
Beispiel #14
0
 public CompareTables(IList <CompareResult> results, ComparisonWriter writer)
 {
     _results = results;
     _writer  = writer;
 }
Beispiel #15
0
 public CompareProcedures(StringBuilder sb, ComparisonWriter writer)
 {
     _sb     = sb;
     _writer = writer;
 }
 public CompareConstraints(IList<CompareResult> results, ComparisonWriter writer)
 {
     _results = results;
     _writer = writer;
 }
        public void WhenViewsIdenticalWithDifferentFormatSql()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareViews(sb, writer);

            var databaseView = CreateView();
            databaseView.Sql = @"
create view ""Alphabetical list of products"" AS
SELECT Products.*, Categories.CategoryName
FROM Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID
WHERE (((Products.Discontinued)=0))
";
            var baseViews = new List<DatabaseView> { databaseView };
            var databaseView2 = CreateView();
            databaseView2.Sql = @"create view [dbo].[Alphabetical list of products] AS
SELECT Products.*, Categories.CategoryName
FROM Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID
WHERE (((Products.Discontinued)=0))";
            var compareViews = new List<DatabaseView> { databaseView2 };

            //act
            target.Execute(baseViews, compareViews);
            var result = string.Join(Environment.NewLine, sb.Select(x=>x.Script).ToArray());

            //assert
            Assert.IsTrue(string.IsNullOrEmpty(result));
        }
 public CompareStatistics(IList <CompareResult> results, ComparisonWriter writer)
 {
     _results = results;
     _writer  = writer;
 }
 public CompareSequences(IList<CompareResult> results, ComparisonWriter writer)
 {
     _results = results;
     _writer = writer;
 }
 public CompareFunctions(IList <CompareResult> results, ComparisonWriter writer)
 {
     _results = results;
     _writer  = writer;
 }
Beispiel #21
0
 public CompareColumns(StringBuilder sb, ComparisonWriter writer)
 {
     _sb     = sb;
     _writer = writer;
 }
Beispiel #22
0
 public CompareTriggers(StringBuilder sb, ComparisonWriter writer)
 {
     _sb     = sb;
     _writer = writer;
 }
 public CompareFunctions(IList<CompareResult> results, ComparisonWriter writer)
 {
     _results = results;
     _writer = writer;
 }
 public CompareConstraints(IList <CompareResult> results, ComparisonWriter writer)
 {
     _results = results;
     _writer  = writer;
 }
Beispiel #25
0
 public CompareFunctions(StringBuilder sb, ComparisonWriter writer)
 {
     _sb     = sb;
     _writer = writer;
 }
Beispiel #26
0
 public CompareSequences(StringBuilder sb, ComparisonWriter writer)
 {
     _sb     = sb;
     _writer = writer;
 }