void CheckReplicationPrerequisities(IReplicationArticle article, Table sourceTable, Table targetTable)
 {
     //Replication strategy requires that the table contains primary key column of int data type and that the value of the column is incremented
     if (!sourceTable.Columns.Any(c => c.IsPrimaryKey &&
                               (c.DataType == System.Data.SqlDbType.TinyInt ||
                                c.DataType == System.Data.SqlDbType.SmallInt ||
                                c.DataType == System.Data.SqlDbType.Int ||
                                c.DataType == System.Data.SqlDbType.BigInt)))
     {
         if (sourceTable.Columns.SingleOrDefault(c => c.IsForeignKey &&
                                (c.DataType == System.Data.SqlDbType.TinyInt ||
                                 c.DataType == System.Data.SqlDbType.SmallInt ||
                                 c.DataType == System.Data.SqlDbType.Int ||
                                 c.DataType == System.Data.SqlDbType.BigInt)) == null)
             throw new ReplicationException($"Table {sourceTable.Name} doesn't contain primary key or single foreign key column or the type of the key column is not TinyInt or SmallInt or Int or BigInt");
     }
     IReplicationAnalyzer replicationAnalyzer = new ReplicationAnalyzer(_log);
     if (!replicationAnalyzer.AreTableSchemasReplicationCompliant(sourceTable, targetTable))
         throw new ReplicationException($"Source and target table {sourceTable.Name} are not replication compliant (there are schema differences in those tables)");
 }
 public void AreTableSchemasReplicationCompliant_TestHappyPath()
 {
     IReplicationAnalyzer replicationAnalyzer = new ReplicationAnalyzer(_logMock.Object);
     Table sourceTable = new Table()
     {
         Name = "TestTable",
         Columns = new Column[]
         {
             new Column() {Name = "Column1", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int },
             new Column() {Name = "Column2", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int }
         }
     };
     Table targetTable = new Table()
     {
         Name = "TestTable",
         Columns = new Column[]
         {
             new Column() {Name = "Column1", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int },
             new Column() {Name = "Column2", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int }
         }
     };
     Assert.True(replicationAnalyzer.AreTableSchemasReplicationCompliant(sourceTable, targetTable), "Happy path - the result must be true");
 }
 public void AreTableSchemasReplicationCompliant_TestDifferentColumnTypes()
 {
     IReplicationAnalyzer replicationAnalyzer = new ReplicationAnalyzer(_logMock.Object);
     Table sourceTable = new Table()
     {
         Name = "TestTable",
         Columns = new Column[]
         {
             new Column() {Name = "Column1", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int },
             new Column() {Name = "Column2", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int }
         }
     };
     Table targetTable = new Table()
     {
         Name = "TestTable",
         Columns = new Column[]
         {
             new Column() {Name = "Column1", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int },
             new Column() {Name = "Column2", IsPrimaryKey = false, DataType = System.Data.SqlDbType.BigInt }
         }
     };
     Assert.True(replicationAnalyzer.AreTableSchemasReplicationCompliant(sourceTable, targetTable) == false, "Columns in source and target table with different type not recognized");
 }
 public void AreTableSchemasReplicationCompliant_TestNewColumnInSourceDatabase()
 {
     IReplicationAnalyzer replicationAnalyzer = new ReplicationAnalyzer(_logMock.Object);
     Table sourceTable = new Table()
     {
         Name = "TestTable",
         Columns = new Column[]
         {
             new Column() {Name = "Column1", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int },
             new Column() {Name = "Column2", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int },
             new Column() {Name = "Column3", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int }
         }
     };
     Table targetTable = new Table()
     {
         Name = "TestTable",
         Columns = new Column[]
         {
             new Column() {Name = "Column1", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int },
             new Column() {Name = "Column2", IsPrimaryKey = false, DataType = System.Data.SqlDbType.Int }
         }
     };
     Assert.True(replicationAnalyzer.AreTableSchemasReplicationCompliant(sourceTable, targetTable) == false, "New column in source table not recognized");
 }
 void CheckReplicationPrerequisities(IReplicationArticle article, Table sourceTable, Table targetTable)
 {
     IReplicationAnalyzer replicationAnalyzer = new ReplicationAnalyzer(_log);
     if (!replicationAnalyzer.AreTableSchemasReplicationCompliant(sourceTable, targetTable))
         throw new ReplicationException($"Source and target table {sourceTable.Name} are not replication compliant (there are schema differences in those tables)");
 }