Пример #1
0
        public void GetNextWorkUnit_ScaffoldingStateModel_ArgumentOutOfRangeException_StateModel(StateModelState state)
        {
            // Arrange
            var drMock           = new Mock <IDependencyResolver>();
            IWorkUnitFactory wuf = new WorkUnitFactory(drMock.Object);
            var project          = new SqlProject("a", "b", "c");
            var configuration    = ConfigurationModel.GetDefault();
            var targetVersion    = new Version(1, 0);

            Task HandlerFunc(bool b) => Task.CompletedTask;

            var model = new ScaffoldingStateModel(project, configuration, targetVersion, HandlerFunc)
            {
                CurrentState = state
            };

            // Act & Assert
            // ReSharper disable once AssignNullToNotNullAttribute
            Assert.Throws <ArgumentOutOfRangeException>(() => wuf.GetNextWorkUnit(model));
        }
        public void Paths_Get_Set()
        {
            // Arrange
            var project         = new SqlProject("a", "b", "c");
            var configuration   = ConfigurationModel.GetDefault();
            var previousVersion = new Version(1, 0);
            // ReSharper disable once ConvertToLocalFunction
            Func <bool, Task> changeHandler = b => Task.CompletedTask;
            var model       = new ScriptCreationStateModel(project, configuration, previousVersion, true, changeHandler);
            var directories = new DirectoryPaths("projectDirectory", "latestArtifactsDirectory", "newArtifactsDirectory");
            var sourcePaths = new DeploySourcePaths("newDacpacPath", "publishProfilePath", "previousDacpacPath");
            var targetPaths = new DeployTargetPaths("deployScriptPath", "deployReportPath");
            var paths       = new PathCollection(directories, sourcePaths, targetPaths);

            // Act
            model.Paths = paths;

            // Assert
            Assert.AreSame(paths, model.Paths);
        }
