public async Task CreateStreamTwice () { var provider = new StreamProvider (Engine, "testDir", Torrent); await provider.StartAsync (); using var stream = await provider.CreateStreamAsync (provider.Files[0], false, CancellationToken.None); Assert.ThrowsAsync<InvalidOperationException> (() => provider.CreateStreamAsync (provider.Files[0], false, CancellationToken.None)); }
public async Task ReadPastEndOfStream () { var provider = new StreamProvider (Engine, "testDir", Torrent); await provider.StartAsync (); using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: false, CancellationToken.None).WithTimeout (); stream.Seek (0, SeekOrigin.End); Assert.AreEqual (0, await stream.ReadAsync (new byte[1], 0, 1).WithTimeout ()); }
public async Task SeekPastEnd () { var provider = new StreamProvider (Engine, "testDir", Torrent); await provider.StartAsync (); using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: false, CancellationToken.None).WithTimeout (); stream.Seek (stream.Length + 100, SeekOrigin.Begin); Assert.AreEqual (stream.Length, stream.Position); }
public async Task CreateStream () { var provider = new StreamProvider (Engine, "testDir", Torrent); await provider.StartAsync (); using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: false, CancellationToken.None); Assert.IsNotNull (stream); Assert.AreEqual (0, stream.Position); Assert.AreEqual (provider.Files[0].Length, stream.Length); }
public async Task CreateStream() { var provider = new StreamProvider(Engine, "testDir", Torrent); await provider.StartAsync(); using var stream = await provider.CreateStreamAsync(provider.Files[0], false, CancellationToken.None); Assert.IsNotNull(stream); }
public async Task CreateStream_Prebuffer () { var provider = new StreamProvider (Engine, "testDir", Torrent); await provider.StartAsync (); await provider.Manager.WaitForState (TorrentState.Downloading); provider.Manager.Bitfield.SetAll (true); // should not be allowed by public API. using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: true, CancellationToken.None); Assert.IsNotNull (stream); Assert.AreEqual (0, stream.Position); Assert.AreEqual (provider.Files[0].Length, stream.Length); }
public async Task ReadLastByte () { var provider = new StreamProvider (Engine, "testDir", Torrent); await provider.StartAsync (); await provider.Manager.WaitForState (TorrentState.Downloading).WithTimeout (); provider.Manager.Bitfield.SetAll (true); // the public API shouldn't allow this. using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: false, CancellationToken.None).WithTimeout (); stream.Seek (1, SeekOrigin.End); Assert.AreEqual (1, await stream.ReadAsync (new byte[1], 0, 1).WithTimeout ()); stream.Seek (1, SeekOrigin.End); Assert.AreEqual (1, await stream.ReadAsync (new byte[5], 0, 5).WithTimeout ()); }
public async Task SeekToMiddle() { var provider = new StreamProvider(Engine, "testDir", Torrent); await provider.StartAsync(); await provider.Manager.WaitForState(TorrentState.Downloading); provider.Manager.Bitfield.SetAll(true); // should not be allowed by public API. using var stream = await provider.CreateStreamAsync(provider.Files[0], prebuffer : false, CancellationToken.None); stream.Seek(12345, SeekOrigin.Begin); Assert.AreEqual(provider.Manager.ByteOffsetToPieceIndex(12345), provider.Requester.HighPriorityPieceIndex); }