Example #1
0
        public void Test_Run_With_Faulty_Script_Throws_Error_Must_Rollback_All_Changes()
        {
            //arrange
            var localVersionService = new LocalVersionService(_traceService);

            localVersionService.Init(_testConfiguration.WorkspacePath);

            localVersionService.IncrementMajorVersion(_testConfiguration.WorkspacePath, null);
            _testDataService.CreateScriptFile(Path.Combine(Path.Combine(_testConfiguration.WorkspacePath, "v1.00"), $"test_v1_00.sql"), _testDataService.GetSqlForCreateDbObject($"test_v1_00"));
            _testDataService.CreateScriptFile(Path.Combine(Path.Combine(_testConfiguration.WorkspacePath, "v1.00"), $".sql"), _testDataService.GetSqlForCreateBulkTable("TestCsv"));
            File.Copy(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Core"), "TestCsv.csv"), Path.Combine(Path.Combine(_testConfiguration.WorkspacePath, "v1.00"), "TestCsv.csv"));
            _testDataService.CreateScriptFile(Path.Combine(Path.Combine(_testConfiguration.WorkspacePath, "v1.00"), $"test_v1_00_error.sql"), _testDataService.GetSqlForCreateDbObjectWithError($"test_v1_00_error"));

            //act
            try
            {
                var migrationService = _migrationServiceFactory.Create(_testConfiguration.Platform);
                migrationService.Initialize(_testConfiguration.ConnectionString);
                migrationService.Run(_testConfiguration.WorkspacePath, "v1.00", autoCreateDatabase: true);
            }
            catch (Exception ex)
            {
                //used try/catch this instead of Assert.ThrowsException because different vendors
                //throws different exception type and message content
                ex.Message.ShouldNotBeNullOrEmpty();
            }

            //assert
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, "test_v1_00").ShouldBeFalse();
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, "TestCsv").ShouldBeFalse();
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, "test_v1_00_error").ShouldBeFalse();
        }
        public void Test_Run_With_Faulty_Script_Throws_Error_Must_Rollback_All_Changes()
        {
            //arrange
            var directoryService = new DirectoryService();
            var fileService      = new FileService();
            var workspaceService = new WorkspaceService(_traceService, directoryService, fileService);

            workspaceService.Init(_testConfiguration.WorkspacePath);

            workspaceService.IncrementMajorVersion(_testConfiguration.WorkspacePath, null);
            _testDataService.CreateScriptFile(Path.Combine(Path.Combine(_testConfiguration.WorkspacePath, "v1.00"), $"test_v1_00.sql"), _testDataService.GetSqlForCreateDbObject(TEST_DBOBJECTS.DB_OBJECT_1));
            _testDataService.CreateScriptFile(Path.Combine(Path.Combine(_testConfiguration.WorkspacePath, "v1.00"), $".sql"), _testDataService.GetSqlForCreateBulkTable(TEST_DBOBJECTS.TestCsv));
            File.Copy(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Data"), "TestCsv.csv"), Path.Combine(Path.Combine(_testConfiguration.WorkspacePath, "v1.00"), "TestCsv.csv"));
            _testDataService.CreateScriptFile(Path.Combine(Path.Combine(_testConfiguration.WorkspacePath, "v1.00"), $"test_v1_00_error.sql"), _testDataService.GetSqlForCreateDbObjectWithError(TEST_DBOBJECTS.DB_OBJECT_2));

            //act
            try
            {
                var configuration    = _testConfiguration.GetFreshConfiguration();
                var migrationService = _migrationServiceFactory.Create(configuration.Platform);
                migrationService.Run();
            }
            catch (Exception ex)
            {
                //used try/catch this instead of Assert.ThrowsException because different vendors
                //throws different exception type and message content
                ex.Message.ShouldNotBeNullOrEmpty();
            }

            //assert
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, TEST_DBOBJECTS.DB_OBJECT_1).ShouldBeFalse();
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, TEST_DBOBJECTS.TestCsv).ShouldBeFalse();
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, TEST_DBOBJECTS.DB_OBJECT_2).ShouldBeFalse();
        }
        public void Test_Bulk_Import_With_Default_Separated()
        {
            //arrange - prepare bulk destination table
            var localVersionService = new LocalVersionService(_traceService);

            localVersionService.Init(_testConfiguration.WorkspacePath);

            localVersionService.IncrementMajorVersion(_testConfiguration.WorkspacePath, null);
            string v100Directory = Path.Combine(_testConfiguration.WorkspacePath, "v1.00");

            _testDataService.CreateScriptFile(Path.Combine(v100Directory, $"TestCsv.sql"), _testDataService.GetSqlForCreateBulkTable("TestCsv"));

            //act
            var migrationService = _migrationServiceFactory.Create(_testConfiguration.Platform);

            migrationService.Initialize(_testConfiguration.ConnectionString);
            migrationService.Run(_testConfiguration.WorkspacePath, "v1.00", autoCreateDatabase: true);

            //assert
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, "TestCsv").ShouldBeTrue();

            //arrange - add new minor version with csv files
            localVersionService.IncrementMinorVersion(_testConfiguration.WorkspacePath, null);
            string v101Directory = Path.Combine(_testConfiguration.WorkspacePath, "v1.01");

            File.Copy(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Core"), "TestCsv.csv"), Path.Combine(v101Directory, "TestCsv.csv"));

            //act
            migrationService.Run(_testConfiguration.WorkspacePath, "v1.01", autoCreateDatabase: true);

            //assert
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, "TestCsv").ShouldBeTrue();

            var results      = _testDataService.GetBulkTestData(_testConfiguration.ConnectionString, "TestCsv");
            var testDataRows = new List <BulkTestDataRow>
            {
                new BulkTestDataRow {
                    FirstName = "Jack", LastName = "Poole", BirthDate = new DateTime(1980, 1, 1)
                },
                new BulkTestDataRow {
                    FirstName = "Diana", LastName = "Churchill", BirthDate = new DateTime(1980, 1, 1)
                },
                new BulkTestDataRow {
                    FirstName = "Rebecca", LastName = "Lyman", BirthDate = new DateTime(1980, 1, 1)
                },
                new BulkTestDataRow {
                    FirstName = "Sam", LastName = "Macdonald", BirthDate = new DateTime(1980, 1, 1)
                },
                new BulkTestDataRow {
                    FirstName = "Matt", LastName = "Paige", BirthDate = new DateTime(1980, 1, 1)
                },
            };

            results.Count.ShouldBe(5);
            testDataRows.All(t => results.Exists(r =>
                                                 t.FirstName == r.FirstName &&
                                                 t.LastName == r.LastName &&
                                                 t.BirthDate == r.BirthDate
                                                 )).ShouldBeTrue();
        }
