コード例 #1
0
        public void FromStorageFolder_SurfaceIOException()
        {
            StorageFolder folder   = ApplicationData.Current.TemporaryFolder;
            string        filename = "FromStorageFolder_SurfaceIOException_" + Path.GetRandomFileName();

            using (SafeFileHandle handle = folder.CreateSafeFileHandle(filename, FileMode.CreateNew))
            {
                Assert.NotNull(handle);
                Assert.False(handle.IsInvalid);
            }
            Assert.Contains(
                filename,
                Assert.Throws <IOException>(() => folder.CreateSafeFileHandle(filename, FileMode.CreateNew)).Message);
            File.Delete(Path.Combine(folder.Path, filename));
        }
コード例 #2
0
        public void FromStorageFolder_SurfaceNotFoundException()
        {
            StorageFolder folder   = ApplicationData.Current.TemporaryFolder;
            string        filename = "FromStorageFolder_SurfaceNotFoundException_" + Path.GetRandomFileName();

            Assert.Contains(
                filename,
                Assert.Throws <FileNotFoundException>(() => folder.CreateSafeFileHandle(filename, FileMode.Open)).Message);
        }
コード例 #3
0
        public void FromStorageFolder_Basic()
        {
            StorageFolder folder   = ApplicationData.Current.TemporaryFolder;
            string        filename = "FromStorageFolder_Basic_" + Path.GetRandomFileName();

            using (SafeFileHandle handle = folder.CreateSafeFileHandle(filename, FileMode.CreateNew))
            {
                Assert.NotNull(handle);
                Assert.False(handle.IsInvalid);
            }
            File.Delete(Path.Combine(folder.Path, filename));
        }
コード例 #4
0
        public void FromStorageFolder_FileStream()
        {
            StorageFolder  folder   = ApplicationData.Current.TemporaryFolder;
            string         filename = "FromStorageFolder_FileStream_" + Path.GetRandomFileName();
            SafeFileHandle handle   = folder.CreateSafeFileHandle(filename, FileMode.CreateNew, FileAccess.ReadWrite);

            Assert.NotNull(handle);
            Assert.False(handle.IsInvalid);
            using (FileStream fs = new FileStream(handle, FileAccess.ReadWrite))
            {
                byte[] data = { 0xDE, 0xAD, 0xBE, 0xEF };
                fs.Write(data, 0, data.Length);
                fs.Flush();
                fs.Position = 0;
                byte[] input = new byte[4];
                Assert.Equal(4, fs.Read(input, 0, 4));
                Assert.Equal(data, input);
            }

            File.Delete(Path.Combine(folder.Path, filename));
        }