public async Task Work_ScriptCreationStateModel_CompleteRun_NoFilesDeleted_ConfigurationDisabled_Async()
        {
            // Arrange
            var fsaMock    = new Mock <IFileSystemAccess>();
            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 = false;
            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(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            vsaMock.Verify(m => m.RemoveItemFromProjectRoot(project, It.IsAny <string>()), Times.Never);
            loggerMock.Verify(m => m.LogInfoAsync(It.IsAny <string>()), Times.Never);
            loggerMock.Verify(m => m.LogTraceAsync(It.IsAny <string>()), Times.Never);
        }
        public void Work_ScriptCreationStateModel_ArgumentNullException_StateModel()
        {
            // Arrange
            var fsaMock    = new Mock <IFileSystemAccess>();
            var vsaMock    = new Mock <IVisualStudioAccess>();
            var loggerMock = new Mock <ILogger>();
            IWorkUnit <ScriptCreationStateModel> unit = new DeleteRefactorLogUnit(fsaMock.Object, vsaMock.Object, loggerMock.Object);

            // Act & Assert
            // ReSharper disable once AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => unit.Work(null, CancellationToken.None));
        }
예제 #3
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);
            }
        }