public void GivenAlteredColumn()
        {
            //arrange
            DatabaseSchema schema1 = CreateSchema();
            var productsTable = CreateProductsTable();
            schema1.Tables.Add(productsTable);
            var nameColumn = new DatabaseColumn { Name = "Name", DbDataType = "NVARCHAR", Length = 10, Nullable = false };
            productsTable.Columns.Add(nameColumn);

            DatabaseSchema schema2 = CreateSchema();
            var productsTable2 = CreateProductsTable();
            var nameColumn2 = new DatabaseColumn { Name = "Name", DbDataType = "NVARCHAR", Length = 20, Nullable = true };
            productsTable2.Columns.Add(nameColumn2);
            schema2.Tables.Add(productsTable2);

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

            //assert
            var alterColumn = result.FirstOrDefault(x =>
                                             x.ResultType == ResultType.Change &&
                                             x.SchemaObjectType == SchemaObjectType.Column &&
                                             x.TableName == "Products" &&
                                             x.Name == "Name");
            Assert.IsNotNull(alterColumn);
        }
        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 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);
        }
        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 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);
        }