public void ReplicationTest100kRows()
 {
     string SOURCE_DATABASE_NAME = _testDatabaseProvider.GenerateUniqueDatabaseName("TestReplication_Source");
     string TARGET_DATABASE_NAME = _testDatabaseProvider.GenerateUniqueDatabaseName("TestReplication_Target");
     const string SCHEMA = "dbo";
     _testDatabaseProvider.CreateTestDatabase(SOURCE_DATABASE_NAME);
     try
     {
         _testDatabaseProvider.CreateTestDatabase(TARGET_DATABASE_NAME);
         try
         {
             using (var testContext = new TestContext(_connectionString + $";Database={SOURCE_DATABASE_NAME}"))
             {
                 var standard = new Standard() { StandardName = "Standard" };
                 standard = testContext.Standards.Add(standard);
                 testContext.SaveChanges();
                 List<Student> students2Add = new List<Student>();
                 for (int i = 0; i < 100000; i++)
                 {
                     students2Add.Add(new Student()
                     {
                         StandardId = standard.StandardId,
                         Weight = 70 + i,
                         Height = 178 + i,
                         StudentName = $"Student {i}",
                         DateOfBirth = DateTime.Now,
                         Photo = new byte[] { 0, 1, 2, 3 }
                     });
                 }
                 testContext.BulkInsert(students2Add);
                 testContext.SaveChanges();
             }
             using (var testContext = new TestContext(_connectionString + $";Database={TARGET_DATABASE_NAME}"))
             {
                 var standard = new Standard() { StandardName = "Standard" };
                 standard = testContext.Standards.Add(standard);
                 testContext.SaveChanges();
                 List<Student> students2Add = new List<Student>();
                 for (int i = 0; i < 100000; i++)
                 {
                     students2Add.Add(new Student()
                     {
                         StandardId = standard.StandardId,
                         Weight = 0,
                         Height = 0,
                         StudentName = $"Student old {i}",
                         DateOfBirth = DateTime.Now,
                         Photo = new byte[] { 0, 1, 2, 3 }
                     });
                 }
                 testContext.BulkInsert(students2Add);
                 testContext.SaveChanges();
             }
             IReplicationStrategy replicationStrategy = new Strategies.TableSnapshotReplicationStrategy(_connectionString, _connectionString, _logMock.Object, _foreignKeysDropCreateScriptProvider, new SqlCommandFactory());
             replicationStrategy.Replicate(new ReplicationArticle() { SourceDatabaseName = SOURCE_DATABASE_NAME, TargetDatabaseName = TARGET_DATABASE_NAME, ArticleName = "Standards", SourceSchema = SCHEMA, TargetSchema = SCHEMA, ArticleType = DataContracts.Enums.eArticleType.TABLE });
             replicationStrategy.Replicate(new ReplicationArticle() { SourceDatabaseName = SOURCE_DATABASE_NAME, TargetDatabaseName = TARGET_DATABASE_NAME, ArticleName = "Students", SourceSchema = SCHEMA, TargetSchema = SCHEMA, ArticleType = DataContracts.Enums.eArticleType.TABLE });
             using (var testContext = new TestContext(_connectionString + $";Database={TARGET_DATABASE_NAME}"))
             {
                 Assert.Equal(100000, testContext.Students.Count());
                 for (int i = 0; i < 100000; i += 99)
                 {
                     string expectedStudentName = $"Student {i}";
                     Assert.True(null != testContext.Students.Single(s => s.StudentName == expectedStudentName && s.Weight == 70 + i && s.Height == 178 + i), $"Student {i} not found");
                 }
             }
         }
         finally
         {
             _testDatabaseProvider.DropTestDatabase(TARGET_DATABASE_NAME);
         }
     }
     finally
     {
         _testDatabaseProvider.DropTestDatabase(SOURCE_DATABASE_NAME);
     }
 }
 public void ReplicationForeignKeyWithUpdateOnLastRowTest()
 {
     string SOURCE_DATABASE_NAME = _testDatabaseProvider.GenerateUniqueDatabaseName("TestReplication_Source");
     string TARGET_DATABASE_NAME = _testDatabaseProvider.GenerateUniqueDatabaseName("TestReplication_Target");
     const string SCHEMA = "dbo";
     const int STUDENT_COUNT = 100;
     _testDatabaseProvider.CreateTestDatabase(SOURCE_DATABASE_NAME);
     try
     {
         _testDatabaseProvider.CreateTestDatabase(TARGET_DATABASE_NAME);
         try
         {
             using (var testContext = new TestContext(_connectionString + $";Database={SOURCE_DATABASE_NAME}"))
             {
                 var standard = new Standard() { StandardName = "Standard" };
                 testContext.Standards.Add(standard);
                 testContext.SaveChanges();
                 List<Student> students2Add = new List<Student>();
                 for (int i = 0; i < STUDENT_COUNT; i++)
                 {
                     students2Add.Add(new Student()
                     {
                         StandardId = standard.StandardId,
                         Weight = 70 + i,
                         Height = 178 + i,
                         StudentName = $"Student {i}",
                         DateOfBirth = DateTime.Now,
                         Photo = new byte[] { 0, 1, 2, 3 }
                     });
                 }
                 testContext.BulkInsert(students2Add);
                 testContext.SaveChanges();
             }
             using (var testContext = new TestContext(_connectionString + $";Database={TARGET_DATABASE_NAME}"))
             {
                 testContext.Standards.Select(s => s.StandardId > 0);
                 testContext.Students.Select(s => s.StudentId > 0);
                 testContext.SaveChanges();
             }
             IReplicationStrategy replicationStrategy = new Strategies.TableWithIncKeyUpdateLastRowReplicationStrategy(_connectionString, _connectionString, _logMock.Object, new SqlCommandFactory());
             replicationStrategy.Replicate(new ReplicationArticle() { SourceDatabaseName = SOURCE_DATABASE_NAME, TargetDatabaseName = TARGET_DATABASE_NAME, ArticleName = "Standards", SourceSchema = SCHEMA, TargetSchema = SCHEMA, ArticleType = DataContracts.Enums.eArticleType.TABLE });
             replicationStrategy.Replicate(new ReplicationArticle() { SourceDatabaseName = SOURCE_DATABASE_NAME, TargetDatabaseName = TARGET_DATABASE_NAME, ArticleName = "Students", SourceSchema = SCHEMA, TargetSchema = SCHEMA, ArticleType = DataContracts.Enums.eArticleType.TABLE });
             Student sourceDatabaseLastStudent;
             using (var testContext = new TestContext(_connectionString + $";Database={SOURCE_DATABASE_NAME}"))
             {
                 int studentMaxId = testContext.Students.Max(s => s.StudentId);
                 sourceDatabaseLastStudent = testContext.Students.Single(c => c.StudentId == studentMaxId);
                 sourceDatabaseLastStudent.StudentName = "Jan Halama";
                 testContext.SaveChanges();
             }
             replicationStrategy.Replicate(new ReplicationArticle() { SourceDatabaseName = SOURCE_DATABASE_NAME, TargetDatabaseName = TARGET_DATABASE_NAME, ArticleName = "Standards", SourceSchema = SCHEMA, TargetSchema = SCHEMA, ArticleType = DataContracts.Enums.eArticleType.TABLE });
             replicationStrategy.Replicate(new ReplicationArticle() { SourceDatabaseName = SOURCE_DATABASE_NAME, TargetDatabaseName = TARGET_DATABASE_NAME, ArticleName = "Students", SourceSchema = SCHEMA, TargetSchema = SCHEMA, ArticleType = DataContracts.Enums.eArticleType.TABLE });
             using (var testContext = new TestContext(_connectionString + $";Database={TARGET_DATABASE_NAME}"))
             {
                 Assert.Equal(STUDENT_COUNT, testContext.Students.Count());
                 for (int i = 0; i < STUDENT_COUNT - 1; i++)
                 {
                     string expectedStudentName = $"Student {i}";
                     Assert.True(null != testContext.Students.Single(s => s.StudentName == expectedStudentName && s.Weight == 70 + i && s.Height == 178 + i), $"Student {i} not found");
                 }
                 int studentMaxId = testContext.Students.Max(s => s.StudentId);
                 var lastStudent = testContext.Students.Single(c => c.StudentId == studentMaxId);
                 Assert.Equal(sourceDatabaseLastStudent.StudentId, lastStudent.StudentId);
                 Assert.Equal(sourceDatabaseLastStudent.StudentName, lastStudent.StudentName);
             }
         }
         finally
         {
             _testDatabaseProvider.DropTestDatabase(TARGET_DATABASE_NAME);
         }
     }
     finally
     {
         _testDatabaseProvider.DropTestDatabase(SOURCE_DATABASE_NAME);
     }
 }