public void FFSValidPath() { using var ffs = new FollowingFileStream(this.inputFilePath); Assert.IsNotNull( ffs, "stream must not be null on valid path"); }
public void FFSRead(bool async) { using var ffs = new FollowingFileStream(this.inputFilePath, 4 * 1096, async); var expected = "coucou"; Assert.AreEqual(0, ffs.Position); Assert.AreEqual(expected.Length, ffs.Length); var bytes = new byte[expected.Length]; Assert.AreEqual(expected.Length, ffs.Read(bytes, 0, bytes.Length)); Assert.AreEqual(expected, System.Text.Encoding.Default.GetString(bytes)); ffs.Seek(0, SeekOrigin.Begin); Assert.AreEqual(expected.Length, ffs.ReadAsync(bytes, 0, bytes.Length).Result); Assert.AreEqual(expected, System.Text.Encoding.Default.GetString(bytes)); ffs.Position = 0; Assert.AreEqual(expected.Length, ffs.EndRead(ffs.BeginRead(bytes, 0, bytes.Length, null !, null !))); Assert.AreEqual(expected, System.Text.Encoding.Default.GetString(bytes)); var cts = new CancellationTokenSource(); cts.Cancel(); Assert.ThrowsExceptionAsync <OperationCanceledException>(() => ffs.ReadAsync(bytes, 0, bytes.Length, cts.Token)); cts.Dispose(); }
public void FFSCaps() { using var ffs = new FollowingFileStream(this.inputFilePath); Assert.IsTrue(ffs.CanRead); Assert.IsFalse(ffs.CanWrite); Assert.IsTrue(ffs.CanSeek); Assert.IsTrue(ffs.CanTimeout); }
public void FFSCopyTo(bool async) { { using var ffs = new FollowingFileStream(this.inputFilePath, 4 * 1096, async); using var destination = File.CreateText(this.outputFilePath); ffs.ReadTimeout = 0; ffs.CopyTo(destination.BaseStream); } Assert.IsTrue(FileCompare(this.inputFilePath, this.outputFilePath)); }
public void FFSModification() { using var ffs = new FollowingFileStream(this.inputFilePath); Assert.ThrowsException <NotSupportedException>(() => ffs.Write(null !, 0, 0)); Assert.ThrowsException <NotSupportedException>(() => ffs.WriteAsync(null !, 0, 0)); Assert.ThrowsException <NotSupportedException>(() => ffs.WriteByte(0x0)); Assert.ThrowsException <NotSupportedException>(() => ffs.BeginWrite(null !, 0, 0, null !, null !)); Assert.ThrowsException <NotSupportedException>(() => ffs.SetLength(0)); Assert.ThrowsException <NotSupportedException>(() => ffs.Flush()); Assert.ThrowsException <NotSupportedException>(() => ffs.FlushAsync().GetAwaiter().GetResult()); }
public void FFSClose(bool async) { using var input = File.CreateText(this.inputFilePath); using var ffsa = new FollowingFileStream(this.inputFilePath, 4 * 1024, async); using var ffs = ffsa.Synchronized(); using var destination = File.CreateText(this.outputFilePath); destination.AutoFlush = true; var os = destination.BaseStream; var copy = ffs.CopyToAsync(os); Assert.AreEqual(0, os.Length); Thread.Sleep(200); Assert.IsFalse(copy.IsCompleted); input.WriteLine("coucou2"); ffs.Close(); Thread.Sleep(200); Assert.IsTrue(copy.IsCompletedSuccessfully); }
public void FFSFollowingRead(bool async) { { using var input = File.CreateText(this.inputFilePath); using var ffs = new FollowingFileStream(this.inputFilePath, 4 * 1024, async); using var destination = File.CreateText(this.outputFilePath); ffs.ReadTimeout = 400; destination.AutoFlush = true; var os = destination.BaseStream; var copy = ffs.CopyToAsync(os); Assert.AreEqual(0, os.Length); Thread.Sleep(ffs.ReadTimeout / 2); Assert.IsFalse(copy.IsCompleted); input.WriteLine("coucou2"); input.Close(); Assert.IsTrue(copy.Wait(3 * ffs.ReadTimeout)); } Assert.IsTrue(FileCompare(this.inputFilePath, this.outputFilePath)); }
private static async Task CopyToOutput() { using var source = new FollowingFileStream(InputPath); using var destination = new FileStream(OutputPath, FileMode.Create, FileAccess.Write, FileShare.Read); await source.CopyToAsync(destination).ConfigureAwait(false); }
public void FFSProperties(bool async) { using var ffs = new FollowingFileStream(this.inputFilePath, 4 * 1096, async); Assert.AreEqual(this.inputFilePath, ffs.Name); Assert.AreEqual(async, ffs.IsAsync); }