mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-01-17 10:45:49 +02:00
added ApplicationUpdateCommand
This commit is contained in:
parent
02fe3f9f5a
commit
ecce355ebf
@ -8,6 +8,7 @@
|
||||
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 @@ public void should_delete_sandbox_before_update_if_folder_exists()
|
||||
{
|
||||
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 @@ public void should_not_delete_sandbox_before_update_if_folder_doesnt_exists()
|
||||
{
|
||||
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 @@ public void Should_download_update_package()
|
||||
{
|
||||
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 @@ public void Should_extract_update_package()
|
||||
{
|
||||
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 @@ public void Should_copy_update_client_to_root_of_sandbox()
|
||||
{
|
||||
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 @@ public void should_start_update_client()
|
||||
|
||||
|
||||
|
||||
Subject.InstallAvailableUpdate();
|
||||
Subject.Execute(new CheckForUpdateCommand());
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<IProcessProvider>().Verify(
|
||||
@ -115,7 +121,8 @@ public void when_no_updates_are_available_should_return_without_error_or_warning
|
||||
{
|
||||
Mocker.GetMock<IUpdatePackageProvider>().Setup(c => c.GetLatestUpdate()).Returns<UpdatePackage>(null);
|
||||
|
||||
Subject.InstallAvailableUpdate();
|
||||
Subject.Execute(new CheckForUpdateCommand());
|
||||
|
||||
|
||||
ExceptionVerification.AssertNoUnexcpectedLogs();
|
||||
}
|
||||
@ -133,7 +140,8 @@ public void Should_download_and_extract_to_temp_folder()
|
||||
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" />
|
||||
|
8
NzbDrone.Core/Update/Commands/CheckForUpdateCommand.cs
Normal file
8
NzbDrone.Core/Update/Commands/CheckForUpdateCommand.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Core.Update.Commands
|
||||
{
|
||||
public class CheckForUpdateCommand : ICommand
|
||||
{
|
||||
}
|
||||
}
|
@ -6,18 +6,19 @@
|
||||
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 UpdateService(IUpdatePackageProvider updatePackageProvider, IEnvironmentP
|
||||
_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 Dictionary<DateTime, string> GetUpdateLogFiles()
|
||||
|
||||
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…
Reference in New Issue
Block a user