From c59fe4e67436f6d92ebeb6f076ee70fe7fd39a97 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 6 May 2013 22:38:40 -0700 Subject: [PATCH] fixed broken tests --- NzbDrone.Api/SignalR/Serializer.cs | 2 +- NzbDrone.Common.Test/ProcessProviderTests.cs | 35 ++++++++++++------- NzbDrone.Common/ProcessProvider.cs | 12 +++++-- .../Datastore/ObjectDatabaseFixture.cs | 4 +-- NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs | 3 +- .../UpdateProviderStartFixture.cs | 5 ++- NzbDrone.Update/Providers/UpdateProvider.cs | 17 ++------- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/NzbDrone.Api/SignalR/Serializer.cs b/NzbDrone.Api/SignalR/Serializer.cs index b2b853c24..2196a92de 100644 --- a/NzbDrone.Api/SignalR/Serializer.cs +++ b/NzbDrone.Api/SignalR/Serializer.cs @@ -7,7 +7,7 @@ namespace NzbDrone.Api.SignalR public class Serializer : IJsonSerializer { private readonly Common.IJsonSerializer _nzbDroneSerializer; - private JsonNetSerializer _signalRSerializer; + private readonly JsonNetSerializer _signalRSerializer; public Serializer(Common.IJsonSerializer nzbDroneSerializer) { diff --git a/NzbDrone.Common.Test/ProcessProviderTests.cs b/NzbDrone.Common.Test/ProcessProviderTests.cs index 8b2c3dc9c..ae2a659bb 100644 --- a/NzbDrone.Common.Test/ProcessProviderTests.cs +++ b/NzbDrone.Common.Test/ProcessProviderTests.cs @@ -11,16 +11,13 @@ using NzbDrone.Test.Dummy; namespace NzbDrone.Common.Test { [TestFixture] - public class ProcessProviderTests : TestBase + public class ProcessProviderTests : TestBase { - ProcessProvider _processProvider; - [SetUp] public void Setup() { Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill()); - _processProvider = new ProcessProvider(); } [TearDown] @@ -33,14 +30,14 @@ namespace NzbDrone.Common.Test [TestCase(123332324)] public void Kill_should_not_fail_on_invalid_process_is(int processId) { - _processProvider.Kill(processId); + Subject.Kill(processId); ExceptionVerification.ExpectedWarns(1); } [Test] public void GetById_should_return_null_if_process_doesnt_exist() { - _processProvider.GetProcessById(1234567).Should().BeNull(); + Subject.GetProcessById(1234567).Should().BeNull(); ExceptionVerification.ExpectedWarns(1); } @@ -50,7 +47,7 @@ namespace NzbDrone.Common.Test [TestCase(9999)] public void GetProcessById_should_return_null_for_invalid_process(int processId) { - _processProvider.GetProcessById(processId).Should().BeNull(); + Subject.GetProcessById(processId).Should().BeNull(); ExceptionVerification.ExpectedWarns(1); } @@ -59,7 +56,7 @@ namespace NzbDrone.Common.Test public void Should_be_able_to_kill_procces() { var dummyProcess = StartDummyProcess(); - _processProvider.Kill(dummyProcess.Id); + Subject.Kill(dummyProcess.Id); dummyProcess.HasExited.Should().BeTrue(); } @@ -68,19 +65,31 @@ namespace NzbDrone.Common.Test { var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe"); - - _processProvider.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should() + + Subject.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should() .BeEmpty("Dummy process is already running"); - _processProvider.Start(startInfo).Should().NotBeNull(); + Subject.Start(startInfo).Should().NotBeNull(); - _processProvider.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should() + Subject.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should() .HaveCount(1, "excepted one dummy process to be already running"); } + [Test] + public void kill_all_should_kill_all_process_with_name() + { + var dummy1 = StartDummyProcess(); + var dummy2 = StartDummyProcess(); + + Subject.KillAll(dummy1.ProcessName); + + dummy1.HasExited.Should().BeTrue(); + dummy2.HasExited.Should().BeTrue(); + } + public Process StartDummyProcess() { var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe"); - return _processProvider.Start(startInfo); + return Subject.Start(startInfo); } [Test] diff --git a/NzbDrone.Common/ProcessProvider.cs b/NzbDrone.Common/ProcessProvider.cs index 7ae01bcee..b2b38afe0 100644 --- a/NzbDrone.Common/ProcessProvider.cs +++ b/NzbDrone.Common/ProcessProvider.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using NLog; @@ -111,9 +112,14 @@ namespace NzbDrone.Common }; } - public void KillAll(string nzbdrone) + public virtual void KillAll(string processName) { - throw new System.NotImplementedException(); + var processToKill = GetProcessByName(processName); + + foreach (var processInfo in processToKill) + { + Kill(processInfo.Id); + } } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index c991a3860..7be8b7bd2 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -108,7 +108,6 @@ namespace NzbDrone.Core.Test.Datastore { Name = "Address", Interval = 12 - }; Subject.Insert(childModel); @@ -118,8 +117,7 @@ namespace NzbDrone.Core.Test.Datastore Subject.SetFields(childModel, t => t.Name); - Db.All().Single().Name.Should().Be("Address"); - Db.All().Single().Name.Should().Be("B"); + Db.All().Single().Name.Should().Be("A"); Db.All().Single().Interval.Should().Be(12); } diff --git a/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs b/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs index 4514c0865..4a80fbdc1 100644 --- a/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs +++ b/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using NLog; using Newtonsoft.Json; using NzbDrone.Core.Parser.Model; @@ -24,7 +25,7 @@ namespace NzbDrone.Core.Indexers.Nzbx var jsonReader = new JsonTextReader(new StreamReader(source)); var feed = _serializer.Deserialize>(jsonReader); - foreach (var item in feed) + foreach (var item in feed.Where(c => !string.IsNullOrWhiteSpace(c.Name))) { try { diff --git a/NzbDrone.Update.Test/UpdateProviderStartFixture.cs b/NzbDrone.Update.Test/UpdateProviderStartFixture.cs index 1ac8ad4a6..0c280b579 100644 --- a/NzbDrone.Update.Test/UpdateProviderStartFixture.cs +++ b/NzbDrone.Update.Test/UpdateProviderStartFixture.cs @@ -101,9 +101,8 @@ namespace NzbDrone.Update.Test Mocker.Resolve().Start(TARGET_FOLDER); - - Mocker.GetMock().Verify(c => c.Kill(proccesses[0].Id), Times.Once()); - Mocker.GetMock().Verify(c => c.Kill(proccesses[1].Id), Times.Once()); + + Mocker.GetMock().Verify(c => c.KillAll(ProcessProvider.NzbDroneProcessName), Times.Once()); } [Test] diff --git a/NzbDrone.Update/Providers/UpdateProvider.cs b/NzbDrone.Update/Providers/UpdateProvider.cs index 16520130b..d73fe8d48 100644 --- a/NzbDrone.Update/Providers/UpdateProvider.cs +++ b/NzbDrone.Update/Providers/UpdateProvider.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Linq; using NLog; using NzbDrone.Common; @@ -63,21 +62,9 @@ namespace NzbDrone.Update.Providers //TODO:Should be able to restart service if anything beyond this point fails logger.Info("Killing all running processes"); - var processes = _processProvider.GetProcessByName(ProcessProvider.NzbDroneProcessName); - foreach (var processInfo in processes) - { - _processProvider.Kill(processInfo.Id); - } - - var consoleProcesses = _processProvider.GetProcessByName(ProcessProvider.NzbDroneConsoleProcessName); - foreach (var processInfo in consoleProcesses) - { - appType = AppType.Console; - _processProvider.Kill(processInfo.Id); - } - logger.Info("Killing all orphan IISExpress processes"); - _processProvider.KillAll("NzbDrone"); + _processProvider.KillAll(ProcessProvider.NzbDroneConsoleProcessName); + _processProvider.KillAll(ProcessProvider.NzbDroneProcessName); logger.Info("Creating backup of existing installation"); _diskProvider.CopyDirectory(targetFolder, _environmentProvider.GetUpdateBackUpFolder());