1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

more tests fixed.

This commit is contained in:
Keivan Beigi 2013-04-17 16:32:53 -07:00
parent f9bb4178ed
commit 7c3c02ba60
8 changed files with 113 additions and 99 deletions

View File

@ -1,7 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
@ -9,7 +8,7 @@
namespace NzbDrone.Common.Test namespace NzbDrone.Common.Test
{ {
[TestFixture] [TestFixture]
public class DiskProviderFixture : TestBase public class DiskProviderFixture : TestBase<DiskProvider>
{ {
DirectoryInfo _binFolder; DirectoryInfo _binFolder;
DirectoryInfo _binFolderCopy; DirectoryInfo _binFolderCopy;
@ -36,31 +35,31 @@ public void Setup()
[Test] [Test]
public void directory_exist_should_be_able_to_find_existing_folder() public void directory_exist_should_be_able_to_find_existing_folder()
{ {
Mocker.Resolve<DiskProvider>().FolderExists(TempFolder).Should().BeTrue(); Subject.FolderExists(TempFolder).Should().BeTrue();
} }
[Test] [Test]
public void directory_exist_should_be_able_to_find_existing_unc_share() public void directory_exist_should_be_able_to_find_existing_unc_share()
{ {
Mocker.Resolve<DiskProvider>().FolderExists(@"\\localhost\c$").Should().BeTrue(); Subject.FolderExists(@"\\localhost\c$").Should().BeTrue();
} }
[Test] [Test]
public void directory_exist_should_not_be_able_to_find_none_existing_folder() public void directory_exist_should_not_be_able_to_find_none_existing_folder()
{ {
Mocker.Resolve<DiskProvider>().FolderExists(@"C:\ThisBetterNotExist\").Should().BeFalse(); Subject.FolderExists(@"C:\ThisBetterNotExist\").Should().BeFalse();
} }
[Test] [Test]
public void moveFile_should_overwrite_existing_file() public void moveFile_should_overwrite_existing_file()
{ {
var diskProvider = new DiskProvider();
diskProvider.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName);
var targetPath = Path.Combine(_binFolderCopy.FullName, "file.move"); var targetPath = Path.Combine(_binFolderCopy.FullName, "file.move");
diskProvider.MoveFile(_binFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath); Subject.MoveFile(_binFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath);
diskProvider.MoveFile(_binFolderCopy.GetFiles("*.pdb", SearchOption.AllDirectories).First().FullName, targetPath); Subject.MoveFile(_binFolderCopy.GetFiles("*.pdb", SearchOption.AllDirectories).First().FullName, targetPath);
File.Exists(targetPath).Should().BeTrue(); File.Exists(targetPath).Should().BeTrue();
} }
@ -68,12 +67,12 @@ public void moveFile_should_overwrite_existing_file()
[Test] [Test]
public void moveFile_should_not_move_overwrite_itself() public void moveFile_should_not_move_overwrite_itself()
{ {
var diskProvider = new DiskProvider();
diskProvider.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName);
var targetPath = _binFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName; var targetPath = _binFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName;
diskProvider.MoveFile(targetPath, targetPath); Subject.MoveFile(targetPath, targetPath);
File.Exists(targetPath).Should().BeTrue(); File.Exists(targetPath).Should().BeTrue();
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
@ -83,8 +82,8 @@ public void moveFile_should_not_move_overwrite_itself()
public void CopyFolder_should_copy_folder() public void CopyFolder_should_copy_folder()
{ {
var diskProvider = new DiskProvider();
diskProvider.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName);
VerifyCopy(); VerifyCopy();
@ -95,15 +94,15 @@ public void CopyFolder_should_copy_folder()
public void CopyFolder_should_overright_existing_folder() public void CopyFolder_should_overright_existing_folder()
{ {
var diskProvider = new DiskProvider();
diskProvider.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName);
Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName);
//Delete Random File //Delete Random File
_binFolderCopy.Refresh(); _binFolderCopy.Refresh();
_binFolderCopy.GetFiles("*.*", SearchOption.AllDirectories).First().Delete(); _binFolderCopy.GetFiles("*.*", SearchOption.AllDirectories).First().Delete();
diskProvider.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName);
VerifyCopy(); VerifyCopy();
@ -112,14 +111,14 @@ public void CopyFolder_should_overright_existing_folder()
[Test] [Test]
public void MoveFolder_should_overright_existing_folder() public void MoveFolder_should_overright_existing_folder()
{ {
var diskProvider = new DiskProvider();
diskProvider.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName);
diskProvider.CopyDirectory(_binFolder.FullName, _binFolderMove.FullName); Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName);
Subject.CopyDirectory(_binFolder.FullName, _binFolderMove.FullName);
VerifyCopy(); VerifyCopy();
diskProvider.MoveDirectory(_binFolderCopy.FullName, _binFolderMove.FullName); Subject.MoveDirectory(_binFolderCopy.FullName, _binFolderMove.FullName);
VerifyMove(); VerifyMove();
@ -140,6 +139,12 @@ public void MoveFolder_should_overright_existing_folder()
[TestCase(@"\\smallcheese\DRIVE_G\TV-C\Simspsons", @"\\smallcheese\DRIVE_G\TV-C\Simspsons")] [TestCase(@"\\smallcheese\DRIVE_G\TV-C\Simspsons", @"\\smallcheese\DRIVE_G\TV-C\Simspsons")]
public void paths_should_be_equeal(string first, string second) public void paths_should_be_equeal(string first, string second)
{ {
if (first.StartsWith("\\"))
{
//verify the linux equivalent.
DiskProvider.PathEquals(first.Replace("\\", "/"), second.Replace("\\", "/")).Should().BeTrue();
}
DiskProvider.PathEquals(first, second).Should().BeTrue(); DiskProvider.PathEquals(first, second).Should().BeTrue();
} }
@ -154,35 +159,35 @@ public void paths_should_not_be_equeal(string first, string second)
public void empty_folder_should_return_folder_modified_date() public void empty_folder_should_return_folder_modified_date()
{ {
var tempfolder = new DirectoryInfo(TempFolder); var tempfolder = new DirectoryInfo(TempFolder);
Mocker.Resolve<DiskProvider>().GetLastFolderWrite(TempFolder).Should().Be(tempfolder.LastWriteTimeUtc); Subject.GetLastFolderWrite(TempFolder).Should().Be(tempfolder.LastWriteTimeUtc);
} }
[Test] [Test]
public void folder_should_return_correct_value_for_last_write() public void folder_should_return_correct_value_for_last_write()
{ {
var appPath = new EnvironmentProvider().WorkingDirectory; var appPath = new EnvironmentProvider().WorkingDirectory;
Mocker.Resolve<DiskProvider>().GetLastFolderWrite(appPath).Should().BeOnOrAfter(DateTime.UtcNow.AddMinutes(-10)); Subject.GetLastFolderWrite(appPath).Should().BeOnOrAfter(DateTime.UtcNow.AddMinutes(-10));
Mocker.Resolve<DiskProvider>().GetLastFolderWrite(appPath).Should().BeBefore(DateTime.UtcNow); Subject.GetLastFolderWrite(appPath).Should().BeBefore(DateTime.UtcNow);
} }
[Test] [Test]
[Explicit] [Explicit]
public void check_last_write() public void check_last_write()
{ {
Console.WriteLine(Mocker.Resolve<DiskProvider>().GetLastFolderWrite(@"C:\DRIVERS")); Console.WriteLine(Subject.GetLastFolderWrite(@"C:\DRIVERS"));
Console.WriteLine(new DirectoryInfo(@"C:\DRIVERS").LastWriteTimeUtc); Console.WriteLine(new DirectoryInfo(@"C:\DRIVERS").LastWriteTimeUtc);
} }
[Test] [Test]
public void IsChildOfPath_should_return_true_when_it_is_a_child() public void IsChildOfPath_should_return_true_when_it_is_a_child()
{ {
Mocker.Resolve<DiskProvider>().IsChildOfPath(@"C:\Test\TV", @"C:\Test").Should().BeTrue(); Subject.IsChildOfPath(@"C:\Test\TV", @"C:\Test").Should().BeTrue();
} }
[Test] [Test]
public void IsChildOfPath_should_return_false_when_it_is_not_a_child() public void IsChildOfPath_should_return_false_when_it_is_not_a_child()
{ {
Mocker.Resolve<DiskProvider>().IsChildOfPath(@"C:\NOT_Test\TV", @"C:\Test").Should().BeFalse(); Subject.IsChildOfPath(@"C:\NOT_Test\TV", @"C:\Test").Should().BeFalse();
} }
private void VerifyCopy() private void VerifyCopy()

View File

@ -10,8 +10,8 @@ public class ProcessProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static readonly string NzbDroneProccessName = "NzbDrone"; public const string NzbDroneProcessName = "NzbDrone";
public static readonly string NzbDroneConsoleProccessName = "NzbDrone.Console"; public const string NzbDroneConsoleProcessName = "NzbDrone.Console";
public virtual ProcessInfo GetCurrentProcess() public virtual ProcessInfo GetCurrentProcess()
{ {
@ -66,7 +66,7 @@ public virtual void WaitForExit(Process process)
public virtual void Kill(int processId) public virtual void Kill(int processId)
{ {
if (processId == 0 || !Process.GetProcesses().Any(p => p.Id == processId)) if (processId == 0 || Process.GetProcesses().All(p => p.Id != processId))
{ {
Logger.Warn("Cannot find process with id: {0}", processId); Logger.Warn("Cannot find process with id: {0}", processId);
return; return;
@ -74,14 +74,16 @@ public virtual void Kill(int processId)
var process = Process.GetProcessById(processId); var process = Process.GetProcessById(processId);
if (!process.HasExited) if (process.HasExited)
{ {
Logger.Info("[{0}]: Killing process", process.Id); return;
process.Kill();
Logger.Info("[{0}]: Waiting for exit", process.Id);
process.WaitForExit();
Logger.Info("[{0}]: Process terminated successfully", process.Id);
} }
Logger.Info("[{0}]: Killing process", process.Id);
process.Kill();
Logger.Info("[{0}]: Waiting for exit", process.Id);
process.WaitForExit();
Logger.Info("[{0}]: Process terminated successfully", process.Id);
} }
public virtual void SetPriority(int processId, ProcessPriorityClass priority) public virtual void SetPriority(int processId, ProcessPriorityClass priority)

View File

@ -6,22 +6,20 @@
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests namespace NzbDrone.Core.Test.ProviderTests
{ {
[TestFixture] [TestFixture]
public class MisnamedProviderTest : CoreTest public class MisnamedProviderTest : CoreTest<MisnamedProvider>
{ {
[Test] [Test]
public void no_misnamed_files() public void no_misnamed_files()
{ {
var series = Builder<Series>.CreateNew() var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle") .With(s => s.Title = "SeriesTitle")
.Build(); .Build();
@ -44,7 +42,7 @@ public void no_misnamed_files()
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build().ToList(); .Build().ToList();
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
@ -57,18 +55,18 @@ public void no_misnamed_files()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), episodeFiles[1])) .Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), episodeFiles[1]))
.Returns("Title2"); .Returns("Title2");
var totalItems = 0;
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
var totalItems = 0;
var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems);
misnamedEpisodes.Should().HaveCount(0); misnamedEpisodes.Should().HaveCount(0);
} }
[Test] [Test]
public void all_misnamed_files() public void all_misnamed_files()
{ {
var series = Builder<Series>.CreateNew() var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle") .With(s => s.Title = "SeriesTitle")
.Build(); .Build();
@ -91,7 +89,7 @@ public void all_misnamed_files()
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build().ToList(); .Build().ToList();
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
@ -104,18 +102,18 @@ public void all_misnamed_files()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), episodeFiles[1])) .Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), episodeFiles[1]))
.Returns("New Title 2"); .Returns("New Title 2");
var totalItems = 0;
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
var totalItems = 0;
var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems);
misnamedEpisodes.Should().HaveCount(2); misnamedEpisodes.Should().HaveCount(2);
} }
[Test] [Test]
public void one_misnamed_file() public void one_misnamed_file()
{ {
var series = Builder<Series>.CreateNew() var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle") .With(s => s.Title = "SeriesTitle")
.Build(); .Build();
@ -138,7 +136,7 @@ public void one_misnamed_file()
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build().ToList(); .Build().ToList();
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
@ -151,20 +149,21 @@ public void one_misnamed_file()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), episodeFiles[1])) .Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), episodeFiles[1]))
.Returns("Title2"); .Returns("Title2");
var totalItems = 0;
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
var totalItems = 0;
var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems);
misnamedEpisodes.Should().HaveCount(1); misnamedEpisodes.Should().HaveCount(1);
misnamedEpisodes[0].CurrentName.Should().Be("Title1"); misnamedEpisodes[0].CurrentName.Should().Be("Title1");
misnamedEpisodes[0].ProperName.Should().Be("New Title 1"); misnamedEpisodes[0].ProperName.Should().Be("New Title 1");
} }
[Test] [Test]
[Ignore]
public void misnamed_multi_episode_file() public void misnamed_multi_episode_file()
{ {
var series = Builder<Series>.CreateNew() var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle") .With(s => s.Title = "SeriesTitle")
.Build(); .Build();
@ -187,7 +186,7 @@ public void misnamed_multi_episode_file()
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build().ToList(); .Build().ToList();
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
@ -200,20 +199,21 @@ public void misnamed_multi_episode_file()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), episodeFiles[1])) .Setup(c => c.BuildFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), episodeFiles[1]))
.Returns("Title2"); .Returns("Title2");
var totalItems = 0;
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
var totalItems = 0;
var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems);
misnamedEpisodes.Should().HaveCount(1); misnamedEpisodes.Should().HaveCount(1);
misnamedEpisodes[0].CurrentName.Should().Be("Title1"); misnamedEpisodes[0].CurrentName.Should().Be("Title1");
misnamedEpisodes[0].ProperName.Should().Be("New Title 1"); misnamedEpisodes[0].ProperName.Should().Be("New Title 1");
} }
[Test] [Test]
[Ignore]
public void no_misnamed_multi_episode_file() public void no_misnamed_multi_episode_file()
{ {
var series = Builder<Series>.CreateNew() var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle") .With(s => s.Title = "SeriesTitle")
.Build(); .Build();
@ -236,7 +236,7 @@ public void no_misnamed_multi_episode_file()
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build().ToList(); .Build().ToList();
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
@ -249,11 +249,11 @@ public void no_misnamed_multi_episode_file()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), episodeFiles[1])) .Setup(c => c.BuildFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), episodeFiles[1]))
.Returns("Title2"); .Returns("Title2");
var totalItems = 0;
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
var totalItems = 0;
var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems);
misnamedEpisodes.Should().HaveCount(0); misnamedEpisodes.Should().HaveCount(0);
} }
} }