Пример #3
0
        public async Task Work_ScriptCreationStateModel_PersistReportError_Async()
        {
            // Arrange
            var testException = new Exception("test exception");
            var daMock        = new Mock <IDacAccess>();

            daMock.Setup(m => m.CreateDeployFilesAsync("previousDacpacPath", "newDacpacPath", "publishProfilePath", true, true))
            .ReturnsAsync(new CreateDeployFilesResult("pre script post", "report", "pre ", " post", new PublishProfile()));
            var fsaMock = new Mock <IFileSystemAccess>();

            fsaMock.Setup(m => m.WriteFileAsync("deployReportPath", "report"))
            .ThrowsAsync(testException);
            var loggerMock = new Mock <ILogger>();
            IWorkUnit <ScriptCreationStateModel> unit = new CreateDeploymentFilesUnit(daMock.Object, fsaMock.Object, loggerMock.Object);
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();

            configuration.CreateDocumentationWithScriptCreation = true;
            var previousVersion = new Version(1, 0);

            Task HandlerFunc(bool b) => Task.CompletedTask;

            var directories = new DirectoryPaths("projectDirectory", "latestArtifactsDirectory", "newArtifactsDirectory");
            var sourcePaths = new DeploySourcePaths("newDacpacPath", "publishProfilePath", "previousDacpacPath");
            var targetPaths = new DeployTargetPaths("deployScriptPath", "deployReportPath");
            var paths       = new PathCollection(directories, sourcePaths, targetPaths);
            var model       = new ScriptCreationStateModel(project, configuration, previousVersion, false, HandlerFunc)
            {
                Paths = paths
            };

            // Act
            await unit.Work(model, CancellationToken.None);

            // Assert
            Assert.AreEqual(StateModelState.TriedToCreateDeploymentFiles, model.CurrentState);
            Assert.IsFalse(model.Result);
            fsaMock.Verify(m => m.WriteFileAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(2));
            loggerMock.Verify(m => m.LogErrorAsync("Script creation aborted."), Times.Once);
            loggerMock.Verify(m => m.LogErrorAsync(testException, "Failed to write deploy report"), Times.Once);
        }
        public async Task GetConfigurationOrDefaultAsync_SqlProject_ConfigurationFound_Async()
        {
            // Arrange
            var fsaMock = new Mock <IFileSystemAccess>();

            fsaMock.Setup(m => m.CheckIfFileExists("C:\\Temp\\Test\\Properties\\ssdtlifecycle.json"))
            .Returns(true);
            fsaMock.Setup(m => m.ReadFileAsync("C:\\Temp\\Test\\Properties\\ssdtlifecycle.json"))
            .ReturnsAsync(() =>
                          "{  \"ArtifactsPath\": \"__Deployment\",  \"PublishProfilePath\": \"Test.publish.xml\",  " +
                          "\"SharedDacpacRepositoryPath\": \"C:\\\\Temp\\\\Repository\\\\\", " +
                          "\"BuildBeforeScriptCreation\": false,  \"CreateDocumentationWithScriptCreation\": true,  " +
                          "\"CommentOutUnnamedDefaultConstraintDrops\": true, \"RemoveSqlCmdStatements\": true, " +
                          "\"ReplaceUnnamedDefaultConstraintDrops\": true,  \"VersionPattern\": \"{MAJOR}.0.{BUILD}\",  " +
                          "\"TrackDacpacVersion\": true,  \"CustomHeader\": \"header\",  \"CustomFooter\": \"footer\"}");
            var vsaMock    = Mock.Of <IVisualStudioAccess>();
            var loggerMock = Mock.Of <ILogger>();
            IConfigurationService service = new ConfigurationService(fsaMock.Object, vsaMock, loggerMock);
            var project = new SqlProject("", "C:\\Temp\\Test\\Test.sqlproj", "");
            var defaultConfiguration = ConfigurationModel.GetDefault();

            // Act
            var configuration = await service.GetConfigurationOrDefaultAsync(project);

            // Assert
            Assert.IsNotNull(configuration);
            Assert.IsFalse(defaultConfiguration.Equals(configuration));
            Assert.AreEqual("__Deployment", configuration.ArtifactsPath);
            Assert.AreEqual("Test.publish.xml", configuration.PublishProfilePath);
            Assert.AreEqual("C:\\Temp\\Repository\\", configuration.SharedDacpacRepositoryPath);
            Assert.IsFalse(configuration.BuildBeforeScriptCreation);
            Assert.IsTrue(configuration.CreateDocumentationWithScriptCreation);
            Assert.IsTrue(configuration.CommentOutUnnamedDefaultConstraintDrops);   // This must be true to cause an validation error for the last assert.
            Assert.IsTrue(configuration.ReplaceUnnamedDefaultConstraintDrops);      // This must be true to cause an validation error for the last assert.
            Assert.AreEqual("{MAJOR}.0.{BUILD}", configuration.VersionPattern);
            Assert.IsTrue(configuration.TrackDacpacVersion);
            Assert.AreEqual("header", configuration.CustomHeader);
            Assert.AreEqual("footer", configuration.CustomFooter);
            Assert.IsTrue(configuration.RemoveSqlCmdStatements);
            Assert.IsTrue(configuration.HasErrors); // This will check if ValidateAll is called correctly.
        }
