mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-22 19:10:41 -10:00
Adds negative tests for Begin/End, removes unnecessary block for `\\.\` paths. (The block for `\\.\` paths fulfills a need that predates our supported Windows OSes. You cannot inadvertently mess up "raw" drives. In addition we currently allow `\\?\` which is another form of device path access.) Commit migrated from https://github.com/dotnet/corefx/commit/5376c25bea9523265696ed5806f3dc8b51bbbf25
80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.IO;
|
|
using Xunit;
|
|
|
|
namespace System.IO.Tests
|
|
{
|
|
public class FileStream_BeginWrite : FileSystemTest
|
|
{
|
|
[Fact]
|
|
public void BeginWriteThrowsForNullArray()
|
|
{
|
|
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write))
|
|
{
|
|
Assert.Throws<ArgumentNullException>("array", () => fs.BeginWrite(null, 0, 0, null, null));
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void BeginWriteThrowsForNegativeOffset()
|
|
{
|
|
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write))
|
|
{
|
|
Assert.Throws<ArgumentOutOfRangeException>("offset", () => fs.BeginWrite(new byte[0], -1, 0, null, null));
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void BeginWriteThrowsForNegativeNumBytes()
|
|
{
|
|
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write))
|
|
{
|
|
Assert.Throws<ArgumentOutOfRangeException>("numBytes", () => fs.BeginWrite(new byte[0], 0, -1, null, null));
|
|
}
|
|
}
|
|
|
|
[Theory
|
|
InlineData(0, 0, 1)
|
|
InlineData(0, 1, 0)
|
|
InlineData(1, 0, 2)
|
|
InlineData(1, 1, 1)
|
|
]
|
|
public void BeginWriteThrowsForBadOffset(int arraySize, int offset, int numBytes)
|
|
{
|
|
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write))
|
|
{
|
|
Assert.Throws<ArgumentException>(() => fs.BeginWrite(new byte[arraySize], offset, numBytes, null, null));
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void BeginWriteThrowsForClosed()
|
|
{
|
|
FileStream fs;
|
|
using (fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write))
|
|
{
|
|
}
|
|
|
|
Assert.Throws<ObjectDisposedException>(() => fs.BeginWrite(new byte[0], 0, 0, null, null));
|
|
}
|
|
|
|
[Fact]
|
|
public void BeginWriteThrowsForReadOnly()
|
|
{
|
|
string testPath = GetTestFilePath();
|
|
using (FileStream fs = new FileStream(testPath, FileMode.Create, FileAccess.Write))
|
|
{
|
|
}
|
|
|
|
using (FileStream fs = new FileStream(testPath, FileMode.Open, FileAccess.Read))
|
|
{
|
|
Assert.Throws<NotSupportedException>(() => fs.BeginWrite(new byte[0], 0, 0, null, null));
|
|
}
|
|
}
|
|
}
|
|
}
|