Added some update tests

pull/6/head
kay.one 13 years ago
parent 56a6e1372d
commit 88f4d15fa9

@ -30,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="FizzWare.NBuilder">

@ -30,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentAssertions, Version=1.6.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">

@ -13,8 +13,11 @@ namespace NzbDrone.Common.Test
private EnviromentProvider GetEnviromentProvider()
{
var envMoq = new Mock<EnviromentProvider>();
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");
}
}
}

@ -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);
}
}
}

@ -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<EnviromentProvider>().Object.GetUpdateClientFolder();
//Act
Mocker.Resolve<UpdateProvider>().StartUpgrade(updatePackage);
//Assert
Mocker.GetMock<DiskProvider>().Verify(
c => c.CopyDirectory(updateClientFolder, SANDBOX_FOLDER));
}
[Test]
public void should_start_update_client()
{

@ -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(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\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(),

@ -30,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Practices.ServiceLocation">

Loading…
Cancel
Save