public void RefreshFileCountsTest() { // Create the folder and files to test. var folders = CreateTestDirectory(Root, "Alpha Folder", "Beta Folder"); CreateTestFile(folders[0], "Alpha.S01E01.avi", "Alpha.S01E01.Name.avi", "Alpha.S01E01-02.avi"); TestShows.First(x => x.Name == "Beta Show").Episodes[0].FileCount = 1; // When save shows is called. Assert that each episode has the correct file count. StorageProvider.SaveShows( Arg.Do( new Action <IEnumerable <TvShow> >( x => { var shows = x.ToList(); Assert.AreEqual(3, shows[0].Episodes[0].FileCount); Assert.AreEqual(1, shows[0].Episodes[1].FileCount); Assert.AreEqual(0, shows[1].Episodes[0].FileCount); }))); // Refresh the file counts. scanManager.RefreshFileCounts(new[] { Root }); // Ensure that the call was made. If it was the delegate above will not have been run. StorageProvider.Received(1).SaveShows(Arg.Any <IEnumerable <TvShow> >()); }
public void DualEpisodeFormatting() { // Creat the result. var result = new FileResult { Checked = true, Show = TestShows.First(), InputFile = Substitute.For <IFileInfo>() }; result.Episode = result.Show.Episodes.First(); result.Episodes = new List <Episode> { result.Episode, result.Show.Episodes[1] }; result.InputFile.Extension.Returns(".avi"); var fileResultManager = new FileResultManager(StorageProvider); // Format the string. var output = fileResultManager.FormatOutputPath(result, "{SName(.)}.S{SNum(2)}E{ENum(2)}.{EName(.)}"); Assert.AreEqual( "Alpha.Show.S01E01-02.Episode.One.(1-2)", output, "The output format does not match what it should be."); }
public void AddAlternateName() { var alpha = TestShows.First(); // When the data provider is searched for ShowName, return Alpha. dataProvider.SearchShow("ShowName").Returns(new List <TvShow> { alpha }); // Create the file to be searched. CreateTestFile(Root, "ShowName.S01E01.avi"); // When the show is saved, alpha should contain ShowName as an alternate name. StorageProvider.When(x => x.SaveShow(alpha)) .Do(x => Assert.Contains("ShowName", x.Arg <TvShow>().AlternateNames)); var results = scanManager.Refresh(Root); // There should be one result matching Delta Episode 1. Assert.AreEqual(1, results.Count, "There should be one result."); Assert.AreEqual(results[0].Show, alpha, "The show shuld be Alpha"); // Check that the results were called. StorageProvider.Received(1).SaveShow(alpha); }
/// <summary> /// Asserts the result matches the first show and its first episode. /// </summary> /// <param name="result"> /// The result to check. /// </param> private void MatchesShow1(FileResult result) { Assert.AreEqual(TestShows.First(), result.Show, "The result should be the first test show."); Assert.AreEqual( TestShows.First().Episodes.First(), result.Episode, "The result should match the show's first episode."); }
public void ResetShowNoEpisode() { CreateTestFile(Root, "Alpha.S02E02.avi"); var results = scanManager.Refresh(Root); Assert.AreEqual(1, results.Count, "There should be 1 result."); scanManager.ResetShow(results[0], TestShows.First(x => x.Name == "Beta Show")); Assert.AreEqual("Beta Show", results[0].Show.Name, "The show hasn't changed."); Assert.AreEqual(null, results[0].Episode, "The episode shouldn't have been matched."); }
public void ResetShow() { CreateTestFile(Root, "Alpha.S01E01.avi"); var results = scanManager.Refresh(Root); Assert.AreEqual(1, results.Count, "There should be 1 result."); MatchesShow1(results[0]); scanManager.ResetShow(results[0], TestShows.First(x => x.Name == "Beta Show")); Assert.AreEqual("Beta Show", results[0].Show.Name, "The show hasn't changed."); Assert.AreEqual("211", results[0].Episode.TvdbId, "The episode hasn't changed."); }
public void DualEpisodeScanning() { CreateTestFile(Root, "Alpha.S01E01-02.avi"); var results = scanManager.Refresh(Root); Assert.AreEqual(1, results.Count, "There should be 1 result"); MatchesShow1(results[0]); Assert.AreEqual(2, results[0].Episodes.Count, "There should be 2 episode in the result."); Assert.AreEqual( TestShows.First().Episodes[1], results[0].Episodes[1], "The second episode should be show's second epsiode."); }
public string TestOutputFormat(string format) { // Creat the result. var result = new FileResult { Checked = true, Show = TestShows.First(), InputFile = Substitute.For <IFileInfo>() }; result.Episode = result.Show.Episodes.First(); result.Episodes = new List <Episode> { result.Episode }; result.InputFile.Extension.Returns(".avi"); var fileResultManager = new FileResultManager(StorageProvider); // Format the string. return(fileResultManager.FormatOutputPath(result, format)); }
public void FileCopyMove() { var file = CreateTestFile(Root, "alpha.s01e01.avi")[0]; var result = new FileResult { Checked = true, Show = TestShows.First(), InputFile = file }; result.Episode = result.Show.Episodes.First(); result.Episodes = new List <Episode> { result.Episode }; IDirectoryInfo seasonOne = null; Root.GetFile(Arg.Any <string>()) .Returns( x => { var path = x.Arg <string>(); // Check that the path is as expected var expectedPath = string.Format( "Alpha Folder{0}Season 1{0}Alpha.Show.S01E01.Episode.One.(1).avi", Path.DirectorySeparatorChar); Assert.AreEqual(expectedPath, path, "The path is incorrect."); // Return the correct file. var alphaFolder = CreateTestDirectory(Root, "Alpha Folder")[0]; seasonOne = CreateTestDirectory(alphaFolder, "Season 1")[0]; seasonOne.Exists.Returns(false); var episodeFile = CreateTestFile(seasonOne, "Alpha.Show.S01E01.Episode.One.(1).avi")[0]; episodeFile.Exists.Returns(false); return(episodeFile); }); fileManager.ProcessFiles(new List <FileResult> { result }, FileManager.SortType.Copy, Root); // Check that seasonOne has been created. Assert.NotNull(seasonOne, "The Season One folder should have been created."); // Check that there was a call to its create method. seasonOne.Received(1).Create(); // Copy the files. file.Received(1) .CopyTo( string.Format( "TV{0}Alpha Folder{0}Season 1{0}Alpha.Show.S01E01.Episode.One.(1).avi", Path.DirectorySeparatorChar)); // Check that the episode was saved. StorageProvider.Received(1).SaveEpisode(result.Episode); StorageProvider.ClearReceivedCalls(); // Move the files fileManager.ProcessFiles(new List <FileResult> { result }, FileManager.SortType.Move, Root); // Should be one call to seasonOne Create since it should have been recreated. seasonOne.Received(1).Create(); // Should be one call to MoveTo with the new directory path. file.Received(1) .MoveTo( string.Format( "TV{0}Alpha Folder{0}Season 1{0}Alpha.Show.S01E01.Episode.One.(1).avi", Path.DirectorySeparatorChar)); // Check that the episode was saved. StorageProvider.Received(1).SaveEpisode(result.Episode); }