View File

@ -5,6 +5,7 @@
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
@ -45,6 +46,10 @@ private void WithRecentFolderWrite()
Mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.GetLastFolderWrite(It.IsAny<String>())) .Setup(c => c.GetLastFolderWrite(It.IsAny<String>()))
.Returns(DateTime.UtcNow); .Returns(DateTime.UtcNow);
Mocker.GetMock<DiskProvider>()
.Setup(c => c.GetLastFileWrite(It.IsAny<String>()))
.Returns(DateTime.UtcNow);
} }
[Test] [Test]
@ -73,7 +78,7 @@ public void should_search_for_series_using_folder_name()
Subject.ProcessDropFolder("c:\\drop\\"); Subject.ProcessDropFolder("c:\\drop\\");
Mocker.GetMock<ISeriesService>().Verify(c => c.FindByTitle("foldername"), Times.Once()); Mocker.GetMock<IParsingService>().Verify(c => c.GetSeries("foldername"), Times.Once());
} }

View File

@ -53,8 +53,16 @@ public LocalEpisode GetEpisodes(string fileName, Series series)
public Series GetSeries(string title) public Series GetSeries(string title)
{ {
var searchTitle = title;
var parseResult = Parser.ParseTitle(title); var parseResult = Parser.ParseTitle(title);
return _seriesService.FindByTitle(parseResult.SeriesTitle);
if (parseResult != null)
{
searchTitle = parseResult.SeriesTitle;
}
return _seriesService.FindByTitle(searchTitle);
} }
public RemoteEpisode Map(ReportInfo indexerParseResult) public RemoteEpisode Map(ReportInfo indexerParseResult)

