public void CancelledTokenFastPath() { var cts = new CancellationTokenSource(); cts.Cancel(); CancellationToken cancelledToken = cts.Token; using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create)) { FSAssert.IsCancelled(ReadAsync(fs, new byte[1], 0, 1, cancelledToken), cancelledToken); } using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write)) { // before write only check FSAssert.IsCancelled(ReadAsync(fs, new byte[1], 0, 1, cancelledToken), cancelledToken); fs.Dispose(); // before disposed check FSAssert.IsCancelled(ReadAsync(fs, new byte[1], 0, 1, cancelledToken), cancelledToken); // out of bounds checking happens first Assert.Throws <ArgumentOutOfRangeException>(() => FSAssert.CompletesSynchronously(ReadAsync(fs, new byte[2], 1, 2, cancelledToken))); } }
public void CancelledTokenFastPath() { CancellationTokenSource cts = new CancellationTokenSource(); cts.Cancel(); CancellationToken cancelledToken = cts.Token; string fileName = GetTestFilePath(); using (FileStream fs = new FileStream(fileName, FileMode.Create)) { FSAssert.IsCancelled(fs.WriteAsync(new byte[1], 0, 1, cancelledToken), cancelledToken); } using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { // before read only check FSAssert.IsCancelled(fs.WriteAsync(new byte[1], 0, 1, cancelledToken), cancelledToken); fs.Dispose(); // before disposed check FSAssert.IsCancelled(fs.WriteAsync(new byte[1], 0, 1, cancelledToken), cancelledToken); // out of bounds checking happens first Assert.Throws <ArgumentException>(null, () => FSAssert.CompletesSynchronously(fs.WriteAsync(new byte[2], 1, 2, cancelledToken))); // count is checked prior Assert.Throws <ArgumentOutOfRangeException>("count", () => FSAssert.CompletesSynchronously(fs.WriteAsync(new byte[1], 0, -1, cancelledToken))); // offset is checked prior Assert.Throws <ArgumentOutOfRangeException>("offset", () => FSAssert.CompletesSynchronously(fs.WriteAsync(new byte[1], -1, -1, cancelledToken))); // buffer is checked first Assert.Throws <ArgumentNullException>("buffer", () => FSAssert.CompletesSynchronously(fs.WriteAsync(null, -1, -1, cancelledToken))); } }
public void CancelledTokenFastPath() { var cts = new CancellationTokenSource(); cts.Cancel(); CancellationToken cancelledToken = cts.Token; using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create)) { FSAssert.IsCancelled(ReadAsync(fs, new byte[1], 0, 1, cancelledToken), cancelledToken); } using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write)) { // before write only check FSAssert.IsCancelled(ReadAsync(fs, new byte[1], 0, 1, cancelledToken), cancelledToken); fs.Dispose(); // before disposed check FSAssert.IsCancelled(ReadAsync(fs, new byte[1], 0, 1, cancelledToken), cancelledToken); // out of bounds checking happens first Assert.Throws <ArgumentException>(null, () => FSAssert.CompletesSynchronously(ReadAsync(fs, new byte[2], 1, 2, cancelledToken))); // count is checked prior AssertExtensions.Throws <ArgumentOutOfRangeException>(CountParamName, () => FSAssert.CompletesSynchronously(ReadAsync(fs, new byte[1], 0, -1, cancelledToken))); // offset is checked prior AssertExtensions.Throws <ArgumentOutOfRangeException>(OffsetParamName, () => FSAssert.CompletesSynchronously(ReadAsync(fs, new byte[1], -1, -1, cancelledToken))); // buffer is checked first AssertExtensions.Throws <ArgumentNullException>(BufferParamName, () => FSAssert.CompletesSynchronously(ReadAsync(fs, null, -1, -1, cancelledToken))); } }