public void ReplicationForeignKeyTest()
 {
     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
         {
             Student student;
             using (var testContext = new TestContext(_connectionString + $";Database={SOURCE_DATABASE_NAME}"))
             {
                 var standard = new Standard() { StandardName = "Standard" };
                 testContext.Standards.Add(standard);
                 student = testContext.Students.Add(new Student() {
                     Standard = standard,
                     Weight = 70,
                     Height = 178,
                     StudentName = "Jan Halama",
                     DateOfBirth = DateTime.Now,
                     Photo = new byte[] { 0,1,2,3}
                 });
                 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.TableWithIncKeyReplicationStrategy(_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 });
             using (var testContext = new TestContext(_connectionString + $";Database={TARGET_DATABASE_NAME}"))
             {
                 Assert.True(testContext.Students.Any(s => s.StudentId == student.StudentId && s.StudentName == s.StudentName && s.Standard.StandardId == student.Standard.StandardId),"Target db not as expected after replication");
             }
          }
         finally
         {
             _testDatabaseProvider.DropTestDatabase(TARGET_DATABASE_NAME);
         }
     }
     finally
     {
         _testDatabaseProvider.DropTestDatabase(SOURCE_DATABASE_NAME);
     }
 }
        public void ReplicationTest()
        {
            string SOURCE_DATABASE_NAME = _testDatabaseProvider.GenerateUniqueDatabaseName("TestReplication_Source");
            string TARGET_DATABASE_NAME = _testDatabaseProvider.GenerateUniqueDatabaseName("TestReplication_Target");
            const string TABLE_NAME = "TestTable";
            const string SCHEMA = "dbo";
            const int ROWS_COUNT = 10;
            _testDatabaseProvider.CreateTestDatabase(SOURCE_DATABASE_NAME);
            try
            {
                _testDatabaseProvider.CreateTestDatabase(TARGET_DATABASE_NAME);
                try
                {
                    CreateTable(SOURCE_DATABASE_NAME, SCHEMA, TABLE_NAME);
                    InsertIntoTable(SOURCE_DATABASE_NAME, SCHEMA, TABLE_NAME, ROWS_COUNT);
                    CreateTable(TARGET_DATABASE_NAME, SCHEMA, TABLE_NAME);

                    IReplicationStrategy replicationStrategy = new Strategies.TableWithIncKeyReplicationStrategy(_connectionString, _connectionString, _logMock.Object, new SqlCommandFactory());
                    replicationStrategy.Replicate(new ReplicationArticle() { SourceDatabaseName = SOURCE_DATABASE_NAME, TargetDatabaseName = TARGET_DATABASE_NAME, ArticleName = TABLE_NAME, SourceSchema = SCHEMA, TargetSchema = SCHEMA, ArticleType = DataContracts.Enums.eArticleType.TABLE });
                    Assert.Equal(ROWS_COUNT, TableRowsCount(TARGET_DATABASE_NAME, SCHEMA, TABLE_NAME));
                }
                finally
                {
                    _testDatabaseProvider.DropTestDatabase(TARGET_DATABASE_NAME);
                }
            }
            finally
            {
                _testDatabaseProvider.DropTestDatabase(SOURCE_DATABASE_NAME);
            }
        }
 public void ReplicationWrongArticleTypeTest()
 {
     string SOURCE_DATABASE_NAME = _testDatabaseProvider.GenerateUniqueDatabaseName("TestReplication_Source");
     string TARGET_DATABASE_NAME = _testDatabaseProvider.GenerateUniqueDatabaseName("TestReplication_Target");
     const string TABLE_NAME = "TestTable";
     const string SCHEMA = "dbo";
     _testDatabaseProvider.CreateTestDatabase(SOURCE_DATABASE_NAME);
     try
     {
         _testDatabaseProvider.CreateTestDatabase(TARGET_DATABASE_NAME);
         try
         {
             CreateTable(SOURCE_DATABASE_NAME, SCHEMA, TABLE_NAME);
             CreateTable(TARGET_DATABASE_NAME, SCHEMA, TABLE_NAME);
             IReplicationStrategy replicationStrategy = new Strategies.TableWithIncKeyReplicationStrategy(_connectionString, _connectionString, _logMock.Object, new SqlCommandFactory());
             Assert.Throws<ReplicationException>(() => replicationStrategy.Replicate(new ReplicationArticle() { SourceDatabaseName = SOURCE_DATABASE_NAME, TargetDatabaseName = TARGET_DATABASE_NAME, ArticleName = TABLE_NAME, SourceSchema = SCHEMA, TargetSchema = SCHEMA, ArticleType = DataContracts.Enums.eArticleType.FUNCTION }));
         }
         finally
         {
             _testDatabaseProvider.DropTestDatabase(TARGET_DATABASE_NAME);
         }
     }
     finally
     {
         _testDatabaseProvider.DropTestDatabase(SOURCE_DATABASE_NAME);
     }
 }