Beispiel #1
0
        public void ModifiesTheActualFileSize(FileOptions options)
        {
            using (SafeFileHandle handle = File.OpenHandle(GetTestFilePath(), FileMode.CreateNew, FileAccess.Write, options: options))
            {
                RandomAccess.SetLength(handle, FileSize);

                Assert.Equal(FileSize, RandomAccess.GetLength(handle));
            }
        }
Beispiel #2
0
        public void ZeroesTheFileContentsWhenExtendingTheFile(FileOptions options)
        {
            using (SafeFileHandle handle = File.OpenHandle(GetTestFilePath(), FileMode.CreateNew, FileAccess.Write, options: options))
            {
                RandomAccess.SetLength(handle, FileSize);

                byte[] buffer = new byte[FileSize + 1];
                Assert.Equal(FileSize, RandomAccess.Read(handle, buffer, 0));
                Assert.All(buffer, @byte => Assert.Equal(0, @byte));
            }
        }
Beispiel #3
0
        public void AllowsForShrinking(FileOptions options)
        {
            using (SafeFileHandle handle = File.OpenHandle(GetTestFilePath(), FileMode.CreateNew, FileAccess.Write, options: options))
            {
                RandomAccess.SetLength(handle, FileSize);
                Assert.Equal(FileSize, RandomAccess.GetLength(handle));

                RandomAccess.SetLength(handle, FileSize / 2);
                Assert.Equal(FileSize / 2, RandomAccess.GetLength(handle));

                RandomAccess.SetLength(handle, 0);
                Assert.Equal(0, RandomAccess.GetLength(handle));
            }
        }
Beispiel #4
0
        protected override long MethodUnderTest(SafeFileHandle handle, byte[] bytes, long fileOffset)
        {
            RandomAccess.SetLength(handle, fileOffset);

            return(0);
        }