public void GivenAddedColumn()
        {
            //arrange
            DatabaseSchema schema1       = CreateSchema();
            var            productsTable = CreateProductsTable();

            schema1.Tables.Add(productsTable);

            DatabaseSchema schema2        = CreateSchema();
            var            productsTable2 = CreateProductsTable();

            schema2.Tables.Add(productsTable2);
            var nameColumn = new DatabaseColumn {
                Name = "Name", DbDataType = "NVARCHAR", Length = 10, Nullable = false
            };

            productsTable2.Columns.Add(nameColumn);

            //act
            var comparison = new CompareSchemas(schema1, schema2);
            var result     = comparison.ExecuteResult();

            //assert
            var addColumn = result.FirstOrDefault(x =>
                                                  x.ResultType == ResultType.Add &&
                                                  x.SchemaObjectType == SchemaObjectType.Column &&
                                                  x.TableName == "Products" &&
                                                  x.Name == "Name");

            Assert.IsNotNull(addColumn);
        }
        public void GivenUniqueConstraintWithChangedColumn()
        {
            //arrange
            DatabaseSchema     schema1    = CreateSchema();
            DatabaseConstraint constraint = GetUniqueConstraint();

            schema1.Tables[0].AddConstraint(constraint);

            DatabaseSchema     schema2     = CreateSchema();
            DatabaseConstraint constraint2 = GetUniqueConstraint();

            constraint2.Columns[0] = "Desc";
            schema2.Tables[0].AddConstraint(constraint2);

            //act
            var comparison = new CompareSchemas(schema1, schema2);
            var result     = comparison.ExecuteResult();

            //assert
            var changeConstraint = result.FirstOrDefault(x =>
                                                         x.ResultType == ResultType.Change &&
                                                         x.SchemaObjectType == SchemaObjectType.Constraint &&
                                                         x.TableName == "Orders" &&
                                                         x.Name == "UK_NAME");

            Assert.IsNotNull(changeConstraint);
        }
        public void GivenIdenticalSchemas()
        {
            //arrange
            DatabaseSchema schema1 = CreateSchema();
            DatabaseSchema schema2 = CreateSchema();

            //act
            var comparison = new CompareSchemas(schema1, schema2);
            var result     = comparison.ExecuteResult();

            //assert
            Assert.AreEqual(0, result.Count);
        }
        public void GivenSameUniqueConstraint()
        {
            //arrange
            DatabaseSchema     schema1    = CreateSchema();
            DatabaseConstraint constraint = GetUniqueConstraint();

            schema1.Tables[0].AddConstraint(constraint);
            DatabaseSchema     schema2     = CreateSchema();
            DatabaseConstraint constraint2 = GetUniqueConstraint();

            schema2.Tables[0].AddConstraint(constraint2);

            //act
            var comparison = new CompareSchemas(schema1, schema2);
            var result     = comparison.ExecuteResult();

            //assert
            Assert.AreEqual(0, result.Count);
        }
        public void GivenDroppedTable()
        {
            //arrange
            DatabaseSchema schema1 = CreateSchema();

            schema1.Tables.Add(CreateProductsTable());
            DatabaseSchema schema2 = CreateSchema();

            //act
            var comparison = new CompareSchemas(schema1, schema2);
            var result     = comparison.ExecuteResult();

            //assert
            var dropProducts = result.FirstOrDefault(x =>
                                                     x.ResultType == ResultType.Delete &&
                                                     x.SchemaObjectType == SchemaObjectType.Table &&
                                                     x.Name == "Products");

            Assert.IsNotNull(dropProducts);
        }
        public void GivenDroppedUniqueConstraint()
        {
            //arrange
            DatabaseSchema     schema1    = CreateSchema();
            DatabaseConstraint constraint = GetUniqueConstraint();

            schema1.Tables[0].AddConstraint(constraint);
            DatabaseSchema schema2 = CreateSchema();

            //act
            var comparison = new CompareSchemas(schema1, schema2);
            var result     = comparison.ExecuteResult();

            //assert
            var dropConstraint = result.FirstOrDefault(x =>
                                                       x.ResultType == ResultType.Delete &&
                                                       x.SchemaObjectType == SchemaObjectType.Constraint &&
                                                       x.TableName == "Orders" &&
                                                       x.Name == "UK_NAME");

            Assert.IsNotNull(dropConstraint);
        }