public void CreateNewDirectoryWithRenameAttemptsDateTest() { MockFileSystem mockFileSystem = new MockFileSystem(); FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10); Assert.AreEqual(1, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012")); FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10); Assert.AreEqual(2, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012 (2)")); }
public void CreateNewDirectoryWithRenameAttemptsDateTest() { MockFileSystem mockFileSystem = new MockFileSystem(); FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10); Assert.AreEqual(1, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012")); FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10); Assert.AreEqual(2, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012 (2)")); }
public void TryUnregisterRepo_FailsIfRegistryDirectoryMissing() { MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(Path.GetDirectoryName(this.registryFolderPath), null, null)); ScalarRepoRegistry registry = new ScalarRepoRegistry( new MockTracer(), fileSystem, this.registryFolderPath); fileSystem.DirectoryExists(this.registryFolderPath).ShouldBeFalse(); registry.TryUnregisterRepo(Path.Combine(MockFileSystem.GetMockRoot(), "Repos", "Repo1"), out string errorMessage).ShouldBeFalse(); errorMessage.ShouldNotBeNullOrEmpty(); fileSystem.DirectoryExists(this.registryFolderPath).ShouldBeFalse(); }
public void CreateNewDirectoryWithRenameAttemptsTest() { MockFileSystem mockFileSystem = new MockFileSystem(); FileCreator.CreateNewDirectoryWithRenameAttempts("x:\\abc\\def\\", mockFileSystem, 10); Assert.AreEqual(1, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("x:\\abc\\def\\")); FileCreator.CreateNewDirectoryWithRenameAttempts("x:\\abc\\def\\", mockFileSystem, 10); Assert.AreEqual(2, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("x:\\abc\\def (2)")); FileCreator.CreateNewDirectoryWithRenameAttempts("x:\\abc\\def\\", mockFileSystem, 10); Assert.AreEqual(3, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("x:\\abc\\def (3)")); }
public void CreateNewDirectoryWithRenameAttemptsTest() { MockFileSystem mockFileSystem = new MockFileSystem(); FileCreator.CreateNewDirectoryWithRenameAttempts("x:\\abc\\def\\", mockFileSystem, 10); Assert.AreEqual(1, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("x:\\abc\\def\\")); FileCreator.CreateNewDirectoryWithRenameAttempts("x:\\abc\\def\\", mockFileSystem, 10); Assert.AreEqual(2, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("x:\\abc\\def (2)")); FileCreator.CreateNewDirectoryWithRenameAttempts("x:\\abc\\def\\", mockFileSystem, 10); Assert.AreEqual(3, mockFileSystem.DirectoryCount); Assert.IsTrue(mockFileSystem.DirectoryExists("x:\\abc\\def (3)")); }
public void DeleteFileAndEmptyParentDirectoriesCorrectly() { // Arrange var fileSystem = new MockFileSystem("x:\\"); fileSystem.AddFile("foo\\bar\\hell\\x.txt"); // Act fileSystem.DeleteFileAndParentDirectoriesIfEmpty("foo\\bar\\hell\\x.txt"); // Assert Assert.False(fileSystem.FileExists("foo\\bar\\hell\\x.txt")); Assert.False(fileSystem.DirectoryExists("foo")); Assert.False(fileSystem.DirectoryExists("foo\\bar")); Assert.False(fileSystem.DirectoryExists("foo\\bar\\hell")); }
public void CreatesDirectory() { var configFile = new ConfigFile(Dir); var fs = new MockFileSystem(); var revisionManager = new RevisionManager(configFile, fs); Assert.IsTrue(fs.DirectoryExists(Dir)); }
public void TryRegisterRepo_CreatesMissingRegistryDirectory() { MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(Path.GetDirectoryName(this.registryFolderPath), null, null)); ScalarRepoRegistry registry = new ScalarRepoRegistry( new MockTracer(), fileSystem, this.registryFolderPath); List <ScalarRepoRegistration> registrations = new List <ScalarRepoRegistration> { new ScalarRepoRegistration(Path.Combine(MockFileSystem.GetMockRoot(), "Repos", "Repo1"), "testUser") }; fileSystem.DirectoryExists(this.registryFolderPath).ShouldBeFalse(); this.RegisterRepos(registry, registrations); fileSystem.DirectoryExists(this.registryFolderPath).ShouldBeTrue("Registering a repo should have created the missing registry directory"); this.RegistryShouldContainRegistrations(registry, registrations); }
public async Task CopiesDirectoryCorrectlyWithSubDirs() { var fs = new MockFileSystem(); var directoryCopier = new DirectoryCopier(fs, "C:\\fakeDir", "C:\\SFM", true); fs.CreateDirectory("C:\\fakeDir"); fs.CreateFile("C:\\fakeDir\\file1.txt"); fs.CreateFile("C:\\fakeDir\\file2.txt"); fs.CreateDirectory("C:\\fakeDir\\folder"); fs.CreateFile("C:\\fakeDir\\folder\\file3.txt"); fs.CreateDirectory("C:\\fakeDir\\folder\\folder2"); fs.CreateFile("C:\\fakeDir\\folder\\folder2\\file4.txt"); await directoryCopier.Execute(); Assert.IsTrue(fs.FileExists("C:\\SFM\\file1.txt")); Assert.IsTrue(fs.FileExists("C:\\SFM\\file2.txt")); Assert.IsTrue(fs.DirectoryExists("C:\\SFM\\folder")); Assert.IsTrue(fs.FileExists("C:\\SFM\\folder\\file3.txt")); Assert.IsTrue(fs.DirectoryExists("C:\\SFM\\folder\\folder2")); Assert.IsTrue(fs.FileExists("C:\\SFM\\folder\\folder2\\file4.txt")); }
public void MarkPackageDirectoryForDeletionDoesNotAddDeletemeFileWhenDirectoryRemovalSuccessful() { // Arrange IPackage package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0.0"); var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); string packageDirectoryPath = pathResolver.GetPackageDirectory(package); var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem, () => pathResolver); // Act deleteOnRestartManager.MarkPackageDirectoryForDeletion(package); // Assert Assert.False(fileSystem.DirectoryExists(packageDirectoryPath)); Assert.False(fileSystem.FileExists(packageDirectoryPath + _deletionMarkerSuffix)); }
public void CallRemovePackageWillRemoveTheWholePackageDirectory() { // Arrange var fileSystem = new MockFileSystem("x:\\root"); fileSystem.AddFile("A.2.0\\A.2.0.nupkg"); fileSystem.AddFile("A.2.0\\A.2.0.nuspec"); fileSystem.AddFile("A.2.0\\random"); fileSystem.AddFile("A.2.0\\content\\file.txt"); fileSystem.AddFile("A.2.0\\readme.txt"); var configFileSystem = new MockFileSystem(); var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem); // Act repository.RemovePackage(PackageUtility.CreatePackage("A", "2.0")); // Assert Assert.False(fileSystem.FileExists("A.2.0\\A.2.0.nupkg")); Assert.False(fileSystem.FileExists("A.2.0\\A.2.0.nuspec")); Assert.False(fileSystem.DirectoryExists("A.2.0")); }
protected override void Arrange() { base.Arrange(); MockOptions.FilePaths = new[] { BasePath }; MockOptions.Engine = EngineType.SqlServer; MockOptions.DatabaseType = DatabaseType.ODS; A.CallTo(() => MockFileSystem.DirectoryExists(StructureScripts)) .Returns(true); A.CallTo(() => MockFileSystem.DirectoryExists(DataScripts)) .Returns(true); // These next two are set to make sure they _don't_ turn up in the results. A.CallTo(() => MockFileSystem.DirectoryExists(FeatureScripts)) .Returns(true); A.CallTo(() => MockFileSystem.DirectoryExists(AdminStructureScripts)) .Returns(true); }
protected override void Arrange() { base.Arrange(); MockOptions.FilePaths = new[] { BasePath }; MockOptions.Engine = EngineType.SqlServer; MockOptions.DatabaseType = DatabaseType.ODS; A.CallTo(() => MockFileSystem.DirectoryExists(StructureScripts)) .Returns(false); A.CallTo(() => MockFileSystem.DirectoryExists(DataScripts)) .Returns(false); // Still true - make sure this doesn't show up A.CallTo(() => MockFileSystem.DirectoryExists(FeatureScripts)) .Returns(true); A.CallTo(() => MockFileSystem.DirectoryExists(AdminStructureScripts)) .Returns(true); }
public void MarkPackageDirectoryForDeletionDoesNotAddDeletemeFileWhenFileAdded() { // Arrange IPackage package = NuGet.Test.PackageUtility.CreatePackage(id: "foo", version: "1.0.0"); var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); string packageDirectoryPath = pathResolver.GetPackageDirectory(package); string addedFilePath = Path.Combine("tools", "addedFile.txt"); fileSystem.AddFile(Path.Combine(packageDirectoryPath, pathResolver.GetPackageFileName(package)), Stream.Null); fileSystem.AddFile(Path.Combine(packageDirectoryPath, addedFilePath), "Added Content".AsStream()); var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem, () => pathResolver); // Act deleteOnRestartManager.MarkPackageDirectoryForDeletion(package, _ => package); // Assert Assert.True(fileSystem.DirectoryExists(packageDirectoryPath)); Assert.True(fileSystem.FileExists(Path.Combine(packageDirectoryPath, addedFilePath))); Assert.False(fileSystem.FileExists(packageDirectoryPath + _deletionMarkerSuffix)); }
public void MarkPackageDirectoryForDeletionAddsDeletemeFileWhenDirectoryRemovalUnsuccessful() { // Arrange IPackage package = NuGet.Test.PackageUtility.CreatePackage(id: "foo", version: "1.0.0", content: new string[] { }, assemblyReferences: new string[] { }, tools: new[] { "lockedFile.txt" }); var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); string packageDirectoryPath = pathResolver.GetPackageDirectory(package); string lockedFilePath = Path.Combine("tools", "lockedFile.txt"); fileSystem.AddFile(Path.Combine(packageDirectoryPath, pathResolver.GetPackageFileName(package)), Stream.Null); fileSystem.AddFile(Path.Combine(packageDirectoryPath, packageDirectoryPath + Constants.ManifestExtension), Stream.Null); fileSystem.AddFile(Path.Combine(packageDirectoryPath, lockedFilePath), lockedFilePath.AsStream()); var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem, () => pathResolver); // Act deleteOnRestartManager.MarkPackageDirectoryForDeletion(package); // Assert Assert.True(fileSystem.DirectoryExists(packageDirectoryPath)); Assert.True(fileSystem.FileExists(packageDirectoryPath + _deletionMarkerSuffix)); }
void ThenAllTheOldDirectoryWillBeDeleted() { _fileSystem.DirectoryExists(OldDir).ShouldBe(false); }
void AndGivenNoOldDirectoryExists() { _fileSystem.DirectoryExists(OldDir).ShouldBe(false); }
public void UnknownDirectoryDoesNotExist() { Assert.IsFalse(fileSystem.DirectoryExists(DirectoryName.Create(@"c:\unknown-dir"))); }