コード例 #1
0
        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");
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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");
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        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");
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        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");
        }