Exemplo n.º 1
0
        public void Test41DecodeJsonToSqlDataWithSingleAlterationOk()
        {
            //SETUP

            //EXECUTE
            var sqlData = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", false, "TableInfos", 0, "ColumnInfos", 0, "IsPrimaryKey");

            //VERIFY
            sqlData.TableInfos.Count.ShouldEqual(2);
            sqlData.TableInfos[0].TableName.ShouldEqual("DataTop");
            sqlData.TableInfos[1].TableName.ShouldEqual("DataChild");
        }
Exemplo n.º 2
0
        public void Test40DecodeJsonToSqlDataWithSingleAlterationOk()
        {
            //SETUP

            //EXECUTE
            var sqlData = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "NewDataName", "TableInfos", 0, "TableName");

            //VERIFY
            sqlData.TableInfos.Count.ShouldEqual(5);
            sqlData.TableInfos[0].TableName.ShouldEqual("NewDataName");
            sqlData.TableInfos[1].TableName.ShouldEqual("DataChild");
            sqlData.TableInfos[2].TableName.ShouldEqual("AnotherTable");
            sqlData.TableInfos[3].TableName.ShouldEqual("DataTopToAnotherTable");
            sqlData.TableInfos[4].TableName.ShouldEqual("DataSingleton");
        }
        public void Test26CompareMockDataChangeForeignKeyCascadeOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "NO_ACTION", "ForeignKeys", 2, "DeleteAction");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Cascade Delete: The Many-to-Many relationship between AnotherTable.DataTops and DataTop has a foreign key FK_dbo.AnotherTable_AnotherTableId_dbo.DataTopToAnotherTable_AnotherTableId that is not CASCADE DELETE.  All linking table foreign keys should have CASCADE DELETE.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test12CompareMockDataChangePrimaryKeyOk()
        {
            //SETUP
            var comparer = new SqlCompare("RefUnitTest", "ToBeCheckUnitTest", "", true);
            var sqlData1 = LoadJsonHelpers.DeserializeData <SqlAllInfo>("SqlAllInfo01*.json");
            var sqlData2 = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", false, "TableInfos", 0, "ColumnInfos", 0, "IsPrimaryKey");

            //EXECUTE
            var status = comparer.CompareSqlToSql(sqlData1, sqlData2);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Primary Key: The SQL column [dbo].[DataTop].DataTopId primary key settings don't match. 'RefUnitTest' db says is a key, 'ToBeCheckUnitTest' db says it is NOT a key.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test35CompareMockDataChangeIndexHasIdentityOk()
        {
            //SETUP
            var comparer = new SqlCompare("RefUnitTest", "ToBeCheckUnitTest", "", true);
            var sqlData1 = LoadJsonHelpers.DeserializeData <SqlAllInfo>("SqlAllInfo01*.json");
            var sqlData2 = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", true, "Indexes", 0, "IsIdentity");

            //EXECUTE
            var status = comparer.CompareSqlToSql(sqlData1, sqlData2);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Index Mismatch: The 'RefUnitTest' SQL database, index on [dbo].[DataChild].DataTopId is NOT an identity column, while the index on the same table.column in SQL database ToBeCheckUnitTest is an identity column.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test05CompareMockDataChangeTableNameOk()
        {
            //SETUP
            var comparer = new SqlCompare("RefUnitTest", "ToBeCheckUnitTest", "", true);
            var sqlData1 = LoadJsonHelpers.DeserializeData <SqlAllInfo>("SqlAllInfo01*.json");
            var sqlData2 = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "NewDataName", "TableInfos", 0, "TableName");

            //EXECUTE
            var status = comparer.CompareSqlToSql(sqlData1, sqlData2);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Missing Table: The 'RefUnitTest' SQL database has a table called [dbo].[DataTop], which is missing in the 'ToBeCheckUnitTest' database.", status.GetAllErrors());
            string.Join(",", status.Warnings).ShouldEqual("Warning: Extra Table: SQL database 'RefUnitTest', table [dbo].[NewDataName] table contained an extra table, [dbo].[NewDataName]", string.Join(",", status.Warnings));
        }
        public void Test24CompareMockDataChangeForeignKeyReferencedColNameOk()
        {
            //SETUP
            var comparer = new SqlCompare("RefUnitTest", "ToBeCheckUnitTest", "", true);
            var sqlData1 = LoadJsonHelpers.DeserializeData <SqlAllInfo>("SqlAllInfo01*.json");
            var sqlData2 = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "BadName", "ForeignKeys", 0, "DeleteAction");

            //EXECUTE
            var status = comparer.CompareSqlToSql(sqlData1, sqlData2);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Foreign Key Delete Action: The [RefUnitTest] database has a foreign key Parent: DataChild.DataTopId, Referenced: DataTop.DataTopId that has delete action of CASCADE, while database [ToBeCheckUnitTest] has delete action of BadName.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test31CompareMockDataChangeIndexColumnNameOk()
        {
            //SETUP
            var comparer = new SqlCompare("RefUnitTest", "ToBeCheckUnitTest", "", true);
            var sqlData1 = LoadJsonHelpers.DeserializeData <SqlAllInfo>("SqlAllInfo01*.json");
            var sqlData2 = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "BadName", "Indexes", 0, "ColumnName");

            //EXECUTE
            var status = comparer.CompareSqlToSql(sqlData1, sqlData2);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Missing Index: The 'RefUnitTest' SQL database has an index [dbo].[DataChild].DataTopId: (not primary key, not clustered, not unique), which is missing in the 'ToBeCheckUnitTest' database.", status.GetAllErrors());
            string.Join(",", status.Warnings).ShouldEqual("Warning: Missing Index: The 'ToBeCheckUnitTest' database has an index [dbo].[DataChild].BadName: (not primary key, not clustered, not unique), which the 'RefUnitTest' database did not have.", string.Join(",", status.Warnings));
        }
        public void Test13CompareMockDataChangePrimaryKeyOrderOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", 2, "TableInfos", 0, "ColumnInfos", 0, "PrimaryKeyOrder");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Primary Key Order: The SQL SqlRefString  column [dbo].[DataTop].DataTopId primary key order does not match. SQL order = 2, EF order = 1.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test23CompareMockDataChangeForeignKeyReferencedColNameOk()
        {
            //SETUP
            var comparer = new SqlCompare("RefUnitTest", "ToBeCheckUnitTest", "", true);
            var sqlData1 = LoadJsonHelpers.DeserializeData <SqlAllInfo>("SqlAllInfo01*.json");
            var sqlData2 = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "BadName", "ForeignKeys", 0, "ReferencedColName");

            //EXECUTE
            var status = comparer.CompareSqlToSql(sqlData1, sqlData2);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Missing Foreign key: The 'RefUnitTest' SQL database has a foreign key Parent: DataChild.DataTopId, Referenced: DataTop.DataTopId, which is missing in the 'ToBeCheckUnitTest' database.", status.GetAllErrors());
            string.Join(",", status.Warnings).ShouldEqual("Warning: The 'ToBeCheckUnitTest' database has a foreign key Parent: DataChild.DataTopId, Referenced: DataTop.BadName, which the 'RefUnitTest' database did not have.", string.Join(",", status.Warnings));
        }
        public void Test11CompareMockDataChangeColumnSqlTypeOk()
        {
            //SETUP
            var comparer = new SqlCompare("RefUnitTest", "ToBeCheckUnitTest", "", true);
            var sqlData1 = LoadJsonHelpers.DeserializeData <SqlAllInfo>("SqlAllInfo01*.json");
            var sqlData2 = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "bit", "TableInfos", 0, "ColumnInfos", 0, "SqlTypeName");

            //EXECUTE
            var status = comparer.CompareSqlToSql(sqlData1, sqlData2);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Column Type: SQL column [dbo].[DataTop].DataTopId type does not match EF. 'RefUnitTest' db type = int, 'ToBeCheckUnitTest' db type = bit.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test27CompareMockDataChangeForeignKeyCascadeOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "CASCADE", "ForeignKeys", 3, "DeleteAction");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Cascade Delete: The ZeroOrOne-to-One relationship between DataSingleton.Parent and DataTop has different cascade delete value. SQL foreign key say CASCADE, EF setting is NO_ACTION.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test21CompareMockDataChangeForeignKeyParentColNameOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "BadName", "ForeignKeys", 0, "ParentColName");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Missing Foreign key: The 'RefUnitTest' SQL database has a foreign key Parent: DataChild.DataTopId, Referenced: DataTop.DataTopId, which is missing in the 'ToBeCheckUnitTest' database.", status.GetAllErrors());
            string.Join(",", status.Warnings).ShouldEqual("Warning: The 'ToBeCheckUnitTest' database has a foreign key Parent: DataChild.BadName, Referenced: DataTop.DataTopId, which the 'RefUnitTest' database did not have.", string.Join(",", status.Warnings));
        }
        public void Test23CompareMockDataChangeForeignKeyReferencedColNameOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "BadName", "ForeignKeys", 0, "ReferencedColName");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Missing Foreign Key: EF has a Many-to-One relationship between DataChild.Parent and DataTop but we don't find that in SQL.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test17CompareMockDataChangeMaxLengthNvarcharOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "20", "TableInfos", 1, "ColumnInfos", 3, "MaxLength");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("MaxLength: The  SQL SqlRefString  column [dbo].[DataChild].MyUnicodeString, type System.String, length does not match EF. SQL length = 10, EF length = 20.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test15CompareMockDataChangeMaxLengthMaxLengthSqlOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", -1, "TableInfos", 0, "ColumnInfos", 0, "MaxLength");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid();
            status.HasWarnings.ShouldEqual(true);
            string.Join(",", status.Warnings).ShouldEqual("Warning: MaxLength: The SQL SqlRefString column [dbo].[DataTop].DataTopId, type System.Int32, is at max length, but EF length is at 4.");
        }
        public void Test14CompareMockDataChangeIsNullableOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", true, "TableInfos", 0, "ColumnInfos", 0, "IsNullable");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Column Nullable: SQL SqlRefString column [dbo].[DataTop].DataTopId nullablity does not match. SQL is NULL, EF is NOT NULL.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test10CompareMockDataChangeColumnNameOk()
        {
            //SETUP
            var comparer = new SqlCompare("RefUnitTest", "ToBeCheckUnitTest", "", true);
            var sqlData1 = LoadJsonHelpers.DeserializeData <SqlAllInfo>("SqlAllInfo01*.json");
            var sqlData2 = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "BadColName", "TableInfos", 0, "ColumnInfos", 0, "ColumnName");

            //EXECUTE
            var status = comparer.CompareSqlToSql(sqlData1, sqlData2);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Missing Column: The SQL table [dbo].[DataTop] in second database does not contain a column called DataTopId.", status.GetAllErrors());
            string.Join(",", status.Warnings).ShouldEqual("Warning: Extra Column: The 'ToBeCheckUnitTest' database SQL table [dbo].[DataTop] has a column called BadColName (type int), which database 'RefUnitTest' did not have.", string.Join(",", status.Warnings));
        }
        public void Test11CompareMockDataChangeColumnSqlTypeOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "bit", "TableInfos", 0, "ColumnInfos", 0, "SqlTypeName");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Column Type: The SQL SqlRefString column [dbo].[DataTop].DataTopId type does not match EF. SQL type = bit, EF type = int.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test12CompareMockDataChangePrimaryKeyOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", false, "TableInfos", 0, "ColumnInfos", 0, "IsPrimaryKey");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Primary Key: The SQL SqlRefString  column [dbo].[DataTop].DataTopId primary key settings don't match. SQL says it is NOT a key, EF says it is a key.\n" +
                                              "Missing Foreign Key: EF has a Many-to-One relationship between DataChild.Parent and DataTop but we don't find that in SQL.", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false, string.Join(",", status.Warnings));
        }
        public void Test10CompareMockDataChangeColumnNameOk()
        {
            //SETUP
            var efData   = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData  = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "BadColName", "TableInfos", 0, "ColumnInfos", 0, "ColumnName");
            var comparer = new EfCompare("SqlRefString", sqlData.TableInfos.ToDictionary(x => x.CombinedName));

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Missing Column: The SQL SqlRefString table [dbo].[DataTop] does not contain a column called DataTopId. Needed by EF class DataTop.\n" +
                                              "Missing Foreign Key: EF has a Many-to-One relationship between DataChild.Parent and DataTop but we don't find that in SQL.", status.GetAllErrors());
            string.Join(",", status.Warnings).ShouldEqual("Warning: SQL SqlRefString table [dbo].[DataTop] has a column called BadColName (.NET type System.Int32) that EF does not access.", string.Join(",", status.Warnings));
        }
        public void Test05CompareMockDataChangeTableNameOk()
        {
            //SETUP
            var efData      = LoadJsonHelpers.DeserializeData <List <EfTableInfo> >("EfTableInfos01*.json");
            var sqlData     = LoadJsonHelpers.DeserializeObjectWithSingleAlteration <SqlAllInfo>("SqlAllInfo01*.json", "NewDataName", "TableInfos", 0, "TableName");
            var sqlInfoDict = sqlData.TableInfos.ToDictionary(x => x.CombinedName);
            var comparer    = new EfCompare("SqlRefString", sqlInfoDict);

            //EXECUTE
            var status = comparer.CompareEfWithSql(efData, sqlData);

            //VERIFY
            status.ShouldBeValid(false);
            status.GetAllErrors().ShouldEqual("Missing Table: The SQL SqlRefString does not contain a table called [dbo].[DataTop]. Needed by EF class DataTop.\n" +
                                              "Missing SQL Table: Could not find the SQL table called [dbo].[DataTop].", status.GetAllErrors());
            status.HasWarnings.ShouldEqual(false);
            sqlInfoDict.Keys.Count.ShouldEqual(1);
            sqlInfoDict.ContainsKey("[dbo].[NewDataName]").ShouldEqual(true);
        }