Example #1
0
        public async Task FastResume_SomeExist()
        {
            PieceWriter.FilesThatExist.AddRange(new[] {
                Manager.Torrent.Files [0],
                Manager.Torrent.Files [2],
            });
            var bf = Manager.Bitfield.Clone().SetAll(true);

            Manager.LoadFastResume(new FastResume(Manager.InfoHash, bf));

            Assert.IsTrue(Manager.Bitfield.AllTrue, "#1");
            foreach (TorrentFile file in Manager.Torrent.Files)
            {
                Assert.IsTrue(file.BitField.AllTrue, "#2." + file.Path);
            }

            var mode = new StartingMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.Mode = mode;
            await mode.WaitForStartingToComplete();

            Assert.IsTrue(Manager.Bitfield.AllFalse, "#3");
            foreach (TorrentFile file in Manager.Torrent.Files)
            {
                Assert.IsTrue(file.BitField.AllFalse, "#4." + file.Path);
            }
        }
Example #2
0
        public void StartTwiceTest()
        {
            var mode = new StartingMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.Mode = mode;
            Assert.ThrowsAsync <TorrentException> (() => Manager.StartAsync(), "#1");
        }
 public async Task Announce_NoTrackers ()
 {
     Assert.AreEqual (0, Manager.TrackerManager.Tiers.Count, "#1");
     var mode = new StartingMode (Manager, DiskManager, ConnectionManager, Settings);
     Manager.Mode = mode;
     await mode.WaitForStartingToComplete ();
     Assert.IsInstanceOf<DownloadMode> (Manager.Mode, "#2");
 }
        public async Task Announce_NoTrackers()
        {
            Assert.IsNull(Manager.TrackerManager.CurrentTracker, "#1");
            var mode = new StartingMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.Mode = mode;
            await mode.StartingTask;

            Assert.IsInstanceOf <DownloadMode> (Manager.Mode, "#2");
        }
Example #5
0
        public async Task Announce()
        {
            TrackerManager.AddTracker("http://1.1.1.1");

            var mode = new StartingMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.Mode = mode;
            await mode.WaitForStartingToComplete();

            Assert.AreEqual(1, TrackerManager.Announces.Count, "#1");
            Assert.AreEqual(TrackerManager.CurrentTracker, TrackerManager.Announces[0].Item1, "#2");
            Assert.AreEqual(TorrentEvent.Started, TrackerManager.Announces[0].Item2, "#3");
        }
        public async Task StateChanges_AlreadyHashed ()
        {
            var modeChanged = new List<Mode> ();
            Manager.ModeChanged += (oldMode, newMode) => modeChanged.Add (newMode);

            var mode = new StartingMode (Manager, DiskManager, ConnectionManager, Settings);
            Manager.LoadFastResume (new FastResume (Manager.InfoHash, new MutableBitField (Manager.PieceCount ()), new MutableBitField (Manager.PieceCount ())));
            Manager.Mode = mode;
            await mode.WaitForStartingToComplete ();

            Assert.AreEqual (2, modeChanged.Count, "#1");
            Assert.IsInstanceOf<StartingMode> (modeChanged[0], "#2");
            Assert.IsInstanceOf<DownloadMode> (modeChanged[1], "#2");
        }
        public async Task StateChanges_NeedsHashing ()
        {
            var modeChanged = new List<Mode> ();
            Manager.ModeChanged += (oldMode, newMode) => modeChanged.Add (newMode);

            var mode = new StartingMode (Manager, DiskManager, ConnectionManager, Settings);
            Assert.IsFalse (Manager.HashChecked);
            Manager.Mode = mode;
            await mode.WaitForStartingToComplete ();

            Assert.AreEqual (3, modeChanged.Count, "#1");
            Assert.IsInstanceOf<StartingMode> (modeChanged[0], "#2");
            Assert.IsInstanceOf<HashingMode> (modeChanged[1], "#3");
            Assert.IsInstanceOf<DownloadMode> (modeChanged[2], "#4");
        }
        public async Task Announce ()
        {
            await TrackerManager.AddTrackerAsync (TrackerFactory.Create (new Uri ("http://1.1.1.1")));

            var mode = new StartingMode (Manager, DiskManager, ConnectionManager, Settings);
            Manager.Mode = mode;
            await mode.WaitForStartingToComplete ();

            // Technically this is not what we want. However the logic to avoid announcing to quickly
            // is now inside TrackerManager so a mocked TrackerManager will double announce.
            Assert.AreEqual (2, TrackerManager.Announces.Count, "#1");
            Assert.AreEqual (null, TrackerManager.Announces[0].Item1, "#2");
            Assert.AreEqual (null, TrackerManager.Announces[1].Item1, "#2");
            Assert.AreEqual (TorrentEvent.Started, TrackerManager.Announces[0].Item2, "#3");
            Assert.AreEqual (TorrentEvent.None, TrackerManager.Announces[1].Item2, "#3");
        }
        public async Task StateChanges_AlreadyHashed()
        {
            var modeChanged = new List <Mode> ();

            Manager.ModeChanged += (oldMode, newMode) => modeChanged.Add(newMode);

            var mode = new StartingMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.HashChecked = true;
            Manager.Mode        = mode;
            await mode.StartingTask;

            Assert.AreEqual(2, modeChanged.Count, "#1");
            Assert.IsInstanceOf <StartingMode> (modeChanged[0], "#2");
            Assert.IsInstanceOf <DownloadMode> (modeChanged[1], "#2");
        }
        public async Task FastResume_NoneExist ()
        {
            var bf = new MutableBitField (Manager.PieceCount ()).SetAll (true);
            Manager.LoadFastResume (new FastResume (Manager.InfoHash, bf, Manager.UnhashedPieces.SetAll (false)));

            Assert.IsTrue (Manager.Bitfield.AllTrue, "#1");
            foreach (var file in Manager.Files)
                Assert.IsTrue (file.BitField.AllTrue, "#2." + file.Path);

            var startingMode = new StartingMode (Manager, DiskManager, ConnectionManager, Settings);
            Manager.Mode = startingMode;
            await startingMode.WaitForStartingToComplete ();

            Assert.IsTrue (Manager.Bitfield.AllFalse, "#3");
            foreach (var file in Manager.Files)
                Assert.IsTrue (file.BitField.AllFalse, "#4." + file.Path);
        }
Example #11
0
        public async Task FastResume_NoneExist()
        {
            var bf = Manager.Bitfield.Clone().SetAll(true);

            Manager.LoadFastResume(new FastResume(Manager.InfoHash, bf));

            Assert.IsTrue(Manager.Bitfield.AllTrue, "#1");
            foreach (TorrentFile file in Manager.Torrent.Files)
            {
                Assert.IsTrue(file.BitField.AllTrue, "#2." + file.Path);
            }

            var startingMode = new StartingMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.Mode = startingMode;
            await startingMode.WaitForStartingToComplete();

            Assert.IsTrue(Manager.Bitfield.AllFalse, "#3");
            foreach (var file in Manager.Torrent.Files)
            {
                Assert.IsTrue(file.BitField.AllFalse, "#4." + file.Path);
            }
        }