コード例 #1
0
            public void ThrowsFileNotFoundExceptionWhenFileIsAlreadyDeleted()
            {
                var file = new PlatformFile(this.platformFile);

                FileSystemTest.DeletePlatformItem(this.platformFile);
                AssertEx.Throws <FileNotFoundException>(() => file.Open());
            }
コード例 #2
0
 public void ThrowsUnauthorizedAccessExceptionWhenProcessHasNoRightToWriteToFile()
 {
     using (new FileAccessDenier(this.platformFile, FileSystemRights.Write))
     {
         var file = new PlatformFile(this.platformFile);
         AssertEx.Throws <UnauthorizedAccessException>(() => file.Open());
     }
 }
コード例 #3
0
 public void ThrowsUnauthorizedAccessExceptionWhenProcessHasNoRightToWriteToFile()
 {
     // Only on Windows as the APIs are not available in Linux.
     using (new FileAccessDenier(this.platformFile, FileSystemRights.Write))
     {
         var file = new PlatformFile(this.platformFile);
         AssertEx.Throws <UnauthorizedAccessException>(() => file.Open());
     }
 }
コード例 #4
0
            public void ThrowsIOExceptionWhenFileIsAlreadyOpen()
            {
                var file = new PlatformFile(this.platformFile);

                using (Stream previouslyOpenedStream = FileSystemTest.OpenPlatformFile(this.platformFile))
                {
                    AssertEx.Throws <IOException>(() => file.Open());
                }
            }
コード例 #5
0
            public void ReturnsStreamThatCanBeUsedToModifyFileContents()
            {
                var file = new PlatformFile(this.platformFile);

                var writtenBytes = new byte[] { 4, 2 };

                PlatformFileTest.WriteBytesAndDispose(file.Open(), writtenBytes);

                byte[] readBytes = ReadBytesAndDispose(FileSystemTest.OpenPlatformFile(this.platformFile));
                AssertEx.AreEqual(writtenBytes, readBytes);
            }
コード例 #6
0
 public void ThrowsUnauthorizedAccessExceptionWhenProcessHasNoRightToWriteToFile()
 {
     using (new FileAccessDenier(this.platformFile, FileSystemRights.Write))
     { 
         var file = new PlatformFile(this.platformFile);
         Assert.Throws<UnauthorizedAccessException>(() => file.Open());
     }
 }
コード例 #7
0
 public void ThrowsIOExceptionWhenFileIsAlreadyOpen()
 {
     var file = new PlatformFile(this.platformFile);
     using (Stream previouslyOpenedStream = FileSystemTest.OpenPlatformFile(this.platformFile))
     {
         Assert.Throws<IOException>(() => file.Open());
     }
 }
コード例 #8
0
 public void ThrowsFileNotFoundExceptionWhenFileIsAlreadyDeleted()
 {
     var file = new PlatformFile(this.platformFile);
     FileSystemTest.DeletePlatformItem(this.platformFile);
     Assert.Throws<FileNotFoundException>(() => file.Open());
 }
コード例 #9
0
            public void ReturnsStreamThatCanBeUsedToModifyFileContents()
            {
                var file = new PlatformFile(this.platformFile);

                var writtenBytes = new byte[] { 4, 2 };
                PlatformFileTest.WriteBytesAndDispose(file.Open(), writtenBytes);

                byte[] readBytes = ReadBytesAndDispose(FileSystemTest.OpenPlatformFile(this.platformFile));
                Assert.Equal(writtenBytes, readBytes);
            }