Пример #5
0
        public async Task DoWorkAsync_ExceptionInWorkUnitWithExceptionInCatch_Async()
        {
            // Arrange
            var testException = new Exception("test exception");
            var loggerMock    = new Mock <ILogger>();

            loggerMock.Setup(m => m.LogErrorAsync(testException, "operation failed."))
            .ThrowsAsync(new Exception("catch exception"));
            var wuMock        = new Mock <IWorkUnit <ScaffoldingStateModel> >();
            var instance      = new AsyncExecutorBaseTestImplementation(loggerMock.Object, () => wuMock.Object);
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();
            var targetVersion = new Version(1, 0);
            var stateList     = new List <bool>();

            Task HandlerFunc(bool b)
            {
                stateList.Add(b);
                return(Task.CompletedTask);
            }

            var model = new ScaffoldingStateModel(project, configuration, targetVersion, HandlerFunc);
            var cts   = new CancellationTokenSource();

            wuMock.Setup(m => m.Work(model, cts.Token))
            .ThrowsAsync(testException);

            // Act
            await instance.CallDoWorkAsync(model, cts.Token);

            // Assert
            Assert.IsNull(model.Result);
            Assert.AreEqual(2, stateList.Count);
            Assert.IsTrue(stateList[0]);
            Assert.IsFalse(stateList[1]);
            wuMock.Verify(m => m.Work(model, cts.Token), Times.Once);
            loggerMock.Verify(m => m.LogInfoAsync("started"), Times.Once);
            loggerMock.Verify(m => m.LogInfoAsync("Creation was canceled by the user."), Times.Never);
            loggerMock.Verify(m => m.LogInfoAsync(It.Is <string>(s => s.StartsWith("completed stateModel in"))), Times.Never);
            loggerMock.Verify(m => m.LogErrorAsync(testException, "operation failed."), Times.Once);
        }
        public async Task Work_ScriptCreationStateModel_NoError_Async()
        {
            // Arrange
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();

            configuration.SharedDacpacRepositoryPath = "C:\\Temp\\Test\\";
            var previousVersion = new Version(1, 2, 3);

            Task HandleWorkInProgressChanged(bool arg) => Task.CompletedTask;

            var directories = new DirectoryPaths("projectDirectory", "latestArtifactsDirectory", "newArtifactsDirectory");
            var sourcePaths = new DeploySourcePaths("newDacpacPath", "publishProfilePath", "previousDacpacPath");
            var targetPaths = new DeployTargetPaths("deployScriptPath", "deployReportPath");
            var paths       = new PathCollection(directories, sourcePaths, targetPaths);
            var model       = new ScriptCreationStateModel(project, configuration, previousVersion, true, HandleWorkInProgressChanged)
            {
                Paths = paths
            };
            var fsaMock = new Mock <IFileSystemAccess>();

            fsaMock.Setup(m => m.EnsureDirectoryExists("C:\\Temp\\Test\\"))
            .Returns(null as string);
            fsaMock.Setup(m => m.CopyFile("newDacpacPath", "C:\\Temp\\Test\\newDacpacPath"))
            .Returns(null as string);
            var loggerMock = new Mock <ILogger>();
            IWorkUnit <ScriptCreationStateModel> unit = new CopyDacpacToSharedDacpacRepositoryUnit(fsaMock.Object, loggerMock.Object);

            // Act
            await unit.Work(model, CancellationToken.None);

            // Assert
            Assert.AreEqual(StateModelState.TriedToCopyDacpacToSharedDacpacRepository, model.CurrentState);
            Assert.IsNull(model.Result);
            fsaMock.Verify(m => m.EnsureDirectoryExists("C:\\Temp\\Test\\"), Times.Once);
            fsaMock.Verify(m => m.CopyFile("newDacpacPath", "C:\\Temp\\Test\\newDacpacPath"), Times.Once);
            loggerMock.Verify(m => m.LogInfoAsync("Copying DACPAC to shared DACPAC repository ..."), Times.Once);
            loggerMock.Verify(m => m.LogErrorAsync(It.IsAny <string>()), Times.Never);
            loggerMock.Verify(m => m.LogErrorAsync(It.IsAny <Exception>(), It.IsAny <string>()), Times.Never);
        }
        public async Task Work_ScriptCreationStateModel_LoadedSuccessful_Async()
        {
            // Arrange
            var project         = new SqlProject("a", "b", "c");
            var configuration   = ConfigurationModel.GetDefault();
            var previousVersion = new Version(1, 2, 3);

            Task HandleWorkInProgressChanged(bool arg) => Task.CompletedTask;

            var model   = new ScriptCreationStateModel(project, configuration, previousVersion, true, HandleWorkInProgressChanged);
            var spsMock = new Mock <ISqlProjectService>();

            spsMock.Setup(m => m.TryLoadSqlProjectPropertiesAsync(project)).ReturnsAsync(true);
            IWorkUnit <ScriptCreationStateModel> unit = new LoadSqlProjectPropertiesUnit(spsMock.Object);

            // Act
            await unit.Work(model, CancellationToken.None);

            // Assert
            Assert.AreEqual(StateModelState.SqlProjectPropertiesLoaded, model.CurrentState);
            Assert.IsNull(model.Result);
        }
        public async Task GetConfigurationOrDefaultAsync_Path_NoConfigurationFound_UseDefault_Async()
        {
            // Arrange
            var exception = new FileNotFoundException("foo");
            var fsaMock   = new Mock <IFileSystemAccess>();

            fsaMock.Setup(m => m.CheckIfFileExists("C:\\Temp\\Test\\Properties\\ssdtlifecycle.json"))
            .Returns(false);
            var vsaMock    = new Mock <IVisualStudioAccess>();
            var loggerMock = new Mock <ILogger>();
            IConfigurationService service = new ConfigurationService(fsaMock.Object, vsaMock.Object, loggerMock.Object);
            var defaultConfiguration      = ConfigurationModel.GetDefault();

            // Act
            var configuration = await service.GetConfigurationOrDefaultAsync("C:\\Temp\\Test\\Properties\\ssdtlifecycle.json");

            // Assert
            Assert.IsNotNull(configuration);
            Assert.IsTrue(defaultConfiguration.Equals(configuration));
            vsaMock.Verify(m => m.ShowModalError(It.IsAny <string>()), Times.Never);
            loggerMock.Verify(m => m.LogErrorAsync(exception, It.IsAny <string>()), Times.Never);
        }
