|
|
|
@ -20,36 +20,36 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
private const string TARGET_FOLDER = @"C:\NzbDrone\";
|
|
|
|
|
private const string UPDATE_LOG_FOLDER = @"C:\NzbDrone\UpdateLogs\";
|
|
|
|
|
|
|
|
|
|
Mock<EnvironmentProvider> _environmentProvider;
|
|
|
|
|
Mock<IEnvironmentProvider> _environmentProvider;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
_environmentProvider = Mocker.GetMock<EnvironmentProvider>();
|
|
|
|
|
_environmentProvider = Mocker.GetMock<IEnvironmentProvider>();
|
|
|
|
|
|
|
|
|
|
_environmentProvider.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\");
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.FolderExists(UPDATE_FOLDER))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.FolderExists(TARGET_FOLDER))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithInstalledService()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<ServiceProvider>()
|
|
|
|
|
Mocker.GetMock<IServiceProvider>()
|
|
|
|
|
.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithServiceRunning(bool state)
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<ServiceProvider>()
|
|
|
|
|
Mocker.GetMock<IServiceProvider>()
|
|
|
|
|
.Setup(c => c.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -63,7 +63,7 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
|
|
|
|
Mocker.GetMock<IServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
@ -76,7 +76,7 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Never());
|
|
|
|
|
Mocker.GetMock<IServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
@ -86,7 +86,7 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(It.IsAny<string>()), Times.Never());
|
|
|
|
|
Mocker.GetMock<IServiceProvider>().Verify(c => c.Stop(It.IsAny<string>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
@ -94,7 +94,7 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
{
|
|
|
|
|
var proccesses = Builder<ProcessInfo>.CreateListOfSize(2).Build().ToList();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ProcessProvider>()
|
|
|
|
|
Mocker.GetMock<IProcessProvider>()
|
|
|
|
|
.Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProcessName))
|
|
|
|
|
.Returns(proccesses);
|
|
|
|
|
|
|
|
|
@ -102,13 +102,13 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ProcessProvider>().Verify(c => c.KillAll(ProcessProvider.NzbDroneProcessName), Times.Once());
|
|
|
|
|
Mocker.GetMock<IProcessProvider>().Verify(c => c.KillAll(ProcessProvider.NzbDroneProcessName), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_kill_nzbdrone_process_not_running()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<ProcessProvider>()
|
|
|
|
|
Mocker.GetMock<IProcessProvider>()
|
|
|
|
|
.Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProcessName))
|
|
|
|
|
.Returns(new List<ProcessInfo>());
|
|
|
|
|
|
|
|
|
@ -116,13 +116,13 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ProcessProvider>().Verify(c => c.Kill(It.IsAny<int>()), Times.Never());
|
|
|
|
|
Mocker.GetMock<IProcessProvider>().Verify(c => c.Kill(It.IsAny<int>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_create_backup_of_current_installation()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.CopyDirectory(TARGET_FOLDER, BACKUP_FOLDER));
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
|
|
|
@ -131,10 +131,10 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_copy_update_package_to_target()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.DeleteFolder(UPDATE_FOLDER, true));
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
|
|
|
@ -143,7 +143,7 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_restore_if_update_fails()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER))
|
|
|
|
|
.Throws(new IOException());
|
|
|
|
|
|
|
|
|
@ -151,7 +151,7 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Verify(c => c.CopyDirectory(BACKUP_FOLDER, TARGET_FOLDER), Times.Once());
|
|
|
|
|
ExceptionVerification.ExpectedFatals(1);
|
|
|
|
|
}
|
|
|
|
@ -188,7 +188,7 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
WithInstalledService();
|
|
|
|
|
WithServiceRunning(true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER))
|
|
|
|
|
.Throws(new IOException());
|
|
|
|
|
|
|
|
|
@ -206,7 +206,7 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
WithInstalledService();
|
|
|
|
|
WithServiceRunning(false);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER))
|
|
|
|
|
.Throws(new IOException());
|
|
|
|
|
|
|
|
|
@ -220,19 +220,19 @@ namespace NzbDrone.Update.Test
|
|
|
|
|
|
|
|
|
|
private void VerifyServiceRestart()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<ServiceProvider>()
|
|
|
|
|
Mocker.GetMock<IServiceProvider>()
|
|
|
|
|
.Verify(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ProcessProvider>()
|
|
|
|
|
Mocker.GetMock<IProcessProvider>()
|
|
|
|
|
.Verify(c => c.Start(It.IsAny<string>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VerifyProcessRestart()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<ServiceProvider>()
|
|
|
|
|
Mocker.GetMock<IServiceProvider>()
|
|
|
|
|
.Verify(c => c.Start(It.IsAny<string>()), Times.Never());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ProcessProvider>()
|
|
|
|
|
Mocker.GetMock<IProcessProvider>()
|
|
|
|
|
.Verify(c => c.Start(TARGET_FOLDER + "NzbDrone.exe"), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|