2011-10-23 23:35:16 +03:00
|
|
|
using AutoMoq;
|
2011-10-23 21:31:17 +03:00
|
|
|
using FizzWare.NBuilder;
|
2011-10-23 08:26:43 +03:00
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Common;
|
2011-10-23 21:31:17 +03:00
|
|
|
using NzbDrone.Common.Model;
|
2011-10-23 08:26:43 +03:00
|
|
|
using NzbDrone.Update.Providers;
|
|
|
|
|
|
|
|
namespace NzbDrone.Update.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2011-10-23 21:31:17 +03:00
|
|
|
class UpdateProviderStartTest
|
2011-10-23 08:26:43 +03:00
|
|
|
{
|
|
|
|
AutoMoqer mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
mocker = new AutoMoqer();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2011-10-23 21:31:17 +03:00
|
|
|
public void should_stop_nzbdrone_service_if_installed()
|
2011-10-23 08:26:43 +03:00
|
|
|
{
|
2011-10-23 21:31:17 +03:00
|
|
|
mocker.GetMock<ServiceProvider>()
|
2011-10-26 20:15:47 +03:00
|
|
|
.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
2011-10-23 21:31:17 +03:00
|
|
|
.Returns(true);
|
2011-10-23 08:26:43 +03:00
|
|
|
|
|
|
|
//Act
|
2011-10-23 21:31:17 +03:00
|
|
|
mocker.Resolve<UpdateProvider>().Start(null);
|
2011-10-23 08:26:43 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-10-26 20:15:47 +03:00
|
|
|
mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
2011-10-23 08:26:43 +03:00
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2011-10-23 21:31:17 +03:00
|
|
|
public void should_kill_nzbdrone_process_if_running()
|
2011-10-23 08:26:43 +03:00
|
|
|
{
|
2011-10-23 21:31:17 +03:00
|
|
|
var proccesses = Builder<ProcessInfo>.CreateListOfSize(2).Build();
|
|
|
|
|
|
|
|
mocker.GetMock<ProcessProvider>()
|
|
|
|
.Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProccessName))
|
|
|
|
.Returns(proccesses);
|
2011-10-23 08:26:43 +03:00
|
|
|
|
|
|
|
//Act
|
2011-10-23 21:31:17 +03:00
|
|
|
mocker.Resolve<UpdateProvider>().Start(null);
|
2011-10-23 08:26:43 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-10-23 21:31:17 +03:00
|
|
|
mocker.GetMock<ProcessProvider>().Verify(c => c.Kill(proccesses[0].Id), Times.Once());
|
|
|
|
mocker.GetMock<ProcessProvider>().Verify(c => c.Kill(proccesses[1].Id), Times.Once());
|
2011-10-23 08:26:43 +03:00
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|