From ecce355ebfa78be153e12a1935ad7b383acac5d3 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Wed, 15 May 2013 17:16:06 -0700 Subject: [PATCH] added ApplicationUpdateCommand --- .../UpdateTests/UpdateServiceFixture.cs | 24 +++++++++----- NzbDrone.Core/NzbDrone.Core.csproj | 1 + .../Update/Commands/CheckForUpdateCommand.cs | 8 +++++ NzbDrone.Core/Update/UpdateService.cs | 32 +++++++++---------- 4 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 NzbDrone.Core/Update/Commands/CheckForUpdateCommand.cs diff --git a/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs b/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs index 15feac05d..32255bfad 100644 --- a/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs +++ b/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs @@ -8,6 +8,7 @@ using NzbDrone.Common; using NzbDrone.Common.Model; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Update; +using NzbDrone.Core.Update.Commands; using NzbDrone.Test.Common; using NzbDrone.Test.Common.Categories; @@ -46,7 +47,7 @@ namespace NzbDrone.Core.Test.UpdateTests { Mocker.GetMock().Setup(c => c.FolderExists(_sandboxFolder)).Returns(true); - Subject.InstallAvailableUpdate(); + Subject.Execute(new CheckForUpdateCommand()); Mocker.GetMock().Verify(c => c.DeleteFolder(_sandboxFolder, true)); } @@ -56,7 +57,8 @@ namespace NzbDrone.Core.Test.UpdateTests { Mocker.GetMock().Setup(c => c.FolderExists(_sandboxFolder)).Returns(false); - Subject.InstallAvailableUpdate(); + Subject.Execute(new CheckForUpdateCommand()); + Mocker.GetMock().Verify(c => c.DeleteFolder(_sandboxFolder, true), Times.Never()); } @@ -67,7 +69,8 @@ namespace NzbDrone.Core.Test.UpdateTests { var updateArchive = Path.Combine(_sandboxFolder, _updatePackage.FileName); - Subject.InstallAvailableUpdate(); + Subject.Execute(new CheckForUpdateCommand()); + Mocker.GetMock().Verify(c => c.DownloadFile(_updatePackage.Url, updateArchive)); } @@ -77,7 +80,8 @@ namespace NzbDrone.Core.Test.UpdateTests { var updateArchive = Path.Combine(_sandboxFolder, _updatePackage.FileName); - Subject.InstallAvailableUpdate(); + Subject.Execute(new CheckForUpdateCommand()); + Mocker.GetMock().Verify(c => c.ExtractArchive(updateArchive, _sandboxFolder)); } @@ -87,7 +91,8 @@ namespace NzbDrone.Core.Test.UpdateTests { var updateClientFolder = Mocker.GetMock().Object.GetUpdateClientFolder(); - Subject.InstallAvailableUpdate(); + Subject.Execute(new CheckForUpdateCommand()); + Mocker.GetMock().Verify(c => c.MoveDirectory(updateClientFolder, _sandboxFolder)); @@ -100,7 +105,8 @@ namespace NzbDrone.Core.Test.UpdateTests - Subject.InstallAvailableUpdate(); + Subject.Execute(new CheckForUpdateCommand()); + Mocker.GetMock().Verify( @@ -115,7 +121,8 @@ namespace NzbDrone.Core.Test.UpdateTests { Mocker.GetMock().Setup(c => c.GetLatestUpdate()).Returns(null); - Subject.InstallAvailableUpdate(); + Subject.Execute(new CheckForUpdateCommand()); + ExceptionVerification.AssertNoUnexcpectedLogs(); } @@ -133,7 +140,8 @@ namespace NzbDrone.Core.Test.UpdateTests Mocker.Resolve(); Mocker.Resolve(); - Subject.InstallAvailableUpdate(); + Subject.Execute(new CheckForUpdateCommand()); + updateSubFolder.Refresh(); diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 7bb98795f..4e9c60820 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -505,6 +505,7 @@ + diff --git a/NzbDrone.Core/Update/Commands/CheckForUpdateCommand.cs b/NzbDrone.Core/Update/Commands/CheckForUpdateCommand.cs new file mode 100644 index 000000000..1bd99877e --- /dev/null +++ b/NzbDrone.Core/Update/Commands/CheckForUpdateCommand.cs @@ -0,0 +1,8 @@ +using NzbDrone.Common.Messaging; + +namespace NzbDrone.Core.Update.Commands +{ + public class CheckForUpdateCommand : ICommand + { + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Update/UpdateService.cs b/NzbDrone.Core/Update/UpdateService.cs index 81eca56a2..1700da773 100644 --- a/NzbDrone.Core/Update/UpdateService.cs +++ b/NzbDrone.Core/Update/UpdateService.cs @@ -6,18 +6,19 @@ using System.IO; using System.Linq; using NLog; using NzbDrone.Common; +using NzbDrone.Common.Messaging; using NzbDrone.Core.Update; +using NzbDrone.Core.Update.Commands; namespace NzbDrone.Core.Update { public interface IUpdateService { - void InstallAvailableUpdate(); Dictionary GetUpdateLogFiles(); } } -public class UpdateService : IUpdateService +public class UpdateService : IUpdateService, IExecute { private readonly IUpdatePackageProvider _updatePackageProvider; private readonly IEnvironmentProvider _environmentProvider; @@ -43,19 +44,6 @@ public class UpdateService : IUpdateService _logger = logger; } - public void InstallAvailableUpdate() - { - var latestAvailable = _updatePackageProvider.GetLatestUpdate(); - - if (latestAvailable == null || latestAvailable.Version <= _environmentProvider.Version) - { - _logger.Debug("No update available."); - return; - } - - InstallUpdate(latestAvailable); - - } private void InstallUpdate(UpdatePackage updatePackage) { @@ -108,5 +96,17 @@ public class UpdateService : IUpdateService return list; } -} + public void Execute(ApplicationUpdateCommand message) + { + var latestAvailable = _updatePackageProvider.GetLatestUpdate(); + + if (latestAvailable == null || latestAvailable.Version <= _environmentProvider.Version) + { + _logger.Debug("No update available."); + return; + } + + InstallUpdate(latestAvailable); + } +} \ No newline at end of file