View File

@ -2,9 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Diagnostics;
using NLog;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
@ -17,7 +14,6 @@ public class MisnamedProvider
private readonly IEpisodeService _episodeService; private readonly IEpisodeService _episodeService;
private readonly IBuildFileNames _buildFileNames; private readonly IBuildFileNames _buildFileNames;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public MisnamedProvider(IEpisodeService episodeService, IBuildFileNames buildFileNames) public MisnamedProvider(IEpisodeService episodeService, IBuildFileNames buildFileNames)
{ {
@ -31,8 +27,6 @@ public virtual List<MisnamedEpisodeModel> MisnamedFiles(int pageNumber, int page
var episodesWithFiles = _episodeService.EpisodesWithFiles().GroupBy(e => e.EpisodeFileId).ToList(); var episodesWithFiles = _episodeService.EpisodesWithFiles().GroupBy(e => e.EpisodeFileId).ToList();
totalItems = episodesWithFiles.Count(); totalItems = episodesWithFiles.Count();
var stopwatch = new Stopwatch();
stopwatch.Start();
var misnamedFilesSelect = episodesWithFiles.AsParallel().Where( var misnamedFilesSelect = episodesWithFiles.AsParallel().Where(
w => w =>
@ -41,27 +35,27 @@ public virtual List<MisnamedEpisodeModel> MisnamedFiles(int pageNumber, int page
//Process the episodes //Process the episodes
misnamedFilesSelect.AsParallel().ForAll(f => misnamedFilesSelect.AsParallel().ForAll(f =>
{ {
var episodes = f.Select(e => e).ToList(); var episodes = f.Select(e => e).ToList();
var firstEpisode = episodes[0]; var firstEpisode = episodes[0];
var properName = _buildFileNames.BuildFilename(episodes, firstEpisode.Series, firstEpisode.EpisodeFile); var properName = _buildFileNames.BuildFilename(episodes, firstEpisode.Series,
firstEpisode.EpisodeFile);
var currentName = Path.GetFileNameWithoutExtension(firstEpisode.EpisodeFile.Path); var currentName = Path.GetFileNameWithoutExtension(firstEpisode.EpisodeFile.Path);
if (properName != currentName) if (properName != currentName)
{ {
misnamedFiles.Add(new MisnamedEpisodeModel misnamedFiles.Add(new MisnamedEpisodeModel
{ {
CurrentName = currentName, CurrentName = currentName,
EpisodeFileId = firstEpisode.EpisodeFileId, EpisodeFileId = firstEpisode.EpisodeFileId,
ProperName = properName, ProperName = properName,
SeriesId = firstEpisode.SeriesId, SeriesId = firstEpisode.SeriesId,
SeriesTitle = firstEpisode.Series.Title SeriesTitle = firstEpisode.Series.Title
}); });
} }
}); });
stopwatch.Stop();
return misnamedFiles.OrderBy(e => e.SeriesTitle).ToList(); return misnamedFiles.OrderBy(e => e.SeriesTitle).ToList();
} }
} }

View File

@ -95,7 +95,7 @@ public void should_kill_nzbdrone_process_if_running()
var proccesses = Builder<ProcessInfo>.CreateListOfSize(2).Build().ToList(); var proccesses = Builder<ProcessInfo>.CreateListOfSize(2).Build().ToList();
Mocker.GetMock<ProcessProvider>() Mocker.GetMock<ProcessProvider>()
.Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProccessName)) .Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProcessName))
.Returns(proccesses); .Returns(proccesses);
@ -110,7 +110,7 @@ public void should_kill_nzbdrone_process_if_running()
public void should_not_kill_nzbdrone_process_not_running() public void should_not_kill_nzbdrone_process_not_running()
{ {
Mocker.GetMock<ProcessProvider>() Mocker.GetMock<ProcessProvider>()
.Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProccessName)) .Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProcessName))
.Returns(new List<ProcessInfo>()); .Returns(new List<ProcessInfo>());

View File

@ -65,13 +65,13 @@ public virtual void Start(string targetFolder)
//TODO:Should be able to restart service if anything beyond this point fails //TODO:Should be able to restart service if anything beyond this point fails
logger.Info("Killing all running processes"); logger.Info("Killing all running processes");
var processes = _processProvider.GetProcessByName(ProcessProvider.NzbDroneProccessName); var processes = _processProvider.GetProcessByName(ProcessProvider.NzbDroneProcessName);
foreach (var processInfo in processes) foreach (var processInfo in processes)
{ {
_processProvider.Kill(processInfo.Id); _processProvider.Kill(processInfo.Id);
} }
var consoleProcesses = _processProvider.GetProcessByName(ProcessProvider.NzbDroneConsoleProccessName); var consoleProcesses = _processProvider.GetProcessByName(ProcessProvider.NzbDroneConsoleProcessName);
foreach (var processInfo in consoleProcesses) foreach (var processInfo in consoleProcesses)
{ {
appType = AppType.Console; appType = AppType.Console;