From 88f4d15fa947a5ac2509eb079ad0b2945bc748b4 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 17:27:11 -0800 Subject: [PATCH] Added some update tests --- NzbDrone.App.Test/NzbDrone.App.Test.csproj | 1 + .../NzbDrone.Common.Test.csproj | 1 + NzbDrone.Common.Test/PathExtentionFixture.cs | 27 +++++++++++++++++++ NzbDrone.Common/PathExtentions.cs | 8 +++++- .../PreformUpdateFixture.cs | 15 ++++++++++- NzbDrone.Core/Providers/UpdateProvider.cs | 9 +++++-- .../NzbDrone.Test.Common.csproj | 1 + 7 files changed, 58 insertions(+), 4 deletions(-) diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index 7fe0e878b..4bb247286 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -30,6 +30,7 @@ TRACE prompt 4 + x86 diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index d979c397e..2b5a0dfda 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -30,6 +30,7 @@ TRACE prompt 4 + x86 diff --git a/NzbDrone.Common.Test/PathExtentionFixture.cs b/NzbDrone.Common.Test/PathExtentionFixture.cs index c1d5abb4d..7924da49a 100644 --- a/NzbDrone.Common.Test/PathExtentionFixture.cs +++ b/NzbDrone.Common.Test/PathExtentionFixture.cs @@ -13,8 +13,11 @@ namespace NzbDrone.Common.Test private EnviromentProvider GetEnviromentProvider() { var envMoq = new Mock(); + envMoq.SetupGet(c => c.ApplicationPath).Returns(@"C:\NzbDrone\"); + envMoq.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\"); + return envMoq.Object; } @@ -49,5 +52,29 @@ namespace NzbDrone.Common.Test { GetEnviromentProvider().GetNlogConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\log.config"); } + + [Test] + public void Sanbox() + { + GetEnviromentProvider().GetUpdateSandboxFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\"); + } + + [Test] + public void GetUpdatePackageFolder() + { + GetEnviromentProvider().GetUpdatePackageFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\"); + } + + [Test] + public void GetUpdateClientFolder() + { + GetEnviromentProvider().GetUpdateClientFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\"); + } + + [Test] + public void GetUpdateClientExePath() + { + GetEnviromentProvider().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\NzbDrone.Update.exe"); + } } } diff --git a/NzbDrone.Common/PathExtentions.cs b/NzbDrone.Common/PathExtentions.cs index 6a1071097..49f2d46a6 100644 --- a/NzbDrone.Common/PathExtentions.cs +++ b/NzbDrone.Common/PathExtentions.cs @@ -20,6 +20,7 @@ namespace NzbDrone.Common private const string UPDATE_PACKAGE_FOLDER_NAME = "nzbdrone\\"; private const string UPDATE_BACKUP_FOLDER_NAME = "nzbdrone_backup\\"; private const string UPDATE_CLIENT_EXE = "nzbdrone.update.exe"; + private const string UPDATE_CLIENT_FOLDER_NAME = "NzbDrone.Update\\"; public static string GetIISFolder(this EnviromentProvider enviromentProvider) { @@ -91,9 +92,14 @@ namespace NzbDrone.Common return Path.Combine(enviromentProvider.GetUpdateSandboxFolder(), UPDATE_PACKAGE_FOLDER_NAME); } + public static string GetUpdateClientFolder(this EnviromentProvider enviromentProvider) + { + return Path.Combine(enviromentProvider.GetUpdatePackageFolder(), UPDATE_CLIENT_FOLDER_NAME); + } + public static string GetUpdateClientExePath(this EnviromentProvider enviromentProvider) { - return Path.Combine(enviromentProvider.GetUpdateSandboxFolder(), UPDATE_CLIENT_EXE); + return Path.Combine(enviromentProvider.GetUpdateClientFolder(), UPDATE_CLIENT_EXE); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs index bdb668443..9e23e3c29 100644 --- a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs @@ -50,7 +50,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests } [Test] - public void Should_call_download_and_extract_using_correct_arguments() + public void Should_extract_update_package() { var updateArchive = Path.Combine(SANDBOX_FOLDER, updatePackage.FileName); @@ -62,6 +62,19 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests c => c.ExtractArchive(updateArchive, SANDBOX_FOLDER)); } + [Test] + public void Should_copy_update_client_to_root_of_sandbox() + { + var updateClientFolder = Mocker.GetMock().Object.GetUpdateClientFolder(); + + //Act + Mocker.Resolve().StartUpgrade(updatePackage); + + //Assert + Mocker.GetMock().Verify( + c => c.CopyDirectory(updateClientFolder, SANDBOX_FOLDER)); + } + [Test] public void should_start_update_client() { diff --git a/NzbDrone.Core/Providers/UpdateProvider.cs b/NzbDrone.Core/Providers/UpdateProvider.cs index 0af33a383..f2d6b66a0 100644 --- a/NzbDrone.Core/Providers/UpdateProvider.cs +++ b/NzbDrone.Core/Providers/UpdateProvider.cs @@ -21,6 +21,7 @@ namespace NzbDrone.Core.Providers private readonly EnviromentProvider _enviromentProvider; private readonly ArchiveProvider _archiveProvider; private readonly ProcessProvider _processProvider; + private readonly DiskProvider _diskProvider; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Regex parseRegex = new Regex(@"(?:\>)(?NzbDrone.+?(?\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase); @@ -29,7 +30,7 @@ namespace NzbDrone.Core.Providers [Inject] public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, ConfigFileProvider configFileProvider, - EnviromentProvider enviromentProvider, ArchiveProvider archiveProvider, ProcessProvider processProvider) + EnviromentProvider enviromentProvider, ArchiveProvider archiveProvider, ProcessProvider processProvider, DiskProvider diskProvider) { _httpProvider = httpProvider; _configProvider = configProvider; @@ -37,6 +38,7 @@ namespace NzbDrone.Core.Providers _enviromentProvider = enviromentProvider; _archiveProvider = archiveProvider; _processProvider = processProvider; + _diskProvider = diskProvider; } public UpdateProvider() @@ -88,8 +90,11 @@ namespace NzbDrone.Core.Providers _archiveProvider.ExtractArchive(packageDestination, _enviromentProvider.GetUpdateSandboxFolder()); logger.Info("Update package extracted successfully"); - logger.Info("Starting update client"); + logger.Info("Preparing client"); + _diskProvider.CopyDirectory(_enviromentProvider.GetUpdateClientFolder(), _enviromentProvider.GetUpdateSandboxFolder()); + + logger.Info("Starting update client"); var startInfo = new ProcessStartInfo() { FileName = _enviromentProvider.GetUpdateClientExePath(), diff --git a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj index 71cdb191b..60777f58a 100644 --- a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj +++ b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj @@ -30,6 +30,7 @@ TRACE prompt 4 + x86