System.IO.Tests.FileStream_ctor_sfh_fa.InconsistentFileAccessThrows C# (CSharp) Méthode

InconsistentFileAccessThrows() private méthode

private InconsistentFileAccessThrows ( ) : void
Résultat void
        public void InconsistentFileAccessThrows()
        {
            string fileName = GetTestFilePath();

            using (FileStream fs = new FileStream(fileName, FileMode.Create))
            {
                fs.WriteByte(0);
            }

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                FileStream fsw = CreateFileStream(fs.SafeFileHandle, FileAccess.Write);
                Assert.False(fsw.CanRead);
                Assert.Throws<NotSupportedException>(() => fsw.ReadByte());
                Assert.True(fsw.CanWrite);
                // doesn't throw due to buffering.
                fsw.WriteByte(0);
                Assert.True(fsw.CanSeek);
                // throws due to FS trying to flush write buffer
                Assert.Throws<UnauthorizedAccessException>(() => fsw.Dispose());
            }

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Write))
            {
                using (FileStream fsr = CreateFileStream(fs.SafeFileHandle, FileAccess.Read))
                {
                    Assert.True(fsr.CanRead);
                    Assert.Throws<UnauthorizedAccessException>(() => fsr.ReadByte());
                    Assert.False(fsr.CanWrite);
                    Assert.Throws<NotSupportedException>(() => fsr.WriteByte(0));
                    Assert.True(fsr.CanSeek);
                }
            }
        }
    }