Пример #9
0
        public async Task Work_ScaffoldingStateModel_LoadFailed_Async()
        {
            // Arrange
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();
            var targetVersion = new Version(1, 2, 3);

            Task HandleWorkInProgressChanged(bool arg) => Task.CompletedTask;

            var model   = new ScaffoldingStateModel(project, configuration, targetVersion, HandleWorkInProgressChanged);
            var spsMock = new Mock <ISqlProjectService>();

            spsMock.Setup(m => m.TryLoadPathsForScaffoldingAsync(project, configuration)).ReturnsAsync(null as PathCollection);
            IWorkUnit <ScaffoldingStateModel> unit = new LoadPathsUnit(spsMock.Object);

            // Act
            await unit.Work(model, CancellationToken.None);

            // Assert
            Assert.AreEqual(StateModelState.PathsLoaded, model.CurrentState);
            Assert.IsFalse(model.Result);
        }
Пример #10
0
        public void GetNextWorkUnit_ScaffoldingStateModel_CorrectWorkUnitForTriedToCopyDacpacToSharedDacpacRepository()
        {
            // Arrange
            var drMock           = new Mock <IDependencyResolver>();
            IWorkUnitFactory wuf = new WorkUnitFactory(drMock.Object);
            var project          = new SqlProject("a", "b", "c");
            var configuration    = ConfigurationModel.GetDefault();
            var targetVersion    = new Version(1, 0);

            Task HandlerFunc(bool b) => Task.CompletedTask;

            var model = new ScaffoldingStateModel(project, configuration, targetVersion, HandlerFunc)
            {
                CurrentState = StateModelState.TriedToCopyDacpacToSharedDacpacRepository
            };

            // Act
            var workUnit = wuf.GetNextWorkUnit(model);

            // Assert
            Assert.IsNull(workUnit);
        }
        public async Task Work_ScriptCreationStateModel_CompleteRun_NoFilesDeleted_Async()
        {
            // Arrange
            var fsaMock = new Mock <IFileSystemAccess>();

            fsaMock.Setup(m => m.TryToCleanDirectory("p", "*.refactorlog"))
            .Returns(new string[0]);
            var vsaMock    = new Mock <IVisualStudioAccess>();
            var loggerMock = new Mock <ILogger>();
            IWorkUnit <ScriptCreationStateModel> unit = new DeleteRefactorLogUnit(fsaMock.Object, vsaMock.Object, loggerMock.Object);
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();

            configuration.DeleteRefactorlogAfterVersionedScriptGeneration = true;
            var previousVersion = new Version(1, 0);

            Task HandlerFunc(bool b) => Task.CompletedTask;

            var directories = new DirectoryPaths("projectDirectory", "latestArtifactsDirectory", "newArtifactsDirectory");
            var sourcePaths = new DeploySourcePaths("newDacpacPath", "publishProfilePath", "previousDacpacPath");
            var targetPaths = new DeployTargetPaths("deployScriptPath", "deployReportPath");
            var paths       = new PathCollection(directories, sourcePaths, targetPaths);
            var model       = new ScriptCreationStateModel(project, configuration, previousVersion, true, HandlerFunc)
            {
                Paths = paths
            };

            // Act
            await unit.Work(model, CancellationToken.None);

            // Assert
            Assert.AreEqual(StateModelState.DeletedRefactorLog, model.CurrentState);
            Assert.IsNull(model.Result);
            fsaMock.Verify(m => m.TryToCleanDirectory("projectDirectory", "*.refactorlog"), Times.Once);
            vsaMock.Verify(m => m.RemoveItemFromProjectRoot(project, It.IsAny <string>()), Times.Never);
            loggerMock.Verify(m => m.LogInfoAsync("Deleting refactorlog files ..."), Times.Once);
            loggerMock.Verify(m => m.LogTraceAsync("No files were deleted."), Times.Once);
            loggerMock.Verify(m => m.LogTraceAsync(It.Is <string>(s => s.StartsWith("Deleted file"))), Times.Never);
        }
