public void broken_executor_should_publish_executed_event() { GivenCommandQueue(); var commandA = new CommandA(); var commandModel = new CommandModel { Body = commandA }; _executorA.Setup(s => s.Execute(It.IsAny <CommandA>())) .Throws(new NotImplementedException()); Subject.Handle(new ApplicationStartedEvent()); _commandQueue.Add(commandModel); WaitForExecution(commandModel); VerifyEventPublished <CommandExecutedEvent>(); ExceptionVerification.ExpectedErrors(1); }
public void should_follow_redirects_to_https() { if (typeof(TDispatcher) == typeof(ManagedHttpDispatcher) && PlatformInfo.IsMono) { Assert.Ignore("Will fail on tls1.2 via managed dispatcher, ignore."); } var request = new HttpRequestBuilder($"http://{_httpBinHost}/redirect-to") .AddQueryParam("url", $"https://sonarr.tv/") .Build(); request.AllowAutoRedirect = true; var response = Subject.Get(request); response.StatusCode.Should().Be(HttpStatusCode.OK); response.Content.Should().Contain("Sonarr"); ExceptionVerification.ExpectedErrors(0); }
public void should_handle_error_deleting_track_file() { GivenRootFolderExists(); GivenRootFolderHasFolders(); GivenArtistFolderExists(); Mocker.GetMock <IDiskProvider>() .Setup(s => s.FileExists(_trackFile.Path)) .Returns(true); Mocker.GetMock <IRecycleBinProvider>() .Setup(s => s.DeleteFile(_trackFile.Path, "Artist Name")) .Throws(new IOException()); Assert.Throws <NzbDroneClientException>(() => Subject.DeleteTrackFile(_artist, _trackFile)); ExceptionVerification.ExpectedErrors(1); Mocker.GetMock <IRecycleBinProvider>().Verify(v => v.DeleteFile(_trackFile.Path, "Artist Name"), Times.Once()); Mocker.GetMock <IMediaFileService>().Verify(v => v.Delete(_trackFile, DeleteMediaFileReason.Manual), Times.Never()); }
public void should_not_scan_if_series_root_folder_is_empty() { GivenRootFolder(); Subject.Scan(_series); ExceptionVerification.ExpectedWarns(1); Mocker.GetMock <IDiskProvider>() .Verify(v => v.GetFiles(_series.Path, SearchOption.AllDirectories), Times.Never()); Mocker.GetMock <IDiskProvider>() .Verify(v => v.CreateFolder(_series.Path), Times.Never()); Mocker.GetMock <IMediaFileTableCleanupService>() .Verify(v => v.Clean(It.IsAny <Series>(), It.IsAny <List <string> >()), Times.Never()); Mocker.GetMock <IMakeImportDecision>() .Verify(v => v.GetImportDecisions(It.IsAny <List <string> >(), _series), Times.Never()); }
public void should_not_delete_if_there_is_large_rar_file() { GivenValidSeries(); var localEpisode = new LocalEpisode(); var imported = new List <ImportDecision>(); imported.Add(new ImportDecision(localEpisode)); Mocker.GetMock <IMakeImportDecision>() .Setup(s => s.GetImportDecisions(It.IsAny <List <String> >(), It.IsAny <Series>(), null, true)) .Returns(imported); Mocker.GetMock <IImportApprovedEpisodes>() .Setup(s => s.Import(It.IsAny <List <ImportDecision> >(), true, null)) .Returns(imported.Select(i => new ImportResult(i)).ToList()); Mocker.GetMock <IDetectSample>() .Setup(s => s.IsSample(It.IsAny <Series>(), It.IsAny <QualityModel>(), It.IsAny <String>(), It.IsAny <Int64>(), It.IsAny <Int32>())) .Returns(true); Mocker.GetMock <IDiskProvider>() .Setup(s => s.GetFiles(It.IsAny <string>(), SearchOption.AllDirectories)) .Returns(new [] { _videoFiles.First().Replace(".ext", ".rar") }); Mocker.GetMock <IDiskProvider>() .Setup(s => s.GetFileSize(It.IsAny <string>())) .Returns(15.Megabytes()); Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory)); Mocker.GetMock <IDiskProvider>() .Verify(v => v.DeleteFolder(It.IsAny <String>(), true), Times.Never()); ExceptionVerification.ExpectedWarns(1); }
public void folder_should_not_be_tagged_if_existing_tag_is_diffrent() { //Setup WithOldWrite(); var droppedFolder = new DirectoryInfo(TempFolder + @"\_UnknownEpisode_The Office - S01E01 - Episode Title"); droppedFolder.Create(); droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1); var taggedFolder = TempFolder + @"\_UnknownSeries_The Office - S01E01 - Episode Title"; Mocker.GetMock <SeriesProvider>().Setup(s => s.FindSeries(It.IsAny <String>())).Returns <Series>(null); //Act Mocker.Resolve <PostDownloadProvider>().ProcessDownload(droppedFolder); //Assert Mocker.VerifyAllMocks(); Mocker.GetMock <DiskProvider>().Verify(c => c.MoveDirectory(droppedFolder.FullName, taggedFolder), Times.Never()); ExceptionVerification.IgnoreWarns(); }
public void failing_scheduled_job_should_mark_job_as_failed() { IEnumerable <IJob> BaseFakeJobs = new List <IJob> { brokenJob }; Mocker.SetConstant(BaseFakeJobs); //Act ResetLastExecution(); Mocker.Resolve <JobProvider>().QueueScheduled(); WaitForQueue(); //Assert var settings = Mocker.Resolve <JobProvider>().All(); settings.First().LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10)); settings.First().Success.Should().BeFalse(); brokenJob.ExecutionCount.Should().Be(1); ExceptionVerification.ExpectedErrors(1); }
public void should_overwrite_temp_response_cookie() { var requestSet = new HttpRequest($"https://{_httpBinHost}/cookies/set?my=cookie"); requestSet.Cookies.Add("my", "oldcookie"); requestSet.AllowAutoRedirect = true; requestSet.StoreRequestCookie = true; requestSet.StoreResponseCookie = false; var responseSet = Subject.Get <HttpCookieResource>(requestSet); responseSet.Resource.Cookies.Should().HaveCount(1).And.Contain("my", "cookie"); var requestCookies = new HttpRequest($"https://{_httpBinHost}/cookies"); var responseCookies = Subject.Get <HttpCookieResource>(requestCookies); responseCookies.Resource.Cookies.Should().HaveCount(1).And.Contain("my", "oldcookie"); ExceptionVerification.IgnoreErrors(); }
public void should_record_indexer_failure_if_caps_throw() { var request = new HttpRequest("http://my.indexer.com"); var response = new HttpResponse(request, new HttpHeader(), new byte[0], (HttpStatusCode)429); response.Headers["Retry-After"] = "300"; Mocker.GetMock <INewznabCapabilitiesProvider>() .Setup(v => v.GetCapabilities(It.IsAny <NewznabSettings>())) .Throws(new TooManyRequestsException(request, response)); _caps.MaxPageSize = 30; _caps.DefaultPageSize = 25; Subject.FetchRecent().Should().BeEmpty(); Mocker.GetMock <IIndexerStatusService>() .Verify(v => v.RecordFailure(It.IsAny <int>(), TimeSpan.FromMinutes(5.0)), Times.Once()); ExceptionVerification.ExpectedWarns(1); }
public void no_concurent_jobs() { IEnumerable <IJob> BaseFakeJobs = new List <IJob> { slowJob }; Mocker.SetConstant(BaseFakeJobs); var jobProvider = Mocker.Resolve <JobProvider>(); jobProvider.Initialize(); jobProvider.QueueJob(typeof(SlowJob), 1); jobProvider.QueueJob(typeof(SlowJob), 2); jobProvider.QueueJob(typeof(SlowJob), 3); WaitForQueue(); jobProvider.Queue.Should().BeEmpty(); slowJob.ExecutionCount.Should().Be(3); ExceptionVerification.AssertNoUnexcpectedLogs(); }
public void mode_transactional_should_retry_if_partial_copy() { Subject.VerificationMode = DiskTransferVerificationMode.Transactional; var retry = 0; Mocker.GetMock <IDiskProvider>() .Setup(v => v.CopyFile(_sourcePath, _tempTargetPath, false)) .Callback(() => { WithExistingFile(_tempTargetPath, true, 900); if (retry++ == 1) { WithExistingFile(_tempTargetPath, true, 1000); } }); var result = Subject.TransferFile(_sourcePath, _targetPath, TransferMode.Copy); ExceptionVerification.ExpectedWarns(1); }
public void should_store_response_cookie() { var requestSet = new HttpRequest($"http://{_httpBinHost}/cookies/set?my=cookie"); requestSet.AllowAutoRedirect = false; requestSet.StoreResponseCookie = true; var responseSet = Subject.Get(requestSet); var request = new HttpRequest($"http://{_httpBinHost}/get"); var response = Subject.Get <HttpBinResource>(request); response.Resource.Headers.Should().ContainKey("Cookie"); var cookie = response.Resource.Headers["Cookie"].ToString(); cookie.Should().Contain("my=cookie"); ExceptionVerification.IgnoreErrors(); }
public void mode_transactional_should_retry_twice_if_partial_copy() { Subject.VerificationMode = DiskTransferVerificationMode.Transactional; var retry = 0; Mocker.GetMock <IDiskProvider>() .Setup(v => v.CopyFile(_sourcePath, _tempTargetPath, false)) .Callback(() => { WithExistingFile(_tempTargetPath, true, 900); if (retry++ == 3) { throw new Exception("Test Failed, retried too many times."); } }); Assert.Throws <IOException>(() => Subject.TransferFile(_sourcePath, _targetPath, TransferMode.Copy)); ExceptionVerification.ExpectedWarns(2); ExceptionVerification.ExpectedErrors(1); }
public void should_not_process_if_grabbed_history_contains_null_downloadclient_id() { _completed.First().Category = null; GivenCompletedDownloadClientHistory(); var historyGrabbed = Builder <History.History> .CreateListOfSize(1) .Build() .ToList(); historyGrabbed.First().Data.Add("downloadClient", "SabnzbdClient"); historyGrabbed.First().Data.Add("downloadClientId", null); GivenGrabbedHistory(historyGrabbed); GivenNoImportedHistory(); GivenFailedImport(); Subject.Execute(new CheckForFinishedDownloadCommand()); VerifyNoImports(); ExceptionVerification.ExpectedWarns(1); }
public void should_not_blowup_the_process_due_to_failed_augment() { GivenSpecifications(_pass1); Mocker.GetMock <IAugmentingService>() .Setup(c => c.Augment(It.IsAny <LocalTrack>(), It.IsAny <bool>())) .Throws <TestException>(); GivenAudioFiles(new [] { @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic(), @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic(), @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic() }); Subject.GetImportDecisions(_fileInfos, _artist, FilterFilesType.None, false); Mocker.GetMock <IAugmentingService>() .Verify(c => c.Augment(It.IsAny <LocalTrack>(), It.IsAny <bool>()), Times.Exactly(_fileInfos.Count)); ExceptionVerification.ExpectedErrors(3); }
public void should_add_to_rejected_if_release_unavailable_on_indexer() { var albums = new List <Book> { GetAlbum(1) }; var remoteBook = GetRemoteAlbum(albums, new QualityModel(Quality.MP3_320)); var decisions = new List <DownloadDecision>(); decisions.Add(new DownloadDecision(remoteBook)); Mocker.GetMock <IDownloadService>() .Setup(s => s.DownloadReport(It.IsAny <RemoteBook>())) .Throws(new ReleaseUnavailableException(remoteBook.Release, "That 404 Error is not just a Quirk")); var result = Subject.ProcessDecisions(decisions); result.Grabbed.Should().BeEmpty(); result.Rejected.Should().NotBeEmpty(); ExceptionVerification.ExpectedWarns(1); }
public void map_album_should_not_update_id_if_http_throws() { Mocker.GetMock <IHttpClient>() .Setup(x => x.Get <AlbumResource>(It.IsAny <HttpRequest>())) .Throws(new Exception("Dummy exception")); var data = new SpotifyImportListItemInfo { Album = "25", AlbumSpotifyId = "id", Artist = "Adele" }; Subject.MapAlbumItem(data); data.Should().NotBeNull(); data.Artist.Should().Be("Adele"); data.ArtistMusicBrainzId.Should().BeNull(); data.Album.Should().Be("25"); data.AlbumMusicBrainzId.Should().BeNull(); ExceptionVerification.ExpectedErrors(1); }
public void should_throw_if_series_cannot_be_found() { var newSeries = new Series { TvdbId = 1, Path = @"C:\Test\TV\Title1" }; Mocker.GetMock <IProvideSeriesInfo>() .Setup(s => s.GetSeriesInfo(newSeries.TvdbId)) .Throws(new SeriesNotFoundException(newSeries.TvdbId)); Mocker.GetMock <IAddSeriesValidator>() .Setup(s => s.Validate(It.IsAny <Series>())) .Returns(new ValidationResult(new List <ValidationFailure> { new ValidationFailure("Path", "Test validation failure") })); Assert.Throws <ValidationException>(() => Subject.AddSeries(newSeries)); ExceptionVerification.ExpectedErrors(1); }
public void should_not_write_redirect_content_to_stream() { var file = GetTempFilePath(); using (var fileStream = new FileStream(file, FileMode.Create)) { var request = new HttpRequest($"http://{_httpBinHost}/redirect/1"); request.AllowAutoRedirect = false; request.ResponseStream = fileStream; var response = Subject.Get(request); response.StatusCode.Should().Be(HttpStatusCode.Redirect); } ExceptionVerification.ExpectedErrors(1); File.Exists(file).Should().BeTrue(); var fileInfo = new FileInfo(file); fileInfo.Length.Should().Be(0); }
public void should_throw_if_movie_cannot_be_found() { var newMovie = new Movie { TmdbId = 1, Path = @"C:\Test\Movie\Title1" }; Mocker.GetMock <IProvideMovieInfo>() .Setup(s => s.GetMovieInfo(newMovie.TmdbId)) .Throws(new MovieNotFoundException("Movie Not Found")); Mocker.GetMock <IAddMovieValidator>() .Setup(s => s.Validate(It.IsAny <Movie>())) .Returns(new ValidationResult(new List <ValidationFailure> { new ValidationFailure("Path", "Test validation failure") })); Assert.Throws <ValidationException>(() => Subject.AddMovie(newMovie)); ExceptionVerification.ExpectedErrors(1); }
public void can_run_broken_job_again() { IEnumerable <IJob> BaseFakeJobs = new List <IJob> { brokenJob }; Mocker.SetConstant(BaseFakeJobs); var jobProvider = Mocker.Resolve <JobProvider>(); jobProvider.Initialize(); //Act jobProvider.QueueJob(typeof(BrokenJob)); WaitForQueue(); jobProvider.QueueJob(typeof(BrokenJob)); WaitForQueue(); //Assert brokenJob.ExecutionCount.Should().Be(2); ExceptionVerification.ExpectedErrors(2); }
public void should_throw_if_author_cannot_be_found() { var newAuthor = new Author { ForeignAuthorId = "ce09ea31-3d4a-4487-a797-e315175457a0", Path = @"C:\Test\Music\Name1" }; Mocker.GetMock <IProvideAuthorInfo>() .Setup(s => s.GetAuthorInfo(newAuthor.ForeignAuthorId, true)) .Throws(new AuthorNotFoundException(newAuthor.ForeignAuthorId)); Mocker.GetMock <IAddAuthorValidator>() .Setup(s => s.Validate(It.IsAny <Author>())) .Returns(new ValidationResult(new List <ValidationFailure> { new ValidationFailure("Path", "Test validation failure") })); Assert.Throws <ValidationException>(() => Subject.AddAuthor(newAuthor)); ExceptionVerification.ExpectedErrors(1); }
public void should_parse_malformed_cloudflare_cookie(string culture) { var origCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture); try { // the date is bad in the below - should be 13-Jul-2026 string malformedCookie = @"__cfduid=d29e686a9d65800021c66faca0a29b4261436890790; expires=Mon, 13-Jul-26 16:19:50 GMT; path=/; HttpOnly"; var requestSet = new HttpRequestBuilder($"https://{_httpBinHost}/response-headers") .AddQueryParam("Set-Cookie", malformedCookie) .Build(); requestSet.AllowAutoRedirect = false; requestSet.StoreResponseCookie = true; var responseSet = Subject.Get(requestSet); var request = new HttpRequest($"https://{_httpBinHost}/get"); var response = Subject.Get <HttpBinResource>(request); response.Resource.Headers.Should().ContainKey("Cookie"); var cookie = response.Resource.Headers["Cookie"].ToString(); cookie.Should().Contain("__cfduid=d29e686a9d65800021c66faca0a29b4261436890790"); ExceptionVerification.IgnoreErrors(); } finally { Thread.CurrentThread.CurrentCulture = origCulture; Thread.CurrentThread.CurrentUICulture = origCulture; } }
public void should_parse_malformed_cloudflare_cookie(string culture) { var origCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture); try { // the date is bad in the below - should be 13-Jul-2016 string malformedCookie = @"__cfduid=d29e686a9d65800021c66faca0a29b4261436890790; expires=Wed, 13-Jul-16 16:19:50 GMT; path=/; HttpOnly"; string url = "http://eu.httpbin.org/response-headers?Set-Cookie=" + System.Uri.EscapeUriString(malformedCookie); var requestSet = new HttpRequest(url); requestSet.AllowAutoRedirect = false; requestSet.StoreResponseCookie = true; var responseSet = Subject.Get(requestSet); var request = new HttpRequest("http://eu.httpbin.org/get"); var response = Subject.Get <HttpBinResource>(request); response.Resource.Headers.Should().ContainKey("Cookie"); var cookie = response.Resource.Headers["Cookie"].ToString(); cookie.Should().Contain("__cfduid=d29e686a9d65800021c66faca0a29b4261436890790"); ExceptionVerification.IgnoreErrors(); } finally { Thread.CurrentThread.CurrentCulture = origCulture; Thread.CurrentThread.CurrentUICulture = origCulture; } }
public void should_not_mark_as_imported_if_some_files_were_skipped() { GivenCompletedDownloadClientHistory(); var history = Builder <History.History> .CreateListOfSize(1) .Build() .ToList(); GivenGrabbedHistory(history); GivenNoImportedHistory(); Mocker.GetMock <IDownloadedEpisodesImportService>() .Setup(v => v.ProcessFolder(It.IsAny <DirectoryInfo>(), It.IsAny <DownloadClientItem>())) .Returns(new List <ImportResult> { new ImportResult(new ImportDecision(new LocalEpisode() { Path = @"C:\TestPath\Droned.S01E01.mkv" })), new ImportResult( new ImportDecision(new LocalEpisode() { Path = @"C:\TestPath\Droned.S01E01.mkv" }), "Test Failure") }); history.First().Data.Add("downloadClient", "SabnzbdClient"); history.First().Data.Add("downloadClientId", _completed.First().DownloadClientId); Subject.Execute(new CheckForFinishedDownloadCommand()); Mocker.GetMock <IDiskProvider>() .Verify(c => c.DeleteFolder(It.IsAny <string>(), true), Times.Never()); ExceptionVerification.ExpectedErrors(1); }
public void should_reject_malformed_domain_cookie(string malformedCookie) { try { string url = $"https://{_httpBinHost}/response-headers?Set-Cookie={Uri.EscapeUriString(malformedCookie)}"; var requestSet = new HttpRequest(url); requestSet.AllowAutoRedirect = false; requestSet.StoreResponseCookie = true; var responseSet = Subject.Get(requestSet); var request = new HttpRequest($"https://{_httpBinHost}/get"); var response = Subject.Get <HttpBinResource>(request); response.Resource.Headers.Should().NotContainKey("Cookie"); ExceptionVerification.IgnoreErrors(); } finally { } }
public void should_not_blowup_the_process_due_to_failed_parse() { GivenSpecifications(_pass1); Mocker.GetMock <IParsingService>() .Setup(c => c.GetLocalEpisode(It.IsAny <string>(), It.IsAny <Series>(), It.IsAny <ParsedEpisodeInfo>(), It.IsAny <bool>())) .Throws <TestException>(); _videoFiles = new List <string> { "The.Office.S03E115.DVDRip.XviD-OSiTV", "The.Office.S03E115.DVDRip.XviD-OSiTV", "The.Office.S03E115.DVDRip.XviD-OSiTV" }; GivenVideoFiles(_videoFiles); Subject.GetImportDecisions(_videoFiles, _series); Mocker.GetMock <IParsingService>() .Verify(c => c.GetLocalEpisode(It.IsAny <string>(), It.IsAny <Series>(), It.IsAny <ParsedEpisodeInfo>(), It.IsAny <bool>()), Times.Exactly(_videoFiles.Count)); ExceptionVerification.ExpectedErrors(3); }
public void should_not_process_if_storage_directory_in_drone_factory() { GivenCompletedDownloadClientHistory(true); var history = Builder <History.History> .CreateListOfSize(1) .Build() .ToList(); GivenGrabbedHistory(history); GivenNoImportedHistory(); Mocker.GetMock <IConfigService>() .SetupGet(v => v.DownloadedEpisodesFolder) .Returns(@"C:\DropFolder".AsOsAgnostic()); history.First().Data.Add("downloadClient", "SabnzbdClient"); history.First().Data.Add("downloadClientId", _completed.First().DownloadClientId); Subject.Execute(new CheckForFinishedDownloadCommand()); VerifyNoImports(); ExceptionVerification.IgnoreWarns(); }
public void should_not_remove_if_imported_failed() { GivenCompletedDownloadClientHistory(); var history = Builder <History.History> .CreateListOfSize(1) .Build() .ToList(); GivenGrabbedHistory(history); GivenNoImportedHistory(); GivenFailedImport(); _completed.First().IsReadOnly = true; history.First().Data.Add("downloadClient", "SabnzbdClient"); history.First().Data.Add("downloadClientId", _completed.First().DownloadClientId); Subject.Execute(new CheckForFinishedDownloadCommand()); Mocker.GetMock <IDiskProvider>() .Verify(c => c.DeleteFolder(It.IsAny <string>(), true), Times.Never()); ExceptionVerification.IgnoreErrors(); }
public void should_log_error_if_rollback_move_fails() { var targetPath = Path.Combine(Path.GetDirectoryName(_sourcePath), Path.GetFileName(_sourcePath).ToUpper()); Mocker.GetMock <IDiskProvider>() .Setup(v => v.MoveFile(_sourcePath, _backupPath, true)) .Callback(() => { WithExistingFile(_backupPath, true); WithExistingFile(_sourcePath, false); }); Mocker.GetMock <IDiskProvider>() .Setup(v => v.MoveFile(_backupPath, targetPath, false)) .Throws(new IOException("Access Violation")); Mocker.GetMock <IDiskProvider>() .Setup(v => v.MoveFile(_backupPath, _sourcePath, false)) .Throws(new IOException("Access Violation")); Assert.Throws <IOException>(() => Subject.TransferFile(_sourcePath, targetPath, TransferMode.Move)); ExceptionVerification.ExpectedErrors(1); }