public async Task Work_ScaffoldingStateModel_InvalidVersion_Async(string dacVersionString) { // Arrange var dacVersion = Version.Parse(dacVersionString); var formattedTargetVersion = new Version(1, 2, 4); var project = new SqlProject("a", "b", "c"); project.ProjectProperties.DacVersion = dacVersion; 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) { FormattedTargetVersion = formattedTargetVersion }; var vsaMock = new Mock <IVisualStudioAccess>(); var loggerMock = new Mock <ILogger>(); IWorkUnit <ScaffoldingStateModel> unit = new ValidateTargetVersionUnit(vsaMock.Object, loggerMock.Object); // Act await unit.Work(model, CancellationToken.None); // Assert Assert.AreEqual(StateModelState.FormattedTargetVersionValidated, model.CurrentState); Assert.IsFalse(model.Result); vsaMock.Verify(m => m.ShowModalError("Please change the DAC version in the SQL project settings (see output window)."), Times.Once); loggerMock.Verify(m => m.LogErrorAsync(It.IsAny <string>()), Times.Once); }
public void GetNextWorkUnit_ScaffoldingStateModel_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 targetVersion = new Version(1, 0); Task HandlerFunc(bool b) => Task.CompletedTask; var model = new ScaffoldingStateModel(project, configuration, targetVersion, HandlerFunc) { CurrentState = StateModelState.TriedToCopyBuildResult }; // Act var workUnit = wuf.GetNextWorkUnit(model); // Assert Assert.AreSame(expectedWorkUnit, workUnit); drMock.Verify(m => m.Get <CopyDacpacToSharedDacpacRepositoryUnit>(), Times.Once); }
public async Task Work_ScaffoldingStateModel_CopyFailed_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 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 ScaffoldingStateModel(project, configuration, targetVersion, HandleWorkInProgressChanged) { Paths = paths }; var bsMock = new Mock <IBuildService>(); bsMock.Setup(m => m.CopyBuildResultAsync(project, paths.Directories.NewArtifactsDirectory)).ReturnsAsync(false); IWorkUnit <ScaffoldingStateModel> unit = new CopyBuildResultUnit(bsMock.Object); // Act await unit.Work(model, CancellationToken.None); // Assert Assert.AreEqual(StateModelState.TriedToCopyBuildResult, model.CurrentState); Assert.IsFalse(model.Result); }
public async Task Work_ScaffoldingStateModel_CompleteRun_Async() { // Arrange var fsaMock = new Mock <IFileSystemAccess>(); var loggerMock = new Mock <ILogger>(); IWorkUnit <ScaffoldingStateModel> unit = new CleanNewArtifactsDirectoryUnit(fsaMock.Object, loggerMock.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 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 ScaffoldingStateModel(project, configuration, targetVersion, 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); }
public void GetNextWorkUnit_ScaffoldingStateModel_CorrectWorkUnitForProjectPropertiesLoaded() { // Arrange var vsMock = Mock.Of <IVersionService>(); var expectedWorkUnit = new FormatTargetVersionUnit(vsMock); var drMock = new Mock <IDependencyResolver>(); drMock.Setup(m => m.Get <FormatTargetVersionUnit>()).Returns(expectedWorkUnit); 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.SqlProjectPropertiesLoaded }; // Act var workUnit = wuf.GetNextWorkUnit(model); // Assert Assert.AreSame(expectedWorkUnit, workUnit); drMock.Verify(m => m.Get <FormatTargetVersionUnit>(), Times.Once); }
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_ScaffoldingStateModel_LoadedSuccessful_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 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 spsMock = new Mock <ISqlProjectService>(); spsMock.Setup(m => m.TryLoadPathsForScaffoldingAsync(project, configuration)).ReturnsAsync(paths); IWorkUnit <ScaffoldingStateModel> unit = new LoadPathsUnit(spsMock.Object); // Act await unit.Work(model, CancellationToken.None); // Assert Assert.AreEqual(StateModelState.PathsLoaded, model.CurrentState); Assert.IsNull(model.Result); }
public async Task DoWorkAsync_ExceptionInFinally_Async() { // Arrange var loggerMock = new Mock <ILogger>(); var invokedOnce = false; var wuMock = new Mock <IWorkUnit <ScaffoldingStateModel> >(); var instance = new AsyncExecutorBaseTestImplementation(loggerMock.Object, () => { if (invokedOnce) { return(null); } invokedOnce = true; return(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); if (stateList.Count == 2) { throw new Exception("test exception"); } return(Task.CompletedTask); } var model = new ScaffoldingStateModel(project, configuration, targetVersion, HandlerFunc); var cts = new CancellationTokenSource(); // Act await instance.CallDoWorkAsync(model, cts.Token); // Assert Assert.IsTrue(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.Once); }
public void FormattedTargetVersion_Get_Set() { // Arrange var project = new SqlProject("a", "b", "c"); var configuration = ConfigurationModel.GetDefault(); var targetVersion = new Version(1, 0); // ReSharper disable once ConvertToLocalFunction Func <bool, Task> changeHandler = b => Task.CompletedTask; var model = new ScaffoldingStateModel(project, configuration, targetVersion, changeHandler); var formattedVersion = new Version(1, 0, 0); // Act model.FormattedTargetVersion = formattedVersion; // Assert Assert.AreSame(formattedVersion, model.FormattedTargetVersion); }
public void Constructor_CorrectInitialization() { // Arrange var project = new SqlProject("a", "b", "c"); var configuration = ConfigurationModel.GetDefault(); var targetVersion = new Version(1, 0); // ReSharper disable once ConvertToLocalFunction Func <bool, Task> changeHandler = b => Task.CompletedTask; // Act var model = new ScaffoldingStateModel(project, configuration, targetVersion, changeHandler); // Assert Assert.AreSame(project, model.Project); Assert.AreSame(configuration, model.Configuration); Assert.AreSame(targetVersion, model.TargetVersion); Assert.AreSame(changeHandler, model.HandleWorkInProgressChanged); }
public void Paths_Get_Set() { // Arrange var project = new SqlProject("a", "b", "c"); var configuration = ConfigurationModel.GetDefault(); var targetVersion = new Version(1, 0); // ReSharper disable once ConvertToLocalFunction Func <bool, Task> changeHandler = b => Task.CompletedTask; var model = new ScaffoldingStateModel(project, configuration, targetVersion, 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); }
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)); }
IWorkUnit <ScaffoldingStateModel> IWorkUnitFactory.GetNextWorkUnit(ScaffoldingStateModel stateModel) { if (stateModel == null) { throw new ArgumentNullException(nameof(stateModel)); } switch (stateModel.CurrentState) { case StateModelState.Initialized: return(_dependencyResolver.Get <LoadSqlProjectPropertiesUnit>()); case StateModelState.SqlProjectPropertiesLoaded: return(_dependencyResolver.Get <FormatTargetVersionUnit>()); case StateModelState.FormattedTargetVersionLoaded: return(_dependencyResolver.Get <ValidateTargetVersionUnit>()); case StateModelState.FormattedTargetVersionValidated: return(_dependencyResolver.Get <LoadPathsUnit>()); case StateModelState.PathsLoaded: return(_dependencyResolver.Get <BuildProjectUnit>()); case StateModelState.TriedToBuildProject: return(_dependencyResolver.Get <CleanNewArtifactsDirectoryUnit>()); case StateModelState.TriedToCleanArtifactsDirectory: return(_dependencyResolver.Get <CopyBuildResultUnit>()); case StateModelState.TriedToCopyBuildResult: return(_dependencyResolver.Get <CopyDacpacToSharedDacpacRepositoryUnit>()); case StateModelState.TriedToCopyDacpacToSharedDacpacRepository: return(null); default: throw new ArgumentOutOfRangeException(nameof(stateModel) + '.' + nameof(IStateModel.CurrentState)); } }
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); }
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_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); }
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); }
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); }