Пример #12
0
        public async Task Work_ScaffoldingStateModel_BuildFailed_Async()
        {
            // Arrange
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();
            var targetVersion = new Version(1, 2, 3);

            Task HandleWorkInProgressChanged(bool arg) => Task.CompletedTask;

            var model  = new ScaffoldingStateModel(project, configuration, targetVersion, HandleWorkInProgressChanged);
            var bsMock = new Mock <IBuildService>();

            bsMock.Setup(m => m.BuildProjectAsync(project)).ReturnsAsync(false);
            IWorkUnit <ScaffoldingStateModel> unit = new BuildProjectUnit(bsMock.Object);

            // Act
            await unit.Work(model, CancellationToken.None);

            // Assert
            Assert.AreEqual(StateModelState.TriedToBuildProject, model.CurrentState);
            Assert.IsFalse(model.Result);
        }
Пример #13
0
        public void GetNextWorkUnit_ScriptCreationStateModel_CorrectWorkUnitForDeletedLatestArtifacts()
        {
            // Arrange
            var drMock           = new Mock <IDependencyResolver>();
            IWorkUnitFactory wuf = new WorkUnitFactory(drMock.Object);
            var project          = new SqlProject("a", "b", "c");
            var configuration    = ConfigurationModel.GetDefault();
            var previousVersion  = new Version(1, 0);

            Task HandlerFunc(bool b) => Task.CompletedTask;

            var model = new ScriptCreationStateModel(project, configuration, previousVersion, false, HandlerFunc)
            {
                CurrentState = StateModelState.DeletedLatestArtifacts
            };

            // Act
            var workUnit = wuf.GetNextWorkUnit(model);

            // Assert
            Assert.IsNull(workUnit);
        }
Пример #14
0
        public async Task DoWorkAsync_PreviousUnitFailed_Async()
        {
            // Arrange
            var loggerMock = new Mock <ILogger>();
            var instance   = new AsyncExecutorBaseTestImplementation(loggerMock.Object, () =>
            {
                Assert.Fail("This shouldn't be called");
                return(null);
            });
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();
            var targetVersion = new Version(1, 0);
            var stateList     = new List <bool>();

            Task HandlerFunc(bool b)
            {
                stateList.Add(b);
                return(Task.CompletedTask);
            }

            var model = new ScaffoldingStateModel(project, configuration, targetVersion, HandlerFunc)
            {
                Result = false
            };

            // Act
            await instance.CallDoWorkAsync(model, CancellationToken.None);

            // Assert
            Assert.IsFalse(model.Result);
            Assert.AreEqual(2, stateList.Count);
            Assert.IsTrue(stateList[0]);
            Assert.IsFalse(stateList[1]);
            loggerMock.Verify(m => m.LogInfoAsync("started"), Times.Once);
            loggerMock.Verify(m => m.LogInfoAsync("Creation was canceled by the user."), Times.Never);
            loggerMock.Verify(m => m.LogInfoAsync(It.Is <string>(s => s.StartsWith("completed stateModel in"))), Times.Once);
        }
