added ApplicationUpdateCommand

pull/4/head
Keivan Beigi 12 years ago
parent 02fe3f9f5a
commit ecce355ebf

@ -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<IDiskProvider>().Setup(c => c.FolderExists(_sandboxFolder)).Returns(true);
Subject.InstallAvailableUpdate();
Subject.Execute(new CheckForUpdateCommand());
Mocker.GetMock<IDiskProvider>().Verify(c => c.DeleteFolder(_sandboxFolder, true));
}
@ -56,7 +57,8 @@ namespace NzbDrone.Core.Test.UpdateTests
{
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(_sandboxFolder)).Returns(false);
Subject.InstallAvailableUpdate();
Subject.Execute(new CheckForUpdateCommand());
Mocker.GetMock<IDiskProvider>().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<IHttpProvider>().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<ArchiveProvider>().Verify(c => c.ExtractArchive(updateArchive, _sandboxFolder));
}
@ -87,7 +91,8 @@ namespace NzbDrone.Core.Test.UpdateTests
{
var updateClientFolder = Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateClientFolder();
Subject.InstallAvailableUpdate();
Subject.Execute(new CheckForUpdateCommand());
Mocker.GetMock<IDiskProvider>().Verify(c => c.MoveDirectory(updateClientFolder, _sandboxFolder));
@ -100,7 +105,8 @@ namespace NzbDrone.Core.Test.UpdateTests
Subject.InstallAvailableUpdate();
Subject.Execute(new CheckForUpdateCommand());
Mocker.GetMock<IProcessProvider>().Verify(
@ -115,7 +121,8 @@ namespace NzbDrone.Core.Test.UpdateTests
{
Mocker.GetMock<IUpdatePackageProvider>().Setup(c => c.GetLatestUpdate()).Returns<UpdatePackage>(null);
Subject.InstallAvailableUpdate();
Subject.Execute(new CheckForUpdateCommand());
ExceptionVerification.AssertNoUnexcpectedLogs();
}
@ -133,7 +140,8 @@ namespace NzbDrone.Core.Test.UpdateTests
Mocker.Resolve<DiskProvider>();
Mocker.Resolve<ArchiveProvider>();
Subject.InstallAvailableUpdate();
Subject.Execute(new CheckForUpdateCommand());
updateSubFolder.Refresh();

@ -505,6 +505,7 @@
<Compile Include="Tv\Series.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tv\SeriesStatusType.cs" />
<Compile Include="Update\Commands\CheckForUpdateCommand.cs" />
<Compile Include="Update\UpdatePackageProvider.cs" />
<Compile Include="Update\UpdatePackage.cs" />
<Compile Include="Update\UpdateService.cs" />

@ -0,0 +1,8 @@
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.Update.Commands
{
public class CheckForUpdateCommand : ICommand
{
}
}

@ -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<DateTime, string> GetUpdateLogFiles();
}
}
public class UpdateService : IUpdateService
public class UpdateService : IUpdateService, IExecute<ApplicationUpdateCommand>
{
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);
}
}
Loading…
Cancel
Save