public void Execute_NoProjectFile_ShouldLookupProjectFileInWorkDirectory() { var workDirectory = new DirectoryStub("Src") { new DirectoryStub("DotNet") { new DirectoryStub("Build"), new FileStub("Rosalia.sln") }, new DirectoryStub("Artifacts"), new DirectoryStub("Scripts") }; var task = new MsBuildTask { ToolPath = "myMsBuild" }; task.AssertCommand( workDirectory["DotNet"]["Build"], (msBuildPath, msBuildArguments) => { Assert.That(msBuildArguments.Trim(), Is.EqualTo("Src\\DotNet\\Rosalia.sln")); }); }
public void RegisterAssets_ShouldRegisterOneAssetInfo_WhenDirectoryHasThreeFiles_ButOnlyOneAssetFile() { // Arrange const string assetDiscoveryPath = "Assets Root Directory"; var assetInfo = CreateNewAssetInfo(); var root = new DirectoryStub { Files = new[] { Substitute.For <IFile>(), Substitute.For <IFile>(), CreateAssetFile(assetInfo) } }; _fileSystem.GetDirectory(Arg.Any <string>()).Returns(root); var assetStore = GetAssetStore(); // Act assetStore.RegisterAssets(assetDiscoveryPath); // Assert Assert.That(assetStore.GetRegisteredAssets(), Has.One.Items); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo)); }
public void RegisterAssets_ShouldRegisterThreeAssetInfos_WhenDirectoryHasThreeAssetFiles() { // Arrange const string assetDiscoveryPath = "Assets Root Directory"; var assetInfo1 = CreateNewAssetInfo(); var assetInfo2 = CreateNewAssetInfo(); var assetInfo3 = CreateNewAssetInfo(); var root = new DirectoryStub { Files = new[] { CreateAssetFile(assetInfo1), CreateAssetFile(assetInfo2), CreateAssetFile(assetInfo3) } }; _fileSystem.GetDirectory(Arg.Any <string>()).Returns(root); var assetStore = GetAssetStore(); // Act assetStore.RegisterAssets(assetDiscoveryPath); // Assert Assert.That(assetStore.GetRegisteredAssets(), Has.Exactly(3).Items); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo1)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo2)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo3)); }
public SaveFileResult Save(string fileName) { SaveFileResult result; if (!IsValidFileName(fileName)) { return(new SaveFileResult(new InvalidOperationException(string.Format("Invalid filename: '{0}'", fileName ?? "NULL")))); } string destFileName = fileName + ".bkp"; bool flag = false; try { if (FileStub.Exists(fileName)) { FileStub.Copy(fileName, destFileName); } string directoryName = PathStub.GetDirectoryName(fileName); if (!string.IsNullOrEmpty(directoryName) && !DirectoryStub.Exists(directoryName)) { DirectoryStub.CreateDirectory(directoryName); } flag = true; using (Stream stream = FileStub.Open(fileName, FileMode.Create, FileAccess.Write)) { result = this.Save(stream); } if (!result.Success) { return(result); } } catch (Exception exception) { if (flag && FileStub.Exists(destFileName)) { FileStub.Copy(destFileName, fileName); } return(new SaveFileResult(exception)); } finally { if (FileStub.Exists(destFileName)) { FileStub.Delete(destFileName); } } this.LastFilePath = fileName; return(result); }
public void RegisterAssets_ShouldRegisterNoAssetInfos_WhenDirectoryHasNoFiles() { // Arrange const string assetDiscoveryPath = "Assets Root Directory"; var root = new DirectoryStub(); _fileSystem.GetDirectory(Arg.Any <string>()).Returns(root); var assetStore = GetAssetStore(); // Act assetStore.RegisterAssets(assetDiscoveryPath); // Assert Assert.That(assetStore.GetRegisteredAssets(), Is.Empty); }
public void Execute_NoProjectFileAndNoSolutionInWorkDirectory_ShouldLeaveProjectFileBlank() { var workDirectory = new DirectoryStub("Src") { new DirectoryStub("DotNet") { new DirectoryStub("Build"), }, new DirectoryStub("Artifacts"), new DirectoryStub("Scripts") }; var task = new MsBuildTask { ToolPath = "myMsBuild" }; task.AssertCommand( workDirectory["DotNet"]["Build"], (msBuildPath, msBuildArguments) => { Assert.That(msBuildArguments.Trim(), Is.Empty); }); }
public FileSystem() { Drive = new DriveStub(); Directory = new DirectoryStub(); File = new FileStub(); }
public void RegisterAssets_ShouldRegisterTenAssetInfos_WhenDirectoryHasFilesAndSubdirectoriesWithFilesAllHavingTenAssetFilesInTotal() { // Arrange const string assetDiscoveryPath = "Assets Root Directory"; var assetInfo1 = CreateNewAssetInfo(); var assetInfo2 = CreateNewAssetInfo(); var assetInfo3 = CreateNewAssetInfo(); var assetInfo4 = CreateNewAssetInfo(); var assetInfo5 = CreateNewAssetInfo(); var assetInfo6 = CreateNewAssetInfo(); var assetInfo7 = CreateNewAssetInfo(); var assetInfo8 = CreateNewAssetInfo(); var assetInfo9 = CreateNewAssetInfo(); var assetInfo10 = CreateNewAssetInfo(); var root = new DirectoryStub { Files = new[] { CreateAssetFile(assetInfo1), CreateAssetFile(assetInfo2) }, Directories = new[] { new DirectoryStub { Files = new[] { CreateAssetFile(assetInfo3), CreateAssetFile(assetInfo4) } }, new DirectoryStub { Files = new[] { CreateAssetFile(assetInfo5), CreateAssetFile(assetInfo6) }, Directories = new[] { new DirectoryStub { Files = new[] { CreateAssetFile(assetInfo7), CreateAssetFile(assetInfo8) } }, new DirectoryStub { Files = new[] { CreateAssetFile(assetInfo9), CreateAssetFile(assetInfo10) } } } } } }; _fileSystem.GetDirectory(Arg.Any <string>()).Returns(root); var assetStore = GetAssetStore(); // Act assetStore.RegisterAssets(assetDiscoveryPath); // Assert Assert.That(assetStore.GetRegisteredAssets(), Has.Exactly(10).Items); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo1)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo2)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo3)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo4)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo5)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo6)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo7)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo8)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo9)); Assert.That(assetStore.GetRegisteredAssets(), Contains.Item(assetInfo10)); }