Пример #15
0
        public void GetNextWorkUnit_ScriptCreationStateModel_CorrectWorkUnitForModifiedDeploymentScript(bool createLatest)
        {
            // Arrange
            var fsaMock          = Mock.Of <IFileSystemAccess>();
            var vsaMock          = Mock.Of <IVisualStudioAccess>();
            var loggerMock       = Mock.Of <ILogger>();
            var expectedWorkUnit = new DeleteRefactorLogUnit(fsaMock, vsaMock, loggerMock);
            var drMock           = new Mock <IDependencyResolver>();

            drMock.Setup(m => m.Get <DeleteRefactorLogUnit>()).Returns(expectedWorkUnit);
            IWorkUnitFactory wuf = new WorkUnitFactory(drMock.Object);
            var project          = new SqlProject("a", "b", "c");
            var configuration    = ConfigurationModel.GetDefault();
            var previousVersion  = new Version(1, 0);

            Task HandlerFunc(bool b) => Task.CompletedTask;

            var model = new ScriptCreationStateModel(project, configuration, previousVersion, createLatest, HandlerFunc)
            {
                CurrentState = StateModelState.ModifiedDeploymentScript
            };

            // Act
            var workUnit = wuf.GetNextWorkUnit(model);

            // Assert
            if (createLatest)
            {
                Assert.IsNull(workUnit);
                drMock.Verify(m => m.Get <DeleteRefactorLogUnit>(), Times.Never);
            }
            else
            {
                Assert.AreSame(expectedWorkUnit, workUnit);
                drMock.Verify(m => m.Get <DeleteRefactorLogUnit>(), Times.Once);
            }
        }
        public async Task GetConfigurationOrDefaultAsync_Path_ErrorWhileReading_UseDefault_Async()
        {
            // Arrange
            var exception = new FileNotFoundException("foo");
            var fsaMock   = new Mock <IFileSystemAccess>();

            fsaMock.Setup(m => m.CheckIfFileExists("C:\\Temp\\Test\\Properties\\ssdtlifecycle.json"))
            .Returns(true);
            fsaMock.Setup(m => m.ReadFileAsync("C:\\Temp\\Test\\Properties\\ssdtlifecycle.json"))
            .Throws(exception);
            var vsaMock    = new Mock <IVisualStudioAccess>();
            var loggerMock = new Mock <ILogger>();
            IConfigurationService service = new ConfigurationService(fsaMock.Object, vsaMock.Object, loggerMock.Object);
            var defaultConfiguration      = ConfigurationModel.GetDefault();

            // Act
            var configuration = await service.GetConfigurationOrDefaultAsync("C:\\Temp\\Test\\Properties\\ssdtlifecycle.json");

            // Assert
            Assert.IsNotNull(configuration);
            Assert.IsTrue(defaultConfiguration.Equals(configuration));
            vsaMock.Verify(m => m.ShowModalError(It.Is <string>(s => s.Contains("Accessing the configuration file failed."))), Times.Once);
            loggerMock.Verify(m => m.LogErrorAsync(exception, It.Is <string>(s => s.Contains("Failed to read the configuration from file"))), Times.Once);
        }
        public async Task Work_ScaffoldingStateModel_FormattedSuccessful_Async()
        {
            // Arrange
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();
            var targetVersion = new Version(1, 2, 3);
            var expectedFormattedTargetVersion = new Version(1, 2, 3, 0);

            Task HandleWorkInProgressChanged(bool arg) => Task.CompletedTask;

            var model  = new ScaffoldingStateModel(project, configuration, targetVersion, HandleWorkInProgressChanged);
            var vsMock = new Mock <IVersionService>();

            vsMock.Setup(m => m.FormatVersion(targetVersion, configuration)).Returns(expectedFormattedTargetVersion.ToString());
            IWorkUnit <ScaffoldingStateModel> unit = new FormatTargetVersionUnit(vsMock.Object);

            // Act
            await unit.Work(model, CancellationToken.None);

            // Assert
            Assert.AreEqual(StateModelState.FormattedTargetVersionLoaded, model.CurrentState);
            Assert.IsNull(model.Result);
            Assert.AreEqual(expectedFormattedTargetVersion, model.FormattedTargetVersion);
        }
