public async Task Work_ScaffoldingStateModel_InvalidCharsInNewDacpacPath_Async()
        {
            // Arrange
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();

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

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

            var directories = new DirectoryPaths("projectDirectory", "latestArtifactsDirectory", "newArtifactsDirectory");
            var sourcePaths = new DeploySourcePaths("newDacpacPath" + new string(Path.GetInvalidPathChars()), "publishProfilePath", "previousDacpacPath");
            var targetPaths = new DeployTargetPaths("deployScriptPath", "deployReportPath");
            var paths       = new PathCollection(directories, sourcePaths, targetPaths);
            var model       = new ScaffoldingStateModel(project, configuration, targetVersion, HandleWorkInProgressChanged)
            {
                Paths = paths
            };
            var fsaMock    = new Mock <IFileSystemAccess>();
            var loggerMock = new Mock <ILogger>();
            IWorkUnit <ScaffoldingStateModel> unit = new CopyDacpacToSharedDacpacRepositoryUnit(fsaMock.Object, loggerMock.Object);

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

            // Assert
            Assert.AreEqual(StateModelState.TriedToCopyDacpacToSharedDacpacRepository, model.CurrentState);
            Assert.IsFalse(model.Result);
            fsaMock.Verify(m => m.EnsureDirectoryExists(It.IsAny <string>()), Times.Never);
            fsaMock.Verify(m => m.CopyFile(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            loggerMock.Verify(m => m.LogInfoAsync("Copying DACPAC to shared DACPAC repository ..."), Times.Once);
            loggerMock.Verify(m => m.LogErrorAsync(It.Is <string>(s => s.StartsWith("Failed to copy DACPAC to shared DACPAC repository: "))), Times.Once);
        }
        public async Task Work_ScriptCreationStateModel_NoRepositoryConfigured_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 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>();
            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(It.IsAny <string>()), Times.Never);
            fsaMock.Verify(m => m.CopyFile(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            loggerMock.Verify(m => m.LogErrorAsync(It.IsAny <string>()), Times.Never);
            loggerMock.Verify(m => m.LogErrorAsync(It.IsAny <Exception>(), It.IsAny <string>()), Times.Never);
        }
Exemple #3
0
        public void GetNextWorkUnit_ScriptCreationStateModel_CorrectWorkUnitForTriedToCopyBuildResult()
        {
            // Arrange
            var fsaMock          = Mock.Of <IFileSystemAccess>();
            var loggerMock       = Mock.Of <ILogger>();
            var expectedWorkUnit = new CopyDacpacToSharedDacpacRepositoryUnit(fsaMock, loggerMock);
            var drMock           = new Mock <IDependencyResolver>();

            drMock.Setup(m => m.Get <CopyDacpacToSharedDacpacRepositoryUnit>()).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, false, HandlerFunc)
            {
                CurrentState = StateModelState.TriedToCopyBuildResult
            };

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

            // Assert
            Assert.AreSame(expectedWorkUnit, workUnit);
            drMock.Verify(m => m.Get <CopyDacpacToSharedDacpacRepositoryUnit>(), Times.Once);
        }
        public void Work_ScaffoldingStateModel_ArgumentNullException_StateModel()
        {
            // Arrange
            var fsaMock    = new Mock <IFileSystemAccess>();
            var loggerMock = new Mock <ILogger>();
            IWorkUnit <ScaffoldingStateModel> unit = new CopyDacpacToSharedDacpacRepositoryUnit(fsaMock.Object, loggerMock.Object);

            // Act & Assert
            // ReSharper disable once AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => unit.Work(null, CancellationToken.None));
        }