public async Task Test_CancelDownloads_Multiple () { Console.WriteLine ("Test_CancelDownloads_Multiple"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var waiting = new Download { State = State.Waiting }; var error = new Download { State = State.Error }; var downloading = new Download { State = State.Downloading }; var finished = new Download { State = State.Finished }; repo.Insert (waiting); repo.Insert (downloading); repo.Insert (error); repo.Insert (finished); manager.CancelDownloads (new CancelDownloads { }); Assert.AreEqual (State.Finished, waiting.State, "Waiting"); Assert.AreEqual (State.Finished, downloading.State, "Downloading"); Assert.AreEqual (State.Finished, error.State, "Error"); Assert.AreEqual (State.Finished, finished.State, "Finished"); }
public async Task Test_ProgressDownload_Progress1 () { Console.WriteLine ("Test_ProgressDownload_Progress1"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); ErrorEnum downloaderror = ErrorEnum.Empty; bus.Subscribe<DownloadError> (p => { downloaderror = p.Error; }); var download = new Download { State = State.Downloading, Total = 0, Written = 0 }; repo.Insert (download); manager.ProgressDownload (new ProgressDownload { Id = download.Id, Total = 1000, Written = 10 }); Assert.AreEqual (10, download.Written, "Written"); Assert.AreEqual (1000, download.Total, "Total"); Assert.AreEqual (ErrorEnum.Empty, downloaderror, "Downloaderror"); }
public async Task Test_FinishDownload_Finish1 () { Console.WriteLine ("Test_FinishDownload_Finish1"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); ErrorEnum downloaderror = ErrorEnum.Empty; bus.Subscribe<DownloadError> (p => { downloaderror = p.Error; }); var download = new Download { State = State.Downloading, }; repo.Insert (download); manager.FinishedDownload (new FinishedDownload { Id = download.Id, }); Assert.AreEqual (ErrorEnum.Empty, downloaderror, "Downloaderror"); Assert.AreEqual (State.Finished, download.State, "Finished"); }
public async Task Test_QueueUrl_AlreadyQueued1 () { var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo); var wait1 = new AutoResetEvent (false); bool alreadyQueued = false; bool checkFreeSlot = false; bus.Subscribe<AlreadyQueued> (p => { alreadyQueued = true; wait1.Set(); }); bus.Subscribe<CheckFreeSlot> (p => { checkFreeSlot = true; wait1.Set(); }); repo.Insert(new Download { Url = "http://url.com/download/file.zip" }); manager.QueueUrl (new QueueUrl { Url = "http://url.com/download/file.zip" }); wait1.WaitOne (); Assert.AreEqual (false, checkFreeSlot); Assert.AreEqual (true, alreadyQueued); }
public async Task Test_DownloadRejected_Error2 () { Console.WriteLine ("Test_DownloadRejected_Error2"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var wait1 = new AutoResetEvent (false); ErrorEnum error = ErrorEnum.Empty; bus.Subscribe<DownloadError> (p => { error = p.Error; wait1.Set(); }); repo.Insert (new Download { Url = "url", State = State.Finished }); manager.DownloadRejected (new DownloadRejected { Id = 1, Reason = RejectionEnum.QueueFull }); wait1.WaitOne (); Assert.AreEqual (ErrorEnum.DownloadRejected_InvalidState, error); }
public void Queue_2 () { Console.WriteLine ("Queue_2"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); long total = 0; long written = 0; var wait1 = new AutoResetEvent (false); var download = new Download { Url = "url", Total = 0, Written = 0 }; repo.Insert (download); var progressmanager = new ProgressManager (bus, repo); Action<Download> progresshandle = (d) => { total = d.Total; written = d.Written; wait1.Set(); }; progressmanager.Queue (download.Url, progresshandle); download.Total = 100; download.Written = 10; progressmanager.NotifyProgress (new NotifyProgress { Url = download.Url, Download = download }); download.Written = 50; progressmanager.NotifyProgress (new NotifyProgress { Url = download.Url, Download = download }); download.Written = 100; progressmanager.NotifyProgress (new NotifyProgress { Url = download.Url, Download = download }); wait1.WaitOne (); wait1.WaitOne (); wait1.WaitOne (); Assert.AreEqual (100, written, "Written"); Assert.AreEqual (100, total, "Total"); }
public async Task Test_ResetDownloads_Multiple () { Console.WriteLine ("Test_ResetDownloads_Multiple"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var waiting = new Download { State = State.Waiting }; var error = new Download { State = State.Error }; var downloading = new Download { State = State.Downloading }; var finished = new Download { State = State.Finished }; repo.Insert (waiting); repo.Insert (downloading); repo.Insert (error); repo.Insert (finished); manager.ResetDownloads (new ResetDownloads { }); var all = repo.All (); Assert.AreEqual (0, all.Count); }
public async Task Test_CancelDownloads_Single () { Console.WriteLine ("Test_CancelDownloads_Single"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var download = new Download { State = State.Waiting }; repo.Insert (download); manager.CancelDownloads (new CancelDownloads { }); Assert.AreEqual (State.Finished, download.State, "First"); }
public async Task Test_ResetDownloads_Single () { Console.WriteLine ("Test_ResetDownloads_Single"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var download = new Download { State = State.Waiting }; repo.Insert (download); manager.ResetDownloads (new ResetDownloads { }); var all = repo.All (); Assert.AreEqual (0, all.Count); }
public async Task Test_ResetDownloads_Single() { Console.WriteLine("Test_ResetDownloads_Single"); var bus = new InProcessBus(); var repo = new DownloadRepositoryMock(); var manager = new DownloadManager.iOS.DownloadManager(bus, repo, 3); var download = new Download { State = State.Waiting }; repo.Insert(download); manager.ResetDownloads(new ResetDownloads { }); var all = repo.All(); Assert.AreEqual(0, all.Count); }
public async Task Test_FreeSlot_Empty2 () { Console.WriteLine ("Test_FreeSlot_Empty2"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var wait1 = new AutoResetEvent (false); bool queuedownload = false; bool queueempty = false; bool queuefull = false; bus.Subscribe<QueueDownload> (p => { queuedownload = true; wait1.Set(); }); bus.Subscribe<QueueFull> (p => { queuefull = true; wait1.Set(); }); bus.Subscribe<QueueEmpty> (p => { queueempty = true; wait1.Set(); }); repo.Insert(new Download { Url = "http://url.com/download/file.zip", State = State.Finished }); manager.FreeSlot (new FreeSlot { }); wait1.WaitOne (); Assert.AreEqual (false, queuedownload); Assert.AreEqual (false, queuefull); Assert.AreEqual (true, queueempty); }
public async Task Test_ProgressDownload_ErrorNotFound2() { Console.WriteLine("Test_ProgressDownload_ErrorNotFound2"); var bus = new InProcessBus(); var repo = new DownloadRepositoryMock(); var manager = new DownloadManager.iOS.DownloadManager(bus, repo, 3); var wait1 = new AutoResetEvent(false); ErrorEnum downloaderror = ErrorEnum.Empty; bus.Subscribe <DownloadError> (p => { downloaderror = p.Error; wait1.Set(); }); var download = new Download { State = State.Downloading, Total = 0, Written = 0 }; repo.Insert(download); manager.ProgressDownload(new ProgressDownload { Id = 666, Total = 1000, Written = 10 }); wait1.WaitOne(); Assert.AreEqual(0, download.Written, "Written"); Assert.AreEqual(0, download.Total, "Total"); Assert.AreEqual(ErrorEnum.ProgressDownload_IdentifierNotFound, downloaderror, "Downloaderror"); }
public async Task Test_CancelDownloads_Multiple2 () { Console.WriteLine ("Test_CancelDownloads_Multiple2"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var waiting1 = new Download { State = State.Waiting }; var waiting2 = new Download { State = State.Waiting }; var waiting3 = new Download { State = State.Waiting }; var waiting4 = new Download { State = State.Waiting }; var waiting5 = new Download { State = State.Waiting }; repo.Insert (waiting1); repo.Insert (waiting2); repo.Insert (waiting3); repo.Insert (waiting4); repo.Insert (waiting5); manager.CancelDownloads (new CancelDownloads { }); Assert.AreEqual (State.Finished, waiting1.State, "Waiting1"); Assert.AreEqual (State.Finished, waiting2.State, "Waiting2"); Assert.AreEqual (State.Finished, waiting3.State, "Waiting3"); Assert.AreEqual (State.Finished, waiting4.State, "Waiting4"); Assert.AreEqual (State.Finished, waiting5.State, "Waiting5"); }
public async Task Test_ResetDownloads_Multiple2 () { Console.WriteLine ("Test_ResetDownloads_Multiple2"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var waiting1 = new Download { State = State.Waiting }; var waiting2 = new Download { State = State.Waiting }; var waiting3 = new Download { State = State.Waiting }; var waiting4 = new Download { State = State.Waiting }; var waiting5 = new Download { State = State.Waiting }; repo.Insert (waiting1); repo.Insert (waiting2); repo.Insert (waiting3); repo.Insert (waiting4); repo.Insert (waiting5); manager.ResetDownloads (new ResetDownloads { }); var all = repo.All (); Assert.AreEqual (0, all.Count); }
public async Task Test_FinishDownload_ErrorInvalidState1 () { Console.WriteLine ("Test_FinishDownload_ErrorInvalidState1"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var wait1 = new AutoResetEvent (false); ErrorEnum downloaderror = ErrorEnum.Empty; bus.Subscribe<DownloadError> (p => { downloaderror = p.Error; wait1.Set(); }); var download = new Download { State = State.Finished, }; repo.Insert (download); manager.FinishedDownload (new FinishedDownload { Id = download.Id, }); wait1.WaitOne (); Assert.AreEqual (ErrorEnum.FinishedDownload_InvalidState, downloaderror, "DownloadError"); }
public async Task Test_ProgressDownload_ErrorNotFound2 () { Console.WriteLine ("Test_ProgressDownload_ErrorNotFound2"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var wait1 = new AutoResetEvent (false); ErrorEnum downloaderror = ErrorEnum.Empty; bus.Subscribe<DownloadError> (p => { downloaderror = p.Error; wait1.Set(); }); var download = new Download { State = State.Downloading, Total = 0, Written = 0 }; repo.Insert (download); manager.ProgressDownload (new ProgressDownload { Id = 666, Total = 1000, Written = 10 }); wait1.WaitOne (); Assert.AreEqual (0, download.Written, "Written"); Assert.AreEqual (0, download.Total, "Total"); Assert.AreEqual (ErrorEnum.ProgressDownload_IdentifierNotFound, downloaderror, "Downloaderror"); }
public async Task Test_FreeSlot_Queued_Waiting () { var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo); var wait1 = new AutoResetEvent (false); bool queueDownload = false; bool queueEmpty = false; bus.Subscribe<QueueDownload> (p => { queueDownload = true; wait1.Set(); }); bus.Subscribe<QueueEmpty> (p => { queueEmpty = true; wait1.Set(); }); repo.Insert(new Download { Url = "http://url.com/download/file.zip", State = State.Error }); repo.Insert(new Download { Url = "http://url.com/download/file2.zip", State = State.Waiting }); manager.FreeSlot (new FreeSlot { }); wait1.WaitOne (); Assert.AreEqual (true, queueDownload); Assert.AreEqual (false, queueEmpty); }
public async Task Test_DownloadError_Error3 () { Console.WriteLine ("Test_DownloadError_Error3"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var wait1 = new AutoResetEvent (false); ErrorEnum error = ErrorEnum.Empty; bus.Subscribe<DownloadError> (p => { error = p.Error; wait1.Set(); }); var download = new Download { Url = "url", State = State.Finished }; repo.Insert (download); manager.TaskError (new TaskError { Id = download.Id, Error = TaskErrorEnum.DownloadError, }); wait1.WaitOne (); Assert.AreEqual (ErrorEnum.TaskError_InvalidState, error); }
public async Task Test_DownloadError_Error500 () { Console.WriteLine ("Test_DownloadError_Error500"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var wait1 = new AutoResetEvent (false); ErrorEnum error = ErrorEnum.Empty; bus.Subscribe<DownloadError> (p => { error = p.Error; wait1.Set(); }); var download = new Download { Url = "url", State = State.Downloading }; repo.Insert (download); manager.TaskError (new TaskError { Id = download.Id, Error = TaskErrorEnum.InvalidResponse, StatusCode = 500 }); Assert.AreEqual (State.Error, download.State); Assert.AreEqual (500, download.StatusCode); }
public async Task Test_DownloadError_Error404 () { Console.WriteLine ("Test_DownloadError_Error404"); var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3); var wait1 = new AutoResetEvent (false); ErrorEnum error = ErrorEnum.Empty; bus.Subscribe<DownloadError> (p => { error = p.Error; wait1.Set(); }); var download = new Download { Url = "url", State = State.Downloading }; repo.Insert (download); manager.DownloadError (new DownloadError { Id = download.Id, Error = ErrorEnum.DidCompleteWithError_Error, }); wait1.WaitOne (10); Assert.AreEqual (State.Downloading, download.State); Assert.AreEqual (0, download.StatusCode); }
public async Task Test_ProgressDownload_ErrorInvalidState1 () { var bus = new InProcessBus (); var repo = new DownloadRepositoryMock (); var manager = new DownloadManager.iOS.DownloadManager (bus, repo); var wait1 = new AutoResetEvent (false); ErrorEnum downloaderror = ErrorEnum.Empty; bus.Subscribe<DownloadError> (p => { downloaderror = p.Error; wait1.Set(); }); var download = new Download { State = State.Finished, Total = 0, Written = 0 }; repo.Insert (download); manager.ProgressDownload (new ProgressDownload { Id = download.Id, Total = 1000, Written = 10 }); wait1.WaitOne (); Assert.AreEqual (0, download.Written, "Written"); Assert.AreEqual (0, download.Total, "Total"); Assert.AreEqual (ErrorEnum.ProgressDownload_InvalidState, downloaderror, "DownloadError"); }