Пример #18
0
        public async Task Work_ScriptCreationStateModel_PublishProfileValidation_Async(bool removeSqlCmdStatements,
                                                                                       bool createNewDatabase,
                                                                                       bool backupDatabaseBeforeChanges,
                                                                                       bool scriptDatabaseOptions,
                                                                                       bool scriptDeployStateChecks,
                                                                                       bool?expectedResult)
        {
            // Arrange
            var daMock = new Mock <IDacAccess>();

            daMock.Setup(m => m.CreateDeployFilesAsync("previousDacpacPath", "newDacpacPath", "publishProfilePath", true, true))
            .ReturnsAsync(new CreateDeployFilesResult("pre script post", "report", "pre ", " post", new PublishProfile
            {
                CreateNewDatabase           = createNewDatabase,
                BackupDatabaseBeforeChanges = backupDatabaseBeforeChanges,
                ScriptDatabaseOptions       = scriptDatabaseOptions,
                ScriptDeployStateChecks     = scriptDeployStateChecks
            }));
            var fsaMock    = new Mock <IFileSystemAccess>();
            var loggerMock = new Mock <ILogger>();
            IWorkUnit <ScriptCreationStateModel> unit = new CreateDeploymentFilesUnit(daMock.Object, fsaMock.Object, loggerMock.Object);
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();

            configuration.CreateDocumentationWithScriptCreation = true;
            configuration.RemoveSqlCmdStatements = removeSqlCmdStatements;
            var previousVersion = new Version(1, 0);

            Task HandlerFunc(bool b) => Task.CompletedTask;

            var directories = new DirectoryPaths("projectDirectory", "latestArtifactsDirectory", "newArtifactsDirectory");
            var sourcePaths = new DeploySourcePaths("newDacpacPath", "publishProfilePath", "previousDacpacPath");
            var targetPaths = new DeployTargetPaths("deployScriptPath", "deployReportPath");
            var paths       = new PathCollection(directories, sourcePaths, targetPaths);
            var model       = new ScriptCreationStateModel(project, configuration, previousVersion, false, HandlerFunc)
            {
                Paths = paths
            };

            // Act
            await unit.Work(model, CancellationToken.None);

            // Assert
            Assert.AreEqual(StateModelState.TriedToCreateDeploymentFiles, model.CurrentState);
            Assert.AreEqual(expectedResult, model.Result);
            if (removeSqlCmdStatements && createNewDatabase)
            {
                loggerMock.Verify(m => m.LogErrorAsync($"{nameof(PublishProfile.CreateNewDatabase)} cannot bet set to true, when {nameof(ConfigurationModel.RemoveSqlCmdStatements)} is also true."), Times.Once);
            }
            if (removeSqlCmdStatements && backupDatabaseBeforeChanges)
            {
                loggerMock.Verify(m => m.LogErrorAsync($"{nameof(PublishProfile.BackupDatabaseBeforeChanges)} cannot bet set to true, when {nameof(ConfigurationModel.RemoveSqlCmdStatements)} is also true."), Times.Once);
            }
            if (removeSqlCmdStatements && scriptDatabaseOptions)
            {
                loggerMock.Verify(m => m.LogErrorAsync($"{nameof(PublishProfile.ScriptDatabaseOptions)} cannot bet set to true, when {nameof(ConfigurationModel.RemoveSqlCmdStatements)} is also true."), Times.Once);
            }
            if (removeSqlCmdStatements && scriptDeployStateChecks)
            {
                loggerMock.Verify(m => m.LogErrorAsync($"{nameof(PublishProfile.ScriptDeployStateChecks)} cannot bet set to true, when {nameof(ConfigurationModel.RemoveSqlCmdStatements)} is also true."), Times.Once);
            }

            if (expectedResult == null)
            {
                fsaMock.Verify(m => m.WriteFileAsync("deployScriptPath", "pre script post"), Times.Once);
                fsaMock.Verify(m => m.WriteFileAsync("deployReportPath", "report"), Times.Once);
            }
            else
            {
                fsaMock.Verify(m => m.WriteFileAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            }
        }