public void VirtualCanReadWrite_ShouldNotBeCalledDuringCtor()
 {
     using (var fs = File.Create(GetTestFilePath()))
     using (var dfs = new DerivedFileStream(fs.SafeFileHandle, FileAccess.ReadWrite))
     {
         Assert.False(dfs.CanReadCalled);
         Assert.False(dfs.CanWriteCalled);
         Assert.False(dfs.CanSeekCalled);
     }
 }
示例#2
0
        public void CallSpanReadWriteOnDerivedFileStream_ArrayMethodsUsed()
        {
            using (var fs = new DerivedFileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.None, bufferSize: 0x1000, FileOptions.None))
            {
                Assert.False(fs.WriteArrayInvoked);
                Assert.False(fs.ReadArrayInvoked);

                fs.Write(new ReadOnlySpan <byte>(new byte[1]));
                Assert.True(fs.WriteArrayInvoked);
                Assert.False(fs.ReadArrayInvoked);

                fs.Position = 0;
                fs.Read(new Span <byte>(new byte[1]));
                Assert.True(fs.WriteArrayInvoked);
                Assert.True(fs.ReadArrayInvoked);
            }
        }
示例#3
0
        public async Task CallMemoryReadWriteAsyncOnDerivedFileStream_ArrayMethodsUsed()
        {
            using (var fs = new DerivedFileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.None, bufferSize: 0x1000, FileOptions.None))
            {
                Assert.False(fs.WriteAsyncArrayInvoked);
                Assert.False(fs.ReadAsyncArrayInvoked);

                await fs.WriteAsync(new ReadOnlyMemory <byte>(new byte[1]));

                Assert.True(fs.WriteAsyncArrayInvoked);
                Assert.False(fs.ReadAsyncArrayInvoked);

                fs.Position = 0;
                await fs.ReadAsync(new Memory <byte>(new byte[1]));

                Assert.True(fs.WriteAsyncArrayInvoked);
                Assert.True(fs.ReadAsyncArrayInvoked);
            }
        }