public void TryDeleteFileDeletesFile() { string path = "mock:\\file.txt"; DeleteTestsFileSystem fileSystem = new DeleteTestsFileSystem(new[] { new KeyValuePair <string, FileAttributes>(path, FileAttributes.ReadOnly) }); fileSystem.TryDeleteFile(path); fileSystem.ExistingFiles.ContainsKey(path).ShouldBeFalse("DeleteUtils failed to delete file"); }
public void TryDeleteFileReturnsThrownException() { string path = "mock:\\file.txt"; Exception deleteException = new IOException(); DeleteTestsFileSystem fileSystem = new DeleteTestsFileSystem(new[] { new KeyValuePair <string, FileAttributes>(path, FileAttributes.ReadOnly) }); fileSystem.DeleteException = deleteException; Exception e; fileSystem.TryDeleteFile(path, out e).ShouldBeFalse("TryDeleteFile should fail on IOException"); ReferenceEquals(e, deleteException).ShouldBeTrue("TryDeleteFile should return the thrown exception"); deleteException = new UnauthorizedAccessException(); fileSystem.DeleteException = deleteException; fileSystem.TryDeleteFile(path, out e).ShouldBeFalse("TryDeleteFile should fail on UnauthorizedAccessException"); ReferenceEquals(e, deleteException).ShouldBeTrue("TryDeleteFile should return the thrown exception"); }
public void TryDeleteFileDoesNotUpdateMetadataOnSuccess() { string path = "mock:\\file.txt"; DeleteTestsFileSystem fileSystem = new DeleteTestsFileSystem(new[] { new KeyValuePair <string, FileAttributes>(path, FileAttributes.ReadOnly) }); EventMetadata metadata = new EventMetadata(); fileSystem.TryDeleteFile(path, "metadataKey", metadata).ShouldBeTrue("TryDeleteFile should succeed"); metadata.ShouldBeEmpty("TryDeleteFile should not update metadata on success"); }
public void TryDeleteFileReturnsTrueWhenSetAttributesFailsToFindFile() { string path = "mock:\\file.txt"; DeleteTestsFileSystem fileSystem = new DeleteTestsFileSystem( Enumerable.Empty <KeyValuePair <string, FileAttributes> >(), allFilesExist: true, noOpDelete: false); fileSystem.TryDeleteFile(path).ShouldEqual(true, "TryDeleteFile should return true when SetAttributes throws FileNotFoundException"); }
public void TryDeleteFileReturnsNullExceptionOnSuccess() { string path = "mock:\\file.txt"; DeleteTestsFileSystem fileSystem = new DeleteTestsFileSystem(new[] { new KeyValuePair <string, FileAttributes>(path, FileAttributes.ReadOnly) }); Exception e = new Exception(); fileSystem.TryDeleteFile(path, out e); fileSystem.ExistingFiles.ContainsKey(path).ShouldBeFalse("DeleteUtils failed to delete file"); e.ShouldBeNull("Exception should be null when TryDeleteFile succeeds"); }
public void TryDeleteFileSetsAttributesToNormalBeforeDeletingFile() { string path = "mock:\\file.txt"; DeleteTestsFileSystem fileSystem = new DeleteTestsFileSystem( new[] { new KeyValuePair <string, FileAttributes>(path, FileAttributes.ReadOnly) }, allFilesExist: false, noOpDelete: true); fileSystem.TryDeleteFile(path); fileSystem.ExistingFiles.ContainsKey(path).ShouldBeTrue("DeleteTestsFileSystem is configured as no-op delete, file should still be present"); fileSystem.ExistingFiles[path].ShouldEqual(FileAttributes.Normal, "TryDeleteFile should set attributes to Normal before deleting"); }
public void TryDeleteFileUpdatesMetadataOnFailure() { string path = "mock:\\file.txt"; DeleteTestsFileSystem fileSystem = new DeleteTestsFileSystem(new[] { new KeyValuePair <string, FileAttributes>(path, FileAttributes.ReadOnly) }); fileSystem.DeleteException = new IOException(); EventMetadata metadata = new EventMetadata(); fileSystem.TryDeleteFile(path, "testKey", metadata).ShouldBeFalse("TryDeleteFile should fail when IOException is thrown"); metadata.ContainsKey("testKey_DeleteFailed").ShouldBeTrue(); metadata["testKey_DeleteFailed"].ShouldEqual("true"); metadata.ContainsKey("testKey_DeleteException").ShouldBeTrue(); metadata["testKey_DeleteException"].ShouldBeOfType <string>().ShouldContain("IOException"); }