コード例 #1
0
 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));
 }
コード例 #2
0
 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 ());
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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 ());
        }
コード例 #8
0
        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);
        }