Example #4
0
        public void Test_Bulk_Import_With_Default_Separator()
        {
            //arrange - prepare bulk destination table
            var directoryService = new DirectoryService();
            var fileService      = new FileService();
            var workspaceService = new WorkspaceService(_traceService, directoryService, fileService);

            workspaceService.Init(_testConfiguration.WorkspacePath);

            workspaceService.IncrementMajorVersion(_testConfiguration.WorkspacePath, null);
            string v100Directory = Path.Combine(_testConfiguration.WorkspacePath, "v1.00");

            _testDataService.CreateScriptFile(Path.Combine(v100Directory, $"TestCsv.sql"), _testDataService.GetSqlForCreateBulkTable(TEST_DBOBJECTS.TestCsv));

            //act
            var configuration = _testConfiguration.GetFreshConfiguration();

            configuration.TargetVersion = "v1.00";

            var migrationService = _migrationServiceFactory.Create(configuration.Platform);

            migrationService.Run();

            //assert
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, TEST_DBOBJECTS.TestCsv).ShouldBeTrue();

            //arrange - add new minor version with csv files
            workspaceService.IncrementMinorVersion(_testConfiguration.WorkspacePath, null);
            string v101Directory = Path.Combine(_testConfiguration.WorkspacePath, "v1.01");

            File.Copy(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Data"), "TestCsv.csv"), Path.Combine(v101Directory, "TestCsv.csv"));

            //act
            configuration.TargetVersion = "v1.01";
            migrationService.Run();

            //assert
            _testDataService.CheckIfDbObjectExist(_testConfiguration.ConnectionString, TEST_DBOBJECTS.TestCsv).ShouldBeTrue();

            var results      = _testDataService.GetBulkTestData(_testConfiguration.ConnectionString, TEST_DBOBJECTS.TestCsv);
            var testDataRows = new List <BulkTestDataRow>
            {
                new BulkTestDataRow {
                    FirstName = "Jack", LastName = "Poole", BirthDate = "1980-01-01"
                },
                new BulkTestDataRow {
                    FirstName = "Diana", LastName = "Churchill", BirthDate = "1980-01-01"
                },
                new BulkTestDataRow {
                    FirstName = "Rebecca", LastName = "Lyman", BirthDate = "1980-01-01"
                },
                new BulkTestDataRow {
                    FirstName = "Sam", LastName = "Macdonald", BirthDate = "1980-01-01"
                },
                new BulkTestDataRow {
                    FirstName = "Matt", LastName = "Paige", BirthDate = "1980-01-01"
                }
            };

            results.Count.ShouldBe(5);
            testDataRows.All(t => results.Exists(r =>
                                                 t.FirstName == r.FirstName &&
                                                 t.LastName == r.LastName &&
                                                 t.BirthDate == r.BirthDate
                                                 )).ShouldBeTrue();
        }