public void ThrowsFileNotFoundExceptionWhenFileIsAlreadyDeleted()
            {
                var file = new PlatformFile(this.platformFile);

                FileSystemTest.DeletePlatformItem(this.platformFile);
                AssertEx.Throws <FileNotFoundException>(() => file.Open());
            }
            public void ThrowsFileNotFoundExceptionWhenFileIsDeleted()
            {
                var file = new PlatformFile(this.platformFile);

                FileSystemTest.DeletePlatformItem(this.platformFile);
                AssertEx.Throws <FileNotFoundException>(() => { var length = file.Length; });
            }
            public void DeletesFileFromFileSystem()
            {
                var file = new PlatformFile(this.platformFile);

                file.Delete();
                AssertEx.Throws <FileNotFoundException>(() => FileSystemTest.GetPlatformFile(FileSystemTest.GetPlatformFileName(this.platformFile)));
            }
예제 #4
0
        public PlatformFolderTest()
        {
            string uniqueName = GetUniqueFileName();

            this.storageFolder = FileSystemTest.CreatePlatformFolder(uniqueName);
            Trace.WriteLine("Storage folder is:" + this.storageFolder.FullName);
        }
            public void ThrowsIOExceptionWhenFileIsAlreadyOpen()
            {
                var file = new PlatformFile(this.platformFile);

                using (Stream previouslyOpenedStream = FileSystemTest.OpenPlatformFile(this.platformFile))
                {
                    AssertEx.Throws <IOException>(() => file.Open());
                }
            }
            public void ThrowsFileNotFoundExceptionWhenFileIsAlreadyDeleted()
            {
                var file = new PlatformFile(this.platformFile);

                FileSystemTest.DeletePlatformItem(this.platformFile);

                string newName = GetUniqueFileName();

                AssertEx.Throws <FileNotFoundException>(() => file.Rename(newName));
            }
            public void ThrowsIOExceptionWhenFileWithDesiredNameAlreadyExists()
            {
                var file = new PlatformFile(this.platformFile);

                string newName         = GetUniqueFileName();
                var    conflictingFile = FileSystemTest.CreatePlatformFile(newName);

                AssertEx.Throws <IOException>(() => file.Rename(newName));

                FileSystemTest.DeletePlatformItem(conflictingFile);
            }
            public void RenamesFileInFileSystem()
            {
                var    file    = new PlatformFile(this.platformFile);
                string oldName = GetPlatformFileName(this.platformFile);
                string newName = Guid.NewGuid().ToString("N");

                file.Rename(newName);

                AssertEx.Throws <FileNotFoundException>(() => FileSystemTest.GetPlatformFile(oldName));
                Assert.IsNotNull(FileSystemTest.GetPlatformFile(newName));
            }
            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);
            }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing == true)
     {
         try
         {
             FileSystemTest.DeletePlatformItem(this.platformFile);
         }
         catch (IOException)
         {
             // File already deleted
         }
     }
 }
        public PlatformFileTest()
        {
            string uniqueFileName = GetUniqueFileName();

            this.platformFile = FileSystemTest.CreatePlatformFile(uniqueFileName);
        }
예제 #12
0
 public void ThrowsUnauthorizedAccessExceptionWhenProcessDoesNotHaveRightToCreateFile()
 {
     Trace.WriteLine(string.Format("{0} Blocking Listing Permission on: {1} ", DateTime.Now.ToLongTimeString(), this.storageFolder.FullName));
     // Only on Windows as the APIs are not available in Linux.
     // The product also does not this this.
     using (new DirectoryAccessDenier(this.storageFolder, FileSystemRights.CreateFiles))
     {
         var folder = new PlatformFolder(this.storageFolder);
         AssertEx.Throws <UnauthorizedAccessException>(() => folder.CreateFile(FileSystemTest.GetUniqueFileName()));
     }
 }