fixed broken tests

pull/3113/head
kay.one 12 years ago
parent 4c810ca607
commit c59fe4e674

@ -7,7 +7,7 @@ namespace NzbDrone.Api.SignalR
public class Serializer : IJsonSerializer public class Serializer : IJsonSerializer
{ {
private readonly Common.IJsonSerializer _nzbDroneSerializer; private readonly Common.IJsonSerializer _nzbDroneSerializer;
private JsonNetSerializer _signalRSerializer; private readonly JsonNetSerializer _signalRSerializer;
public Serializer(Common.IJsonSerializer nzbDroneSerializer) public Serializer(Common.IJsonSerializer nzbDroneSerializer)
{ {

@ -11,16 +11,13 @@ using NzbDrone.Test.Dummy;
namespace NzbDrone.Common.Test namespace NzbDrone.Common.Test
{ {
[TestFixture] [TestFixture]
public class ProcessProviderTests : TestBase public class ProcessProviderTests : TestBase<ProcessProvider>
{ {
ProcessProvider _processProvider;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill()); Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill());
_processProvider = new ProcessProvider();
} }
[TearDown] [TearDown]
@ -33,14 +30,14 @@ namespace NzbDrone.Common.Test
[TestCase(123332324)] [TestCase(123332324)]
public void Kill_should_not_fail_on_invalid_process_is(int processId) public void Kill_should_not_fail_on_invalid_process_is(int processId)
{ {
_processProvider.Kill(processId); Subject.Kill(processId);
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }
[Test] [Test]
public void GetById_should_return_null_if_process_doesnt_exist() public void GetById_should_return_null_if_process_doesnt_exist()
{ {
_processProvider.GetProcessById(1234567).Should().BeNull(); Subject.GetProcessById(1234567).Should().BeNull();
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }
@ -50,7 +47,7 @@ namespace NzbDrone.Common.Test
[TestCase(9999)] [TestCase(9999)]
public void GetProcessById_should_return_null_for_invalid_process(int processId) public void GetProcessById_should_return_null_for_invalid_process(int processId)
{ {
_processProvider.GetProcessById(processId).Should().BeNull(); Subject.GetProcessById(processId).Should().BeNull();
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }
@ -59,7 +56,7 @@ namespace NzbDrone.Common.Test
public void Should_be_able_to_kill_procces() public void Should_be_able_to_kill_procces()
{ {
var dummyProcess = StartDummyProcess(); var dummyProcess = StartDummyProcess();
_processProvider.Kill(dummyProcess.Id); Subject.Kill(dummyProcess.Id);
dummyProcess.HasExited.Should().BeTrue(); dummyProcess.HasExited.Should().BeTrue();
} }
@ -69,18 +66,30 @@ namespace NzbDrone.Common.Test
var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe"); 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"); .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"); .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() public Process StartDummyProcess()
{ {
var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe"); var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
return _processProvider.Start(startInfo); return Subject.Start(startInfo);
} }
[Test] [Test]

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using NLog; 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);
}
} }
} }
} }

@ -108,7 +108,6 @@ namespace NzbDrone.Core.Test.Datastore
{ {
Name = "Address", Name = "Address",
Interval = 12 Interval = 12
}; };
Subject.Insert(childModel); Subject.Insert(childModel);
@ -118,8 +117,7 @@ namespace NzbDrone.Core.Test.Datastore
Subject.SetFields(childModel, t => t.Name); Subject.SetFields(childModel, t => t.Name);
Db.All<JobDefinition>().Single().Name.Should().Be("Address"); Db.All<JobDefinition>().Single().Name.Should().Be("A");
Db.All<JobDefinition>().Single().Name.Should().Be("B");
Db.All<JobDefinition>().Single().Interval.Should().Be(12); Db.All<JobDefinition>().Single().Interval.Should().Be(12);
} }

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using NLog; using NLog;
using Newtonsoft.Json; using Newtonsoft.Json;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -24,7 +25,7 @@ namespace NzbDrone.Core.Indexers.Nzbx
var jsonReader = new JsonTextReader(new StreamReader(source)); var jsonReader = new JsonTextReader(new StreamReader(source));
var feed = _serializer.Deserialize<List<NzbxRecentItem>>(jsonReader); var feed = _serializer.Deserialize<List<NzbxRecentItem>>(jsonReader);
foreach (var item in feed) foreach (var item in feed.Where(c => !string.IsNullOrWhiteSpace(c.Name)))
{ {
try try
{ {

@ -102,8 +102,7 @@ namespace NzbDrone.Update.Test
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER); Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
Mocker.GetMock<ProcessProvider>().Verify(c => c.Kill(proccesses[0].Id), Times.Once()); Mocker.GetMock<ProcessProvider>().Verify(c => c.KillAll(ProcessProvider.NzbDroneProcessName), Times.Once());
Mocker.GetMock<ProcessProvider>().Verify(c => c.Kill(proccesses[1].Id), Times.Once());
} }
[Test] [Test]

@ -1,6 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
@ -63,21 +62,9 @@ namespace NzbDrone.Update.Providers
//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.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(ProcessProvider.NzbDroneConsoleProcessName);
_processProvider.KillAll("NzbDrone"); _processProvider.KillAll(ProcessProvider.NzbDroneProcessName);
logger.Info("Creating backup of existing installation"); logger.Info("Creating backup of existing installation");
_diskProvider.CopyDirectory(targetFolder, _environmentProvider.GetUpdateBackUpFolder()); _diskProvider.CopyDirectory(targetFolder, _environmentProvider.GetUpdateBackUpFolder());

Loading…
Cancel
Save