public void should_throw_new_entries_if_queue_is_full() { var failed = false; var sut = new UploadQueue <string>(x => Thread.Sleep(100)); sut.MaxQueueSize = 1; sut.ActivateSync = true; sut.Add("hello"); sut.UploadFailed += (o, e) => failed = true; sut.Add("hello"); failed.Should().BeTrue(); }
public void should_invoke_Background_job() { var uploadIsInvoked = false; var sut = new UploadQueue <string>(x => uploadIsInvoked = true); sut.ActivateSync = true; sut.Add("hello"); sut.Wait(100); sut.TaskWasInvoked.Should().BeTrue(); }
/// <summary> /// Upload the report to the web service. /// </summary> /// <param name="report">CreateReport to submit</param> public void UploadReport(UploadToScreenshotsDTO report) { if (report == null) { throw new ArgumentNullException("report"); } if (!NetworkInterface.GetIsNetworkAvailable() || _queueReportsAccessor()) { _reportQueue.Add(report); } else { TryUploadReportNow(report); } }
public void should_retry_if_upload_fails() { int attempts = 0; var sut = new UploadQueue <string>(x => { attempts++; throw new NotSupportedException("we need more power"); }); sut.ActivateSync = true; sut.RetryInterval = TimeSpan.FromMilliseconds(10); sut.Add("hello"); sut.Wait(1000); attempts.Should().BeGreaterThan(1); }
public void should_not_invoke_Failed_report_if_upload_is_successful() { int attempts = 0; var sut = new UploadQueue <string>(x => { }); sut.ActivateSync = true; sut.RetryInterval = TimeSpan.FromMilliseconds(10); sut.MaxAttempts = 3; bool failed = false; sut.UploadFailed += (sender, args) => failed = true; sut.Add("hello"); sut.Wait(1000); failed.Should().BeFalse(); }
public void should_not_invoke_directly_if_queue_got_items() { var uploadIsInvoked = false; var directly = false; var sut = new UploadQueue <string>(x => { uploadIsInvoked = true; Thread.Sleep(50); }); sut.Add("precondition"); sut.ActivateSync = true; sut.AddIfNotEmpty("hello", () => directly = true); sut.Wait(10000); directly.Should().BeFalse("because there is an active worker"); uploadIsInvoked.Should() .BeTrue( "because it should be invoked even if a task is supplied as an argument when the queue is not empty"); }
public void should_throw_report_after_max_attempts() { int attempts = 0; var sut = new UploadQueue <string>(x => { attempts++; throw new NotSupportedException("we need more power"); }); sut.ActivateSync = true; sut.RetryInterval = TimeSpan.FromMilliseconds(10); sut.MaxAttempts = 3; bool failed = false; sut.UploadFailed += (sender, args) => failed = true; sut.Add("hello"); sut.Wait(1000); failed.Should().BeTrue(); }
/// <summary> /// 29/01/2015 /// 1) Create update files list /// 2) Create queue upload list. Iterating file list foreach connection ( i can have multiple cloud storage ) /// 3) Start async upload. /// </summary> internal void BeginUpdatedFiles(int mode) { // ? -> Set IsEnabled = false on GUI to prevent change during upload ? var releasesPath = SquirrelOutputPath; if (!Directory.Exists(releasesPath)) { throw new Exception("Releases directory " + releasesPath + "not finded !"); } if (SelectedConnection == null) { throw new Exception("No selected upload location !"); } /* I tried picking file to update, by their LastWriteTime , but it doesn't works good. I don't know why. * * So i just pick these file by their name * */ var fileToUpdate = new List <string>() { "RELEASES", string.Format("{0}-{1}-delta.nupkg", AppId, Version), }; if (mode == 0) { fileToUpdate.Add(string.Format("Setup.exe")); // fileToUpdate.Add(string.Format("{0}-{1}-full.nupkg", AppId, Version)); } var updatedFiles = new List <FileInfo>(); foreach (var fp in fileToUpdate) { var ffp = releasesPath + fp; if (!File.Exists(ffp)) { continue; } updatedFiles.Add(new FileInfo(ffp)); } if (UploadQueue == null) { UploadQueue = new ObservableCollection <SingleFileUpload>(); } UploadQueue.Clear(); var WebConnections = new List <WebConnectionBase>() { SelectedConnection }; foreach (var connection in WebConnections) { foreach (var file in updatedFiles) { UploadQueue.Add(new SingleFileUpload() { Filename = Path.GetFileName(file.FullName), ConnectionName = connection.ConnectionName, FileSize = BytesToString(file.Length), Connection = connection, FullPath = file.FullName, }); } } if (!CheckInternetConnection.IsConnectedToInternet()) { throw new Exception("Internet Connection not available"); } ProcessNextUploadFile(); }