public async Task Work_ScriptCreationStateModel_CompleteRun_Async()
        {
            // Arrange
            var fsaMock    = new Mock <IFileSystemAccess>();
            var loggerMock = new Mock <ILogger>();
            IWorkUnit <ScriptCreationStateModel> unit = new CleanNewArtifactsDirectoryUnit(fsaMock.Object, loggerMock.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 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.TriedToCleanArtifactsDirectory, model.CurrentState);
            Assert.IsNull(model.Result);
            fsaMock.Verify(m => m.TryToCleanDirectory("newArtifactsDirectory"), Times.Once);
            loggerMock.Verify(m => m.LogInfoAsync(It.IsNotNull <string>()), Times.Once);
        }
Example #2
0
        public void GetNextWorkUnit_ScriptCreationStateModel_CorrectWorkUnitForTriedToBuildProject()
        {
            // Arrange
            var fsaMock          = Mock.Of <IFileSystemAccess>();
            var loggerMock       = Mock.Of <ILogger>();
            var expectedWorkUnit = new CleanNewArtifactsDirectoryUnit(fsaMock, loggerMock);
            var drMock           = new Mock <IDependencyResolver>();

            drMock.Setup(m => m.Get <CleanNewArtifactsDirectoryUnit>()).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.TriedToBuildProject
            };

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

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

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