mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Sort out test projects
This commit is contained in:
12
Squirrel.sln
12
Squirrel.sln
@@ -32,7 +32,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Packaging.OSX", "s
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Deployment", "src\Squirrel.Deployment\Squirrel.Deployment.csproj", "{D19EA72C-E7AE-4A7B-924A-E7550901A49C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Integration.Tests", "test\Squirrel.Integration.Tests\Squirrel.Integration.Tests.csproj", "{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrel.Packaging.Tests", "test\Squirrel.Packaging.Tests\Squirrel.Packaging.Tests.csproj", "{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -72,10 +72,10 @@ Global
|
||||
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -83,7 +83,7 @@ Global
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{98AEB048-E27D-42F4-9440-505B7F78BAFD} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
||||
{519EAB50-47B8-425F-8B20-AB9548F220B4} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
||||
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {68CA987A-9BAB-4C75-8EEB-4596BA6BBD07}
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: InternalsVisibleTo("Squirrel.Tests, PublicKey=" + SNK.SHA1)]
|
||||
[assembly: InternalsVisibleTo("Squirrel.Integration.Tests, PublicKey=" + SNK.SHA1)]
|
||||
[assembly: InternalsVisibleTo("Squirrel.Packaging.Tests, PublicKey=" + SNK.SHA1)]
|
||||
[assembly: InternalsVisibleTo("Squirrel, PublicKey=" + SNK.SHA1)]
|
||||
[assembly: InternalsVisibleTo("Squirrel.Deployment, PublicKey=" + SNK.SHA1)]
|
||||
[assembly: InternalsVisibleTo("Squirrel.Packaging, PublicKey=" + SNK.SHA1)]
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using Squirrel.CommandLine.Commands;
|
||||
using Xunit;
|
||||
namespace Squirrel.CommandLine.Tests;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests
|
||||
{
|
||||
public abstract class BaseCommandTests<T> : TempFileTestBase
|
||||
where T : BaseCommand, new()
|
||||
{
|
||||
@@ -26,4 +23,3 @@ namespace Squirrel.CommandLine.Tests
|
||||
|
||||
protected virtual string GetRequiredDefaultOptions() => "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System.CommandLine.Parsing;
|
||||
using Squirrel.CommandLine.Commands;
|
||||
using Xunit;
|
||||
namespace Squirrel.CommandLine.Tests.Commands;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests.Commands
|
||||
{
|
||||
public abstract class GitHubCommandTests<T> : BaseCommandTests<T>
|
||||
where T : GitHubBaseCommand, new()
|
||||
{
|
||||
@@ -99,4 +95,3 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
Assert.Equal("my release", command.ReleaseName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using System.CommandLine.Parsing;
|
||||
using Squirrel.CommandLine.Commands;
|
||||
using Xunit;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests.Commands;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests.Commands
|
||||
{
|
||||
public class HttpDownloadCommandTests : BaseCommandTests<HttpDownloadCommand>
|
||||
{
|
||||
[Fact]
|
||||
@@ -46,4 +43,3 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
return $"--url \"https://clowd.squirrel.com\" ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System.CommandLine.Parsing;
|
||||
using Squirrel.CommandLine.Commands;
|
||||
using Xunit;
|
||||
namespace Squirrel.CommandLine.Tests.Commands;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests.Commands
|
||||
{
|
||||
public abstract class S3CommandTests<T> : BaseCommandTests<T>
|
||||
where T : S3BaseCommand, new()
|
||||
{
|
||||
@@ -59,7 +55,6 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
|
||||
Assert.Equal(1, parseResult.Errors.Count);
|
||||
Assert.Equal(command, parseResult.Errors[0].SymbolResult?.Symbol);
|
||||
Assert.StartsWith("At least one of the following options are required '--region' and '--endpoint'", parseResult.Errors[0].Message);
|
||||
}
|
||||
|
||||
@@ -72,7 +67,6 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
|
||||
Assert.Equal(1, parseResult.Errors.Count);
|
||||
Assert.Equal(command, parseResult.Errors[0].SymbolResult?.Symbol);
|
||||
Assert.StartsWith("Cannot use '--region' and '--endpoint' options together", parseResult.Errors[0].Message);
|
||||
}
|
||||
|
||||
@@ -122,4 +116,3 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
Assert.Equal(42, command.KeepMaxReleases);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,9 @@
|
||||
using System.CommandLine.Parsing;
|
||||
using Squirrel.CommandLine.Commands;
|
||||
using Xunit;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests.Commands;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests.Commands
|
||||
{
|
||||
public abstract class ReleaseCommandTests<T> : BaseCommandTests<T>
|
||||
where T : ReleasifyWindowsCommand, new()
|
||||
where T : WindowsReleasifyCommand, new()
|
||||
{
|
||||
[Fact]
|
||||
public void BaseUrl_WithUrl_ParsesValue()
|
||||
{
|
||||
var command = new T();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + $"--baseUrl \"https://clowd.squirrel.com\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
|
||||
Assert.Equal("https://clowd.squirrel.com/", command.BaseUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BaseUrl_WithNonHttpValue_ShowsError()
|
||||
{
|
||||
@@ -43,18 +29,6 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
Assert.StartsWith("--baseUrl must contain an absolute Uri.", parseResult.Errors[0].Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DebugSetupExe_WithFilePath_ParsesValue()
|
||||
{
|
||||
string debugExe = CreateTempFile(name: "Blah.exe").FullName;
|
||||
var command = new T();
|
||||
string cli = GetRequiredDefaultOptions() + $"--debugSetupExe \"{debugExe}\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
|
||||
Assert.Equal(debugExe, command.DebugSetupExe);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void NoDelta_BareOption_SetsFlag()
|
||||
{
|
||||
@@ -146,25 +120,11 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
{
|
||||
var command = new T();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + $"--mainExe \"MyApp1.exe\" --mainExe \"MyApp2.exe\"";
|
||||
string cli = GetRequiredDefaultOptions() + $"--mainExe \"MyApp1.exe\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
|
||||
string[]? searchPaths = command.SquirrelAwareExecutableNames;
|
||||
Assert.Equal(2, searchPaths?.Length);
|
||||
Assert.Contains("MyApp1.exe", searchPaths);
|
||||
Assert.Contains("MyApp2.exe", searchPaths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AppIcon_WithValidFile_ParsesValue()
|
||||
{
|
||||
FileInfo fileInfo = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".ico"));
|
||||
var command = new T();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + $"--appIcon \"{fileInfo.FullName}\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
|
||||
Assert.Equal(fileInfo.FullName, command.AppIcon);
|
||||
string searchPaths = command.EntryExecutableName;
|
||||
Assert.Equal("MyApp1.exe", searchPaths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -195,13 +155,13 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
}
|
||||
}
|
||||
|
||||
public class ReleasifyWindowsCommandTests : ReleaseCommandTests<ReleasifyWindowsCommand>
|
||||
public class ReleasifyWindowsCommandTests : ReleaseCommandTests<WindowsReleasifyCommand>
|
||||
{
|
||||
[Fact]
|
||||
public void Command_WithValidRequiredArguments_Parses()
|
||||
{
|
||||
FileInfo package = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".nupkg"));
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
ParseResult parseResult = command.ParseAndApply($"--package \"{package.FullName}\"");
|
||||
|
||||
@@ -213,7 +173,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
public void Package_WithoutNupkgExtension_ShowsError()
|
||||
{
|
||||
FileInfo package = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".notpkg"));
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
ParseResult parseResult = command.ParseAndApply($"--package \"{package.FullName}\"");
|
||||
|
||||
@@ -226,7 +186,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
public void Package_WithoutExistingFile_ShowsError()
|
||||
{
|
||||
string package = Path.ChangeExtension(Path.GetRandomFileName(), ".nupkg");
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
ParseResult parseResult = command.ParseAndApply($"--package \"{package}\"");
|
||||
|
||||
@@ -238,7 +198,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[Fact]
|
||||
public void SignTemplate_WithTemplate_ParsesValue()
|
||||
{
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool {{file}}\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -249,7 +209,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[Fact]
|
||||
public void SignTemplate_WithoutFileParameter_ShowsError()
|
||||
{
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool file\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -262,7 +222,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignParameters_WithParameters_ParsesValue()
|
||||
{
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signParams \"param1 param2\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -273,13 +233,12 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignParameters_WithSignTemplate_ShowsError()
|
||||
{
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool {{file}}\" --signParams \"param1 param2\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
|
||||
Assert.Equal(1, parseResult.Errors.Count);
|
||||
Assert.Equal(command, parseResult.Errors[0].SymbolResult?.Symbol);
|
||||
Assert.Contains("Cannot use", parseResult.Errors[0].Message);
|
||||
Assert.Contains("options together", parseResult.Errors[0].Message);
|
||||
}
|
||||
@@ -287,7 +246,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignSkipDll_BareOption_SetsFlag()
|
||||
{
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signSkipDll";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -298,7 +257,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignParallel_WithValue_SetsFlag()
|
||||
{
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signParallel 42";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -312,7 +271,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[InlineData(1001)]
|
||||
public void SignParallel_WithBadNumericValue_ShowsError(int value)
|
||||
{
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + $"--signParallel {value}";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -325,7 +284,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignParallel_WithNonNumericValue_ShowsError()
|
||||
{
|
||||
var command = new ReleasifyWindowsCommand();
|
||||
var command = new WindowsReleasifyCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + $"--signParallel abc";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -343,14 +302,14 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
}
|
||||
}
|
||||
|
||||
public class PackWindowsCommandTests : ReleaseCommandTests<PackWindowsCommand>
|
||||
public class PackWindowsCommandTests : ReleaseCommandTests<WindowsPackCommand>
|
||||
{
|
||||
[Fact]
|
||||
public void Command_WithValidRequiredArguments_Parses()
|
||||
{
|
||||
DirectoryInfo packDir = CreateTempDirectory();
|
||||
CreateTempFile(packDir);
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
ParseResult parseResult = command.ParseAndApply($"-u Clowd.Squirrel -v 1.2.3 -p \"{packDir.FullName}\"");
|
||||
|
||||
@@ -365,7 +324,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
{
|
||||
DirectoryInfo packDir = CreateTempDirectory();
|
||||
CreateTempFile(packDir);
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
ParseResult parseResult = command.ParseAndApply($"--packId $42@ -v 1.0.0 -p \"{packDir.FullName}\"");
|
||||
|
||||
@@ -379,7 +338,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
{
|
||||
DirectoryInfo packDir = CreateTempDirectory();
|
||||
CreateTempFile(packDir);
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
ParseResult parseResult = command.ParseAndApply($"--packTitle Clowd.Squirrel -v 1.0.0 -p \"{packDir.FullName}\"");
|
||||
|
||||
@@ -391,7 +350,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
{
|
||||
DirectoryInfo packDir = CreateTempDirectory();
|
||||
CreateTempFile(packDir);
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
ParseResult parseResult = command.ParseAndApply($"-u Clowd.Squirrel --packVersion 1.a.c -p \"{packDir.FullName}\"");
|
||||
|
||||
@@ -403,7 +362,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[Fact]
|
||||
public void PackTitle_WithTitle_ParsesValue()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--packTitle \"My Awesome Title\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -414,7 +373,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[Fact]
|
||||
public void PackAuthors_WithMultipleAuthors_ParsesValue()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--packAuthors Me,mysel,I";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -425,7 +384,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[Fact]
|
||||
public void IncludePdb_BareOption_SetsFlag()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--includePdb";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -437,7 +396,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
public void ReleaseNotes_WithExistingFile_ParsesValue()
|
||||
{
|
||||
FileInfo releaseNotes = CreateTempFile();
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + $"--releaseNotes \"{releaseNotes.FullName}\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -449,7 +408,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
public void ReleaseNotes_WithoutFile_ShowsError()
|
||||
{
|
||||
string releaseNotes = Path.GetFullPath(Path.GetRandomFileName());
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + $"--releaseNotes \"{releaseNotes}\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -463,7 +422,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[Fact]
|
||||
public void SignTemplate_WithTemplate_ParsesValue()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool {{file}}\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -474,7 +433,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[Fact]
|
||||
public void SignTemplate_WithoutFileParameter_ShowsError()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool file\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -487,7 +446,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignParameters_WithParameters_ParsesValue()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signParams \"param1 param2\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -498,13 +457,12 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignParameters_WithSignTemplate_ShowsError()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool {{file}}\" --signParams \"param1 param2\"";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
|
||||
Assert.Equal(1, parseResult.Errors.Count);
|
||||
Assert.Equal(command, parseResult.Errors[0].SymbolResult?.Symbol);
|
||||
Assert.Contains("Cannot use", parseResult.Errors[0].Message);
|
||||
Assert.Contains("options together", parseResult.Errors[0].Message);
|
||||
}
|
||||
@@ -512,7 +470,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignSkipDll_BareOption_SetsFlag()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signSkipDll";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -523,7 +481,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignParallel_WithValue_SetsFlag()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + "--signParallel 42";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -537,7 +495,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[InlineData(1001)]
|
||||
public void SignParallel_WithBadNumericValue_ShowsError(int value)
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + $"--signParallel {value}";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -550,7 +508,7 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
[WindowsOnlyFact]
|
||||
public void SignParallel_WithNonNumericValue_ShowsError()
|
||||
{
|
||||
var command = new PackWindowsCommand();
|
||||
var command = new WindowsPackCommand();
|
||||
|
||||
string cli = GetRequiredDefaultOptions() + $"--signParallel abc";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
@@ -568,4 +526,3 @@ namespace Squirrel.CommandLine.Tests.Commands
|
||||
return $"-u Clowd.Squirrel -v 1.0.0 -p \"{packDir.FullName}\" ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
test/Squirrel.CommandLine.Tests/GlobalUsings.cs
Normal file
10
test/Squirrel.CommandLine.Tests/GlobalUsings.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
global using System;
|
||||
global using System.CommandLine;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IO;
|
||||
global using System.Linq;
|
||||
global using System.Threading.Tasks;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Xunit;
|
||||
global using Xunit.Abstractions;
|
||||
global using Squirrel.Csq.Commands;
|
||||
@@ -15,7 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Squirrel.CommandLine\Squirrel.CommandLine.csproj" />
|
||||
<ProjectReference Include="..\..\src\Squirrel.Csq\Squirrel.Csq.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Xunit.Sdk;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests
|
||||
{
|
||||
namespace Squirrel.CommandLine.Tests;
|
||||
|
||||
public abstract class TempFileTestBase : IDisposable
|
||||
{
|
||||
@@ -97,4 +96,3 @@ namespace Squirrel.CommandLine.Tests
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Xunit;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests
|
||||
{
|
||||
namespace Squirrel.CommandLine.Tests;
|
||||
|
||||
public class WindowsOnlyFactAttribute : FactAttribute
|
||||
{
|
||||
public WindowsOnlyFactAttribute()
|
||||
@@ -12,4 +11,3 @@ namespace Squirrel.CommandLine.Tests
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Xunit;
|
||||
|
||||
namespace Squirrel.CommandLine.Tests
|
||||
{
|
||||
namespace Squirrel.CommandLine.Tests;
|
||||
|
||||
public class WindowsOnlyTheoryAttribute : TheoryAttribute
|
||||
{
|
||||
public WindowsOnlyTheoryAttribute()
|
||||
@@ -12,4 +11,3 @@ namespace Squirrel.CommandLine.Tests
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
347
test/Squirrel.Packaging.Tests/DeltaPackageTests.cs
Normal file
347
test/Squirrel.Packaging.Tests/DeltaPackageTests.cs
Normal file
@@ -0,0 +1,347 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.IO;
|
||||
//using System.Linq;
|
||||
//using System.Threading.Tasks;
|
||||
//using Squirrel.NuGet;
|
||||
//using Squirrel;
|
||||
//using Squirrel.SimpleSplat;
|
||||
//using Squirrel.Tests.TestHelpers;
|
||||
//using Xunit;
|
||||
//using Xunit.Abstractions;
|
||||
//using NuGet.Versioning;
|
||||
//using Squirrel.CommandLine;
|
||||
|
||||
//namespace Squirrel.Tests
|
||||
//{
|
||||
// public class ApplyDeltaPackageTests : TestLoggingBase
|
||||
// {
|
||||
// public ApplyDeltaPackageTests(ITestOutputHelper log) : base(log)
|
||||
// {
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void ApplyDeltaPackageSmokeTest()
|
||||
// {
|
||||
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0-full.nupkg");
|
||||
// var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-delta.nupkg");
|
||||
// var expectedPackageFile = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-full.nupkg");
|
||||
// var outFile = Path.GetTempFileName() + ".nupkg";
|
||||
|
||||
// try {
|
||||
// var deltaBuilder = new DeltaPackage();
|
||||
// deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
|
||||
|
||||
// var result = new ZipPackage(outFile);
|
||||
// var expected = new ZipPackage(expectedPackageFile);
|
||||
|
||||
// result.Id.ShouldEqual(expected.Id);
|
||||
// result.Version.ShouldEqual(expected.Version);
|
||||
|
||||
// this.Log().Info("Expected file list:");
|
||||
// var expectedList = expected.Files.Select(x => x.Path).OrderBy(x => x).ToList();
|
||||
// expectedList.ForEach(x => this.Log().Info(x));
|
||||
|
||||
// this.Log().Info("Actual file list:");
|
||||
// var actualList = result.Files.Select(x => x.Path).OrderBy(x => x).ToList();
|
||||
// actualList.ForEach(x => this.Log().Info(x));
|
||||
|
||||
// Enumerable.Zip(expectedList, actualList, (e, a) => e == a)
|
||||
// .All(x => x != false)
|
||||
// .ShouldBeTrue();
|
||||
// } finally {
|
||||
// if (File.Exists(outFile)) {
|
||||
// File.Delete(outFile);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void ApplyDeltaWithBothBsdiffAndNormalDiffDoesntFail()
|
||||
// {
|
||||
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.1.8-full.nupkg");
|
||||
// var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.2.0-delta.nupkg");
|
||||
// var outFile = Path.GetTempFileName() + ".nupkg";
|
||||
|
||||
// try {
|
||||
// var deltaBuilder = new DeltaPackage();
|
||||
// deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
|
||||
|
||||
// var result = new ZipPackage(outFile);
|
||||
|
||||
// result.Id.ShouldEqual("slack");
|
||||
// result.Version.ShouldEqual(SemanticVersion.Parse("1.2.0"));
|
||||
// } finally {
|
||||
// if (File.Exists(outFile)) {
|
||||
// File.Delete(outFile);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void ApplyMultipleDeltasFast()
|
||||
// {
|
||||
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.287-full.nupkg");
|
||||
// var deltaPackage1 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.288-delta.nupkg");
|
||||
// var deltaPackage2 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.291-delta.nupkg");
|
||||
// var deltaPackage3 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.292-delta.nupkg");
|
||||
|
||||
// using var t1 = Utility.GetTempDirectory(out var appDir);
|
||||
// using var t2 = Utility.GetTempDirectory(out var updateDir);
|
||||
|
||||
// using var um = UpdateManagerTestImpl.FromLocalPackageTempDir(updateDir, "theApp", appDir);
|
||||
// var pkgDir = um.Config.PackagesDir;
|
||||
|
||||
// File.Copy(basePackage, Path.Combine(pkgDir, Path.GetFileName(basePackage)));
|
||||
// File.Copy(deltaPackage1, Path.Combine(pkgDir, Path.GetFileName(deltaPackage1)));
|
||||
// File.Copy(deltaPackage2, Path.Combine(pkgDir, Path.GetFileName(deltaPackage2)));
|
||||
// File.Copy(deltaPackage3, Path.Combine(pkgDir, Path.GetFileName(deltaPackage3)));
|
||||
|
||||
// var baseEntry = ReleaseEntry.GenerateFromFile(basePackage);
|
||||
|
||||
// var toApply = new [] {
|
||||
// ReleaseEntry.GenerateFromFile(deltaPackage1),
|
||||
// ReleaseEntry.GenerateFromFile(deltaPackage2),
|
||||
// ReleaseEntry.GenerateFromFile(deltaPackage3),
|
||||
// };
|
||||
|
||||
// List<int> progress = new List<int>();
|
||||
|
||||
// var newEntry = um.createFullPackagesFromDeltas(toApply, baseEntry, progress.Add);
|
||||
|
||||
// var outFile = Path.Combine(pkgDir, newEntry.Filename);
|
||||
// var result = new ZipPackage(outFile);
|
||||
// result.Id.ShouldEqual("Clowd");
|
||||
// result.Version.ShouldEqual(SemanticVersion.Parse("3.4.292"));
|
||||
// }
|
||||
|
||||
// [Fact(Skip = "Rewrite this test, the original uses too many heavyweight fixtures")]
|
||||
// public void ApplyMultipleDeltaPackagesGeneratesCorrectHash()
|
||||
// {
|
||||
// Assert.Fail("Rewrite this test, the original uses too many heavyweight fixtures");
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class CreateDeltaPackageTests : IEnableLogger
|
||||
// {
|
||||
// [Fact]
|
||||
// public void CreateDeltaPackageIntegrationTest()
|
||||
// {
|
||||
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||
|
||||
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
// var tempFiles = Enumerable.Range(0, 3)
|
||||
// .Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||
// .ToArray();
|
||||
|
||||
// try {
|
||||
// baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||
// fixture.CreateReleasePackage(tempFiles[1]);
|
||||
|
||||
// (new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
// (new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
|
||||
// var deltaBuilder = new DeltaPackageBuilder();
|
||||
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||
|
||||
// var fullPkg = new ZipPackage(tempFiles[1]);
|
||||
// var deltaPkg = new ZipPackage(tempFiles[2]);
|
||||
|
||||
// //
|
||||
// // Package Checks
|
||||
// //
|
||||
|
||||
// fullPkg.Id.ShouldEqual(deltaPkg.Id);
|
||||
// fullPkg.Version.CompareTo(deltaPkg.Version).ShouldEqual(0);
|
||||
|
||||
// // Delta packages should be smaller than the original!
|
||||
// var fileInfos = tempFiles.Select(x => new FileInfo(x)).ToArray();
|
||||
// this.Log().Info("Base Size: {0}, Current Size: {1}, Delta Size: {2}",
|
||||
// fileInfos[0].Length, fileInfos[1].Length, fileInfos[2].Length);
|
||||
|
||||
// (fileInfos[2].Length - fileInfos[1].Length).ShouldBeLessThan(0);
|
||||
|
||||
// //
|
||||
// // File Checks
|
||||
// ///
|
||||
|
||||
// var deltaPkgFiles = deltaPkg.Files.ToList();
|
||||
// deltaPkgFiles.Count.ShouldBeGreaterThan(0);
|
||||
|
||||
// this.Log().Info("Files in delta package:");
|
||||
// deltaPkgFiles.ForEach(x => this.Log().Info(x.Path));
|
||||
|
||||
// var newFilesAdded = new[] {
|
||||
// "Newtonsoft.Json.dll",
|
||||
// //"Refit.dll",
|
||||
// //"Refit-Portable.dll",
|
||||
// //"Castle.Core.dll",
|
||||
// }.Select(x => x.ToLowerInvariant());
|
||||
|
||||
// // vNext adds a dependency on Refit
|
||||
// newFilesAdded
|
||||
// .All(x => deltaPkgFiles.Any(y => y.Path.ToLowerInvariant().Contains(x)))
|
||||
// .ShouldBeTrue();
|
||||
|
||||
// // All the other files should be diffs and shasums
|
||||
// deltaPkgFiles
|
||||
// .Where(x => !newFilesAdded.Any(y => x.Path.ToLowerInvariant().Contains(y)))
|
||||
// .All(x => x.Path.ToLowerInvariant().EndsWith("bsdiff") || x.Path.ToLowerInvariant().EndsWith("shasum"))
|
||||
// .ShouldBeTrue();
|
||||
|
||||
// // Every .diff file should have a shasum file
|
||||
// deltaPkg.Files.Any(x => x.Path.ToLowerInvariant().EndsWith(".bsdiff")).ShouldBeTrue();
|
||||
// deltaPkg.Files
|
||||
// .Where(x => x.Path.ToLowerInvariant().EndsWith(".bsdiff"))
|
||||
// .ForEach(x => {
|
||||
// var lookingFor = x.Path.Replace(".bsdiff", ".shasum");
|
||||
// this.Log().Info("Looking for corresponding shasum file: {0}", lookingFor);
|
||||
// deltaPkg.Files.Any(y => y.Path == lookingFor).ShouldBeTrue();
|
||||
// });
|
||||
// } finally {
|
||||
// tempFiles.ForEach(File.Delete);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void WhenBasePackageIsNewerThanNewPackageThrowException()
|
||||
// {
|
||||
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
|
||||
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
// var tempFiles = Enumerable.Range(0, 3)
|
||||
// .Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||
// .ToArray();
|
||||
|
||||
// try {
|
||||
// baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||
// fixture.CreateReleasePackage(tempFiles[1]);
|
||||
|
||||
// (new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
// (new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
|
||||
// Assert.Throws<InvalidOperationException>(() => {
|
||||
// var deltaBuilder = new DeltaPackageBuilder();
|
||||
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||
// });
|
||||
// } finally {
|
||||
// tempFiles.ForEach(File.Delete);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void WhenBasePackageReleaseIsNullThrowsException()
|
||||
// {
|
||||
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0.nupkg");
|
||||
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
|
||||
|
||||
// var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
|
||||
// (new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
|
||||
|
||||
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
// var tempFile = Path.GetTempPath() + Guid.NewGuid() + ".nupkg";
|
||||
|
||||
// try {
|
||||
// Assert.Throws<ArgumentException>(() => {
|
||||
// var deltaBuilder = new DeltaPackageBuilder();
|
||||
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFile);
|
||||
// });
|
||||
// } finally {
|
||||
// File.Delete(tempFile);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void WhenBasePackageDoesNotExistThrowException()
|
||||
// {
|
||||
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||
|
||||
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
// var tempFiles = Enumerable.Range(0, 3)
|
||||
// .Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||
// .ToArray();
|
||||
|
||||
// try {
|
||||
// baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||
// fixture.CreateReleasePackage(tempFiles[1]);
|
||||
|
||||
// (new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
// (new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
|
||||
// // NOW WATCH AS THE FILE DISAPPEARS
|
||||
// File.Delete(baseFixture.ReleasePackageFile);
|
||||
|
||||
// Assert.Throws<FileNotFoundException>(() => {
|
||||
// var deltaBuilder = new DeltaPackageBuilder();
|
||||
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||
// });
|
||||
// } finally {
|
||||
// tempFiles.ForEach(File.Delete);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void WhenNewPackageDoesNotExistThrowException()
|
||||
// {
|
||||
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||
|
||||
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
// var tempFiles = Enumerable.Range(0, 3)
|
||||
// .Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||
// .ToArray();
|
||||
|
||||
// try {
|
||||
// baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||
// fixture.CreateReleasePackage(tempFiles[1]);
|
||||
|
||||
// (new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
// (new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
|
||||
// // NOW WATCH AS THE FILE DISAPPEARS
|
||||
// File.Delete(fixture.ReleasePackageFile);
|
||||
|
||||
// Assert.Throws<FileNotFoundException>(() => {
|
||||
// var deltaBuilder = new DeltaPackageBuilder();
|
||||
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||
// });
|
||||
// } finally {
|
||||
// tempFiles.ForEach(File.Delete);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void HandleBsDiffWithoutExtraData()
|
||||
// {
|
||||
// var baseFileData = new byte[] { 1, 1, 1, 1 };
|
||||
// var newFileData = new byte[] { 2, 1, 1, 1 };
|
||||
|
||||
// byte[] patchData;
|
||||
|
||||
// using (var patchOut = new MemoryStream()) {
|
||||
// Bsdiff.BinaryPatchUtility.Create(baseFileData, newFileData, patchOut);
|
||||
// patchData = patchOut.ToArray();
|
||||
// }
|
||||
|
||||
// using (var toPatch = new MemoryStream(baseFileData))
|
||||
// using (var patched = new MemoryStream()) {
|
||||
// Bsdiff.BinaryPatchUtility.Apply(toPatch, () => new MemoryStream(patchData), patched);
|
||||
|
||||
// Assert.Equal(newFileData, patched.ToArray());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -4,9 +4,9 @@ using Squirrel.Packaging;
|
||||
using Xunit.Abstractions;
|
||||
using Xunit.Sdk;
|
||||
|
||||
[assembly: Xunit.TestFramework("Squirrel.Integration.Tests.TestsInit", "Squirrel.Integration.Tests")]
|
||||
[assembly: Xunit.TestFramework("Squirrel.Packaging.Tests.TestsInit", "Squirrel.Packaging.Tests")]
|
||||
|
||||
namespace Squirrel.Integration.Tests
|
||||
namespace Squirrel.Packaging.Tests
|
||||
{
|
||||
public class TestsInit : XunitTestFramework
|
||||
{
|
||||
178
test/Squirrel.Packaging.Tests/ReleasePackageTests.cs
Normal file
178
test/Squirrel.Packaging.Tests/ReleasePackageTests.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
//using System.Runtime.Versioning;
|
||||
//using Squirrel.MarkdownSharp;
|
||||
//using Squirrel;
|
||||
//using Squirrel.Tests.TestHelpers;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.IO;
|
||||
//using System.Linq;
|
||||
//using System.Reflection;
|
||||
//using System.Xml.Linq;
|
||||
//using Squirrel.SimpleSplat;
|
||||
//using Xunit;
|
||||
//using Squirrel.NuGet;
|
||||
//using Xunit.Abstractions;
|
||||
//using NuGet.Versioning;
|
||||
//using Squirrel.CommandLine;
|
||||
|
||||
//namespace Squirrel.Tests
|
||||
//{
|
||||
// public class CreateReleasePackageTests : TestLoggingBase
|
||||
// {
|
||||
// public CreateReleasePackageTests(ITestOutputHelper log) : base(log)
|
||||
// {
|
||||
// }
|
||||
|
||||
// [Theory]
|
||||
// [InlineData("1.2.3")]
|
||||
// [InlineData("1.2.3-alpha13")]
|
||||
// [InlineData("1.2.3-alpha135")]
|
||||
// [InlineData("0.0.1")]
|
||||
// [InlineData("1.299656.3-alpha")]
|
||||
// public void SemanticVersionParsesValidVersion(string ver)
|
||||
// {
|
||||
// NugetUtil.ThrowIfVersionNotSemverCompliant(ver);
|
||||
// Assert.True(SemanticVersion.TryParse(ver, out var _));
|
||||
// }
|
||||
|
||||
// [Theory]
|
||||
// [InlineData("")]
|
||||
// [InlineData("1")]
|
||||
// [InlineData("0")]
|
||||
// [InlineData("1.2.3.4")]
|
||||
// [InlineData("1.2.3.4-alpha")]
|
||||
// [InlineData("0.0.0.0")]
|
||||
// [InlineData("0.0.0")]
|
||||
// [InlineData("0.0")]
|
||||
// [InlineData("0.0.0-alpha")]
|
||||
// public void SemanticVersionThrowsInvalidVersion(string ver)
|
||||
// {
|
||||
// Assert.ThrowsAny<Exception>(() => NugetUtil.ThrowIfVersionNotSemverCompliant(ver));
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void ReleasePackageIntegrationTest()
|
||||
// {
|
||||
// var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
// var outputPackage = Path.GetTempFileName() + ".nupkg";
|
||||
|
||||
// var fixture = new ReleasePackageBuilder(inputPackage);
|
||||
|
||||
// try {
|
||||
// fixture.CreateReleasePackage(outputPackage);
|
||||
|
||||
// this.Log().Info("Resulting package is at {0}", outputPackage);
|
||||
// var pkg = new ZipPackage(outputPackage);
|
||||
|
||||
// int refs = pkg.FrameworkAssemblies.Count();
|
||||
// this.Log().Info("Found {0} refs", refs);
|
||||
// refs.ShouldEqual(0);
|
||||
|
||||
// this.Log().Info("Files in release package:");
|
||||
|
||||
// List<ZipPackageFile> files = pkg.Files.ToList();
|
||||
// files.ForEach(x => this.Log().Info(x.Path));
|
||||
|
||||
// List<string> nonDesktopPaths = new[] { "sl", "winrt", "netcore", "win8", "windows8", "MonoAndroid", "MonoTouch", "MonoMac", "wp", }
|
||||
// .Select(x => @"lib\" + x)
|
||||
// .ToList();
|
||||
|
||||
// files.Any(x => nonDesktopPaths.Any(y => x.Path.ToLowerInvariant().Contains(y.ToLowerInvariant()))).ShouldBeFalse();
|
||||
// files.Any(x => x.Path.ToLowerInvariant().EndsWith(@".xml")).ShouldBeFalse();
|
||||
// } finally {
|
||||
// File.Delete(outputPackage);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void CanLoadPackageWhichHasNoDependencies()
|
||||
// {
|
||||
// var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.NoDependencies.1.0.0.0.nupkg");
|
||||
// var outputPackage = Path.GetTempFileName() + ".nupkg";
|
||||
// var fixture = new ReleasePackageBuilder(inputPackage);
|
||||
// try {
|
||||
// fixture.CreateReleasePackage(outputPackage);
|
||||
// } finally {
|
||||
// File.Delete(outputPackage);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void ThrowsIfLoadsPackageWithDependencies()
|
||||
// {
|
||||
// var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectDependsOnJsonDotNet.1.0.nupkg");
|
||||
// var outputPackage = Path.GetTempFileName() + ".nupkg";
|
||||
// var fixture = new ReleasePackageBuilder(inputPackage);
|
||||
// try {
|
||||
// Assert.Throws<InvalidOperationException>(() => fixture.CreateReleasePackage(outputPackage));
|
||||
// } finally {
|
||||
// if (File.Exists(outputPackage))
|
||||
// File.Delete(outputPackage);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void SpecFileMarkdownRenderingTest()
|
||||
// {
|
||||
// var dontcare = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
|
||||
// var inputSpec = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nuspec");
|
||||
// var fixture = new ReleasePackageBuilder(dontcare);
|
||||
|
||||
// var targetFile = Path.GetTempFileName();
|
||||
// File.Copy(inputSpec, targetFile, true);
|
||||
|
||||
// try {
|
||||
// var processor = new Func<string, string>(input =>
|
||||
// (new Markdown()).Transform(input));
|
||||
|
||||
// // NB: For No Reason At All, renderReleaseNotesMarkdown is
|
||||
// // invulnerable to ExposedObject. Whyyyyyyyyy
|
||||
// var renderMinfo = fixture.GetType().GetMethod("renderReleaseNotesMarkdown",
|
||||
// BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
// renderMinfo.Invoke(fixture, new object[] { targetFile, processor });
|
||||
|
||||
// var mani = NuspecManifest.ParseFromFile(targetFile);
|
||||
// this.Log().Info("HTML Text:\n{0}", mani.ReleaseNotesHtml);
|
||||
|
||||
// mani.ReleaseNotes.Contains("## Release Notes").ShouldBeTrue();
|
||||
// mani.ReleaseNotesHtml.Contains("## Release Notes").ShouldBeFalse();
|
||||
// mani.ReleaseNotesHtml.Contains("<h2>Release Notes").ShouldBeTrue();
|
||||
// } finally {
|
||||
// File.Delete(targetFile);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void ContentFilesAreIncludedInCreatedPackage()
|
||||
// {
|
||||
// var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectWithContent.1.0.0.0-beta.nupkg");
|
||||
// var outputPackage = Path.GetTempFileName() + ".zip";
|
||||
// var fixture = new ReleasePackageBuilder(inputPackage);
|
||||
|
||||
// try {
|
||||
// fixture.CreateReleasePackage(outputPackage);
|
||||
|
||||
// this.Log().Info("Resulting package is at {0}", outputPackage);
|
||||
// var pkg = new ZipPackage(outputPackage);
|
||||
|
||||
// int refs = pkg.FrameworkAssemblies.Count();
|
||||
// this.Log().Info("Found {0} refs", refs);
|
||||
// refs.ShouldEqual(0);
|
||||
|
||||
// this.Log().Info("Files in release package:");
|
||||
|
||||
// var contentFiles = pkg.Files.Where(f => f.IsContentFile()).ToArray();
|
||||
// Assert.Equal(2, contentFiles.Count());
|
||||
|
||||
// var contentFilePaths = contentFiles.Select(f => f.EffectivePath);
|
||||
|
||||
// Assert.Contains("some-words.txt", contentFilePaths);
|
||||
// Assert.Contains("dir\\item-in-subdirectory.txt", contentFilePaths);
|
||||
|
||||
// Assert.Equal(1, pkg.Files.Where(f => f.IsLibFile()).Count());
|
||||
// } finally {
|
||||
// File.Delete(outputPackage);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -5,7 +5,7 @@ using Squirrel.Compression;
|
||||
using Squirrel.Packaging;
|
||||
using Squirrel.Packaging.Windows.Commands;
|
||||
|
||||
namespace Squirrel.Integration.Tests;
|
||||
namespace Squirrel.Packaging.Tests;
|
||||
|
||||
public class WindowsPackTests
|
||||
{
|
||||
@@ -1,527 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NuGet.Versioning;
|
||||
using Squirrel.NuGet;
|
||||
using Squirrel.Tests.TestHelpers;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public class ApplyReleasesTests : TestLoggingBase
|
||||
{
|
||||
public ApplyReleasesTests(ITestOutputHelper log) : base(log)
|
||||
{
|
||||
}
|
||||
|
||||
public const string APP_ID = "theFakeApp";
|
||||
|
||||
[Fact]
|
||||
public async Task CleanInstallRunsSquirrelAwareAppsWithInstallFlag()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir);
|
||||
await fixture.FullInstall();
|
||||
|
||||
// NB: We execute the Squirrel-aware apps, so we need to give
|
||||
// them a minute to settle or else the using statement will
|
||||
// try to blow away a running process
|
||||
await Task.Delay(1000);
|
||||
|
||||
Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "current", "args2.txt")));
|
||||
Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "current", "args.txt")));
|
||||
|
||||
var text = File.ReadAllText(Path.Combine(tempDir, APP_ID, "current", "args.txt"), Encoding.UTF8);
|
||||
Assert.Contains("firstrun", text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpgradeRunsSquirrelAwareAppsWithUpgradeFlag()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
await fixture.FullInstall();
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
||||
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
await fixture.UpdateApp();
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args2.txt")));
|
||||
Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args.txt")));
|
||||
|
||||
var text = File.ReadAllText(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args.txt"), Encoding.UTF8);
|
||||
Assert.Contains("updated", text);
|
||||
Assert.Contains("0.2.0", text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RunningUpgradeAppTwiceDoesntCrash()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
await fixture.FullInstall();
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
||||
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
await fixture.UpdateApp();
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
// NB: The 2nd time we won't have any updates to apply. We should just do nothing!
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
await fixture.UpdateApp();
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FullUninstallRemovesAllVersions()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
await fixture.FullInstall();
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
||||
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
await fixture.UpdateApp();
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
await fixture.FullUninstall();
|
||||
}
|
||||
|
||||
Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "app-0.1.0", "args.txt")));
|
||||
Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "app-0.2.0", "args.txt")));
|
||||
Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, ".dead")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CanInstallAndUpdatePackageWithDotsInId()
|
||||
{
|
||||
string tempDir;
|
||||
string remotePkgDir;
|
||||
const string pkgName = "Squirrel.Installed.App";
|
||||
|
||||
using (Utility.GetTempDirectory(out tempDir))
|
||||
using (Utility.GetTempDirectory(out remotePkgDir)) {
|
||||
// install 0.1.0
|
||||
IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir, "SquirrelInstalledAppWithDots.nuspec");
|
||||
var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
|
||||
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
|
||||
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
||||
await fixture.FullInstall();
|
||||
}
|
||||
|
||||
//Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "app-0.1.0")));
|
||||
Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "current")));
|
||||
|
||||
var info = new AppDescWindows(Path.Combine(tempDir, pkgName), pkgName);
|
||||
|
||||
var version = info.GetVersions().Single();
|
||||
Assert.True(version.IsCurrent);
|
||||
Assert.Equal(new SemanticVersion(0, 1, 0), version.Manifest.Version);
|
||||
|
||||
await Task.Delay(1000);
|
||||
Assert.True(File.ReadAllText(Path.Combine(version.DirectoryPath, "args.txt")).Contains("--squirrel-firstrun"));
|
||||
|
||||
// update top 0.2.0
|
||||
IntegrationTestHelper.CreateFakeInstalledApp("0.2.0", remotePkgDir, "SquirrelInstalledAppWithDots.nuspec");
|
||||
pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
|
||||
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
|
||||
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
||||
await fixture.UpdateApp();
|
||||
}
|
||||
|
||||
info.UpdateAndRetrieveCurrentFolder(false);
|
||||
|
||||
var versions = info.GetVersions().ToArray();
|
||||
Assert.Equal(2, versions.Count());
|
||||
Assert.Equal(new SemanticVersion(0, 2, 0), versions.Single(s => s.IsCurrent).Version);
|
||||
|
||||
//Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "app-0.2.0")));
|
||||
await Task.Delay(1000);
|
||||
|
||||
// uninstall
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
||||
await fixture.FullUninstall();
|
||||
}
|
||||
|
||||
Assert.False(File.Exists(Path.Combine(tempDir, pkgName, "app-0.1.0", "args.txt")));
|
||||
Assert.False(File.Exists(Path.Combine(tempDir, pkgName, "app-0.2.0", "args.txt")));
|
||||
Assert.True(File.Exists(Path.Combine(tempDir, pkgName, ".dead")));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenNoNewReleasesAreAvailableTheListIsEmpty()
|
||||
{
|
||||
using var _ = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
var appDir = Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
||||
var packages = Path.Combine(appDir.FullName, "packages");
|
||||
Directory.CreateDirectory(packages);
|
||||
|
||||
var package = "Squirrel.Core.1.0.0.0-full.nupkg";
|
||||
File.Copy(IntegrationTestHelper.GetPath("fixtures", package), Path.Combine(packages, package));
|
||||
|
||||
var aGivenPackage = Path.Combine(packages, package);
|
||||
var baseEntry = ReleaseEntry.GenerateFromFile(aGivenPackage);
|
||||
|
||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { baseEntry }, "dontcare");
|
||||
|
||||
Assert.Empty(updateInfo.ReleasesToApply);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThrowsWhenOnlyDeltaReleasesAreAvailable()
|
||||
{
|
||||
string tempDir;
|
||||
using (Utility.GetTempDirectory(out tempDir)) {
|
||||
var appDir = Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
||||
var packages = Path.Combine(appDir.FullName, "packages");
|
||||
Directory.CreateDirectory(packages);
|
||||
|
||||
var baseFile = "Squirrel.Core.1.0.0.0-full.nupkg";
|
||||
File.Copy(IntegrationTestHelper.GetPath("fixtures", baseFile),
|
||||
Path.Combine(packages, baseFile));
|
||||
var basePackage = Path.Combine(packages, baseFile);
|
||||
var baseEntry = ReleaseEntry.GenerateFromFile(basePackage);
|
||||
|
||||
var deltaFile = "Squirrel.Core.1.1.0.0-delta.nupkg";
|
||||
File.Copy(IntegrationTestHelper.GetPath("fixtures", deltaFile),
|
||||
Path.Combine(packages, deltaFile));
|
||||
var deltaPackage = Path.Combine(packages, deltaFile);
|
||||
var deltaEntry = ReleaseEntry.GenerateFromFile(deltaPackage);
|
||||
|
||||
Assert.Throws<Exception>(
|
||||
() => UpdateInfo.Create(baseEntry, new[] { deltaEntry }, "dontcare"));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ApplyReleasesWithOneReleaseFile()
|
||||
{
|
||||
string tempDir;
|
||||
|
||||
using (Utility.GetTempDirectory(out tempDir)) {
|
||||
string appDir = Path.Combine(tempDir, APP_ID);
|
||||
string packagesDir = Path.Combine(appDir, "packages");
|
||||
Directory.CreateDirectory(packagesDir);
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.0.0.0-full.nupkg"));
|
||||
var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||
|
||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
||||
updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
||||
|
||||
var progress = new List<int>();
|
||||
|
||||
await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
progress
|
||||
.Aggregate(0, (acc, x) => {
|
||||
(x >= acc).ShouldBeTrue();
|
||||
return x;
|
||||
})
|
||||
.ShouldEqual(100);
|
||||
|
||||
var filesToFind = new[] {
|
||||
new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||
new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||
};
|
||||
|
||||
filesToFind.ForEach(x => {
|
||||
var path = Path.Combine(tempDir, APP_ID, "staging", "app-1.1.0.0", x.Name);
|
||||
this.Log().Info("Looking for {0}", path);
|
||||
File.Exists(path).ShouldBeTrue();
|
||||
|
||||
var vi = FileVersionInfo.GetVersionInfo(path);
|
||||
var verInfo = new Version(vi.FileVersion ?? "1.0.0.0");
|
||||
x.Version.ShouldEqual(verInfo);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ApplyReleaseWhichRemovesAFile()
|
||||
{
|
||||
string tempDir;
|
||||
|
||||
using (Utility.GetTempDirectory(out tempDir)) {
|
||||
string appDir = Path.Combine(tempDir, APP_ID);
|
||||
string packagesDir = Path.Combine(appDir, "packages");
|
||||
Directory.CreateDirectory(packagesDir);
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.2.0.0-full.nupkg",
|
||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||
var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.2.0.0-full.nupkg"));
|
||||
|
||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
||||
updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
||||
|
||||
var progress = new List<int>();
|
||||
await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
progress
|
||||
.Aggregate(0, (acc, x) => {
|
||||
(x >= acc).ShouldBeTrue();
|
||||
return x;
|
||||
})
|
||||
.ShouldEqual(100);
|
||||
|
||||
var rootDirectory = Path.Combine(tempDir, APP_ID, "staging", "app-1.2.0.0");
|
||||
|
||||
new[] {
|
||||
new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||
new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||
}.ForEach(x => {
|
||||
var path = Path.Combine(rootDirectory, x.Name);
|
||||
this.Log().Info("Looking for {0}", path);
|
||||
File.Exists(path).ShouldBeTrue();
|
||||
});
|
||||
|
||||
var removedFile = Path.Combine("sub", "Ionic.Zip.dll");
|
||||
var deployedPath = Path.Combine(rootDirectory, removedFile);
|
||||
File.Exists(deployedPath).ShouldBeFalse();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ApplyReleaseWhichMovesAFileToADifferentDirectory()
|
||||
{
|
||||
string tempDir;
|
||||
|
||||
using (Utility.GetTempDirectory(out tempDir)) {
|
||||
string appDir = Path.Combine(tempDir, APP_ID);
|
||||
string packagesDir = Path.Combine(appDir, "packages");
|
||||
Directory.CreateDirectory(packagesDir);
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.3.0.0-full.nupkg",
|
||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||
var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.3.0.0-full.nupkg"));
|
||||
|
||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
||||
updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
||||
|
||||
var progress = new List<int>();
|
||||
await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
progress
|
||||
.Aggregate(0, (acc, x) => {
|
||||
(x >= acc).ShouldBeTrue();
|
||||
return x;
|
||||
})
|
||||
.ShouldEqual(100);
|
||||
|
||||
var rootDirectory = Path.Combine(tempDir, APP_ID, "staging", "app-1.3.0.0");
|
||||
|
||||
new[] {
|
||||
new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||
new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||
}.ForEach(x => {
|
||||
var path = Path.Combine(rootDirectory, x.Name);
|
||||
this.Log().Info("Looking for {0}", path);
|
||||
File.Exists(path).ShouldBeTrue();
|
||||
});
|
||||
|
||||
var oldFile = Path.Combine(rootDirectory, "sub", "Ionic.Zip.dll");
|
||||
File.Exists(oldFile).ShouldBeFalse();
|
||||
|
||||
var newFile = Path.Combine(rootDirectory, "other", "Ionic.Zip.dll");
|
||||
File.Exists(newFile).ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ApplyReleasesWithDeltaReleases()
|
||||
{
|
||||
string tempDir;
|
||||
|
||||
using (Utility.GetTempDirectory(out tempDir)) {
|
||||
string appDir = Path.Combine(tempDir, APP_ID);
|
||||
string packagesDir = Path.Combine(appDir, "packages");
|
||||
Directory.CreateDirectory(packagesDir);
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.0.0.0-full.nupkg"));
|
||||
var deltaEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-delta.nupkg"));
|
||||
var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||
|
||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { deltaEntry, latestFullEntry }, packagesDir);
|
||||
updateInfo.ReleasesToApply.Contains(deltaEntry).ShouldBeTrue();
|
||||
|
||||
var progress = new List<int>();
|
||||
|
||||
await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
// TODO: this is failing intermittently, not sure why but is not a big deal atm
|
||||
// progress
|
||||
// .Aggregate(0, (acc, x) => { (x >= acc).ShouldBeTrue(); return x; })
|
||||
// .ShouldEqual(100);
|
||||
|
||||
var filesToFind = new[] {
|
||||
new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||
new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||
};
|
||||
|
||||
filesToFind.ForEach(x => {
|
||||
var path = Path.Combine(tempDir, APP_ID, "staging", "app-1.1.0.0", x.Name);
|
||||
this.Log().Info("Looking for {0}", path);
|
||||
File.Exists(path).ShouldBeTrue();
|
||||
|
||||
var vi = FileVersionInfo.GetVersionInfo(path);
|
||||
var verInfo = new Version(vi.FileVersion ?? "1.0.0.0");
|
||||
x.Version.ShouldEqual(verInfo);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateFullPackagesFromDeltaSmokeTest()
|
||||
{
|
||||
string tempDir;
|
||||
using (Utility.GetTempDirectory(out tempDir)) {
|
||||
string appDir = Path.Combine(tempDir, APP_ID);
|
||||
string packagesDir = Path.Combine(appDir, "packages");
|
||||
Directory.CreateDirectory(packagesDir);
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-delta.nupkg"
|
||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(tempDir, APP_ID, "packages", x)));
|
||||
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(tempDir, APP_ID, "packages", "Squirrel.Core.1.0.0.0-full.nupkg"));
|
||||
var deltaEntry = ReleaseEntry.GenerateFromFile(Path.Combine(tempDir, APP_ID, "packages", "Squirrel.Core.1.1.0.0-delta.nupkg"));
|
||||
|
||||
var result = fixture.createFullPackagesFromDeltas(new[] { deltaEntry }, baseEntry, null);
|
||||
|
||||
var zp = new ZipPackage(Path.Combine(tempDir, APP_ID, "packages", result.Filename));
|
||||
zp.Version.ToString().ShouldEqual("1.1.0.0");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateShortcutsRoundTrip()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir);
|
||||
await fixture.FullInstall();
|
||||
|
||||
fixture.CreateShortcutsForExecutable("SquirrelAwareApp.exe",
|
||||
ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot, false, null, null);
|
||||
|
||||
Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "PublishSingleFileAwareApp.lnk")));
|
||||
|
||||
// NB: COM is Weird.
|
||||
Thread.Sleep(1000);
|
||||
fixture.RemoveShortcutsForExecutable("SquirrelAwareApp.exe",
|
||||
ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot);
|
||||
|
||||
// NB: Squirrel-Aware first-run might still be running, slow
|
||||
// our roll before blowing away the temp path
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
//[Fact]
|
||||
//public async Task GetShortcutsSmokeTest()
|
||||
//{
|
||||
// string remotePkgPath;
|
||||
// string path;
|
||||
|
||||
// using (Utility.WithTempDirectory(out path)) {
|
||||
// using (Utility.WithTempDirectory(out remotePkgPath))
|
||||
// using (var mgr = new UpdateManager(remotePkgPath, APP_ID, path)) {
|
||||
// IntegrationTestHelper.CreateFakeInstalledApp("1.0.0.1", remotePkgPath);
|
||||
// await mgr.FullInstall();
|
||||
// }
|
||||
|
||||
// var fixture = new ApplyReleasesImpl(Path.Combine(path, APP_ID));
|
||||
// var result = fixture.GetShortcutsForExecutable("SquirrelAwareApp.exe", ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup, null);
|
||||
|
||||
// Assert.Equal(3, result.Keys.Count);
|
||||
|
||||
// // NB: Squirrel-Aware first-run might still be running, slow
|
||||
// // our roll before blowing away the temp path
|
||||
// Thread.Sleep(1000);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Squirrel.Tests.TestHelpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public class CheckForUpdateTests
|
||||
{
|
||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
||||
public void NewReleasesShouldBeDetected()
|
||||
{
|
||||
Assert.Fail("Rewrite this to be an integration test");
|
||||
/*
|
||||
string localReleasesFile = Path.Combine(".", "theApp", "packages", "RELEASES");
|
||||
|
||||
var fileInfo = new Mock<FileInfoBase>();
|
||||
fileInfo.Setup(x => x.OpenRead())
|
||||
.Returns(File.OpenRead(IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOh")));
|
||||
|
||||
var fs = new Mock<IFileSystemFactory>();
|
||||
fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
||||
|
||||
var urlDownloader = new Mock<IUrlDownloader>();
|
||||
var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
|
||||
urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
||||
.Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
|
||||
|
||||
var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
||||
var result = default(UpdateInfo);
|
||||
|
||||
using (fixture) {
|
||||
result = fixture.CheckForUpdate().First();
|
||||
}
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1, result.ReleasesToApply.Single().Version.Major);
|
||||
Assert.Equal(1, result.ReleasesToApply.Single().Version.Minor);
|
||||
*/
|
||||
}
|
||||
|
||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
||||
public void CorruptedReleaseFileMeansWeStartFromScratch()
|
||||
{
|
||||
Assert.Fail("Rewrite this to be an integration test");
|
||||
|
||||
/*
|
||||
string localPackagesDir = Path.Combine(".", "theApp", "packages");
|
||||
string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
|
||||
|
||||
var fileInfo = new Mock<FileInfoBase>();
|
||||
fileInfo.Setup(x => x.Exists).Returns(true);
|
||||
fileInfo.Setup(x => x.OpenRead())
|
||||
.Returns(new MemoryStream(Encoding.UTF8.GetBytes("lol this isn't right")));
|
||||
|
||||
var dirInfo = new Mock<DirectoryInfoBase>();
|
||||
dirInfo.Setup(x => x.Exists).Returns(true);
|
||||
|
||||
var fs = new Mock<IFileSystemFactory>();
|
||||
fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
||||
fs.Setup(x => x.CreateDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||
fs.Setup(x => x.DeleteDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||
fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
|
||||
|
||||
var urlDownloader = new Mock<IUrlDownloader>();
|
||||
var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
|
||||
urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
||||
.Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
|
||||
|
||||
var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
||||
using (fixture) {
|
||||
fixture.CheckForUpdate().First();
|
||||
}
|
||||
|
||||
fs.Verify(x => x.CreateDirectoryRecursive(localPackagesDir), Times.Once());
|
||||
fs.Verify(x => x.DeleteDirectoryRecursive(localPackagesDir), Times.Once());
|
||||
*/
|
||||
}
|
||||
|
||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
||||
public void CorruptRemoteFileShouldThrowOnCheck()
|
||||
{
|
||||
Assert.Fail("Rewrite this to be an integration test");
|
||||
|
||||
/*
|
||||
string localPackagesDir = Path.Combine(".", "theApp", "packages");
|
||||
string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
|
||||
|
||||
var fileInfo = new Mock<FileInfoBase>();
|
||||
fileInfo.Setup(x => x.Exists).Returns(false);
|
||||
|
||||
var dirInfo = new Mock<DirectoryInfoBase>();
|
||||
dirInfo.Setup(x => x.Exists).Returns(true);
|
||||
|
||||
var fs = new Mock<IFileSystemFactory>();
|
||||
fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
||||
fs.Setup(x => x.CreateDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||
fs.Setup(x => x.DeleteDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||
fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
|
||||
|
||||
var urlDownloader = new Mock<IUrlDownloader>();
|
||||
urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
||||
.Returns(Observable.Return("lol this isn't right"));
|
||||
|
||||
var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
||||
|
||||
using (fixture) {
|
||||
Assert.Throws<Exception>(() => fixture.CheckForUpdate().First());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
[Fact(Skip = "TODO")]
|
||||
public void IfLocalVersionGreaterThanRemoteWeRollback()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[Fact(Skip = "TODO")]
|
||||
public void IfLocalAndRemoteAreEqualThenDoNothing()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(@"94689fede03fed7ab59c24337673a27837f0c3ec MyCoolApp-1.0.nupkg 1004502", "MyCoolApp", null)]
|
||||
[InlineData(@"0000000000000000000000000000000000000000 https://www.test.org/Folder/MyCoolApp-1.2-delta.nupkg?query=param 1231953", "MyCoolApp", "https://www.test.org/Folder")]
|
||||
public async Task WebSourceRequestsExpectedUrls(string releaseEntry, string releaseName, string baseUrl)
|
||||
{
|
||||
baseUrl = baseUrl ?? "https://example.com/files";
|
||||
var dl = new FakeDownloader();
|
||||
var source = new Sources.SimpleWebSource("https://example.com/files", dl);
|
||||
|
||||
dl.MockedResponseBytes = Encoding.UTF8.GetBytes(releaseEntry);
|
||||
var releases = await source.GetReleaseFeed(null, null);
|
||||
Assert.True(releases.Count() == 1);
|
||||
Assert.Equal(releaseName, releases[0].PackageName);
|
||||
Assert.Equal("https://example.com/files/RELEASES", new Uri(dl.LastUrl).GetLeftPart(UriPartial.Path));
|
||||
|
||||
await source.DownloadReleaseEntry(releases[0], "test", null);
|
||||
Assert.Equal(baseUrl + "/" + releases[0].Filename, new Uri(dl.LastUrl).GetLeftPart(UriPartial.Path));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("http://example.com", "MyPackage.nupkg", "http://example.com/MyPackage.nupkg")]
|
||||
[InlineData("http://example.com?auth=hello", "MyPackage.nupkg", "http://example.com/MyPackage.nupkg?auth=hello")]
|
||||
[InlineData("http://example.com?auth=hello", "https://my.packages.domain/MyPackage-1.0.0.nupkg", "https://my.packages.domain/MyPackage-1.0.0.nupkg")]
|
||||
public async Task SimpleWebSourcePreservesQueryParametersAndAbsoluteReleaseUri(string baseUri, string releaseUri, string expectedPackageUrl)
|
||||
{
|
||||
var dl = new FakeDownloader();
|
||||
var source = new Sources.SimpleWebSource(baseUri, dl);
|
||||
var baseKvp = HttpUtility.ParseQueryString(new Uri(baseUri).Query);
|
||||
var baseDict = baseKvp.AllKeys.Where(k => k != null).ToDictionary(k => k, k => baseKvp[k]);
|
||||
|
||||
var releaseEntry = $"94689fede03fed7ab59c24337673a27837f0c3ec {releaseUri} 1004502";
|
||||
dl.MockedResponseBytes = Encoding.UTF8.GetBytes(releaseEntry);
|
||||
|
||||
var releases = await source.GetReleaseFeed();
|
||||
var expected = new Uri(baseUri).GetLeftPart(UriPartial.Path).TrimEnd('/') + "/RELEASES";
|
||||
Assert.StartsWith(expected, dl.LastUrl);
|
||||
|
||||
// check that each query parameter in base url is in the releases string
|
||||
var releasesUri = new Uri(dl.LastUrl);
|
||||
var releasesKvp = HttpUtility.ParseQueryString(releasesUri.Query);
|
||||
var releasesDict = releasesKvp.AllKeys.Where(k => k != null).ToDictionary(k => k, k => releasesKvp[k]);
|
||||
foreach (var kvp in baseDict) {
|
||||
Assert.Equal(releasesDict[kvp.Key], kvp.Value);
|
||||
}
|
||||
|
||||
await source.DownloadReleaseEntry(releases[0], "test", null);
|
||||
Assert.Equal(expectedPackageUrl, dl.LastUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,347 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Squirrel.NuGet;
|
||||
using Squirrel;
|
||||
using Squirrel.SimpleSplat;
|
||||
using Squirrel.Tests.TestHelpers;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using NuGet.Versioning;
|
||||
using Squirrel.CommandLine;
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public class ApplyDeltaPackageTests : TestLoggingBase
|
||||
{
|
||||
public ApplyDeltaPackageTests(ITestOutputHelper log) : base(log)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyDeltaPackageSmokeTest()
|
||||
{
|
||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0-full.nupkg");
|
||||
var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-delta.nupkg");
|
||||
var expectedPackageFile = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-full.nupkg");
|
||||
var outFile = Path.GetTempFileName() + ".nupkg";
|
||||
|
||||
try {
|
||||
var deltaBuilder = new DeltaPackage();
|
||||
deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
|
||||
|
||||
var result = new ZipPackage(outFile);
|
||||
var expected = new ZipPackage(expectedPackageFile);
|
||||
|
||||
result.Id.ShouldEqual(expected.Id);
|
||||
result.Version.ShouldEqual(expected.Version);
|
||||
|
||||
this.Log().Info("Expected file list:");
|
||||
var expectedList = expected.Files.Select(x => x.Path).OrderBy(x => x).ToList();
|
||||
expectedList.ForEach(x => this.Log().Info(x));
|
||||
|
||||
this.Log().Info("Actual file list:");
|
||||
var actualList = result.Files.Select(x => x.Path).OrderBy(x => x).ToList();
|
||||
actualList.ForEach(x => this.Log().Info(x));
|
||||
|
||||
Enumerable.Zip(expectedList, actualList, (e, a) => e == a)
|
||||
.All(x => x != false)
|
||||
.ShouldBeTrue();
|
||||
} finally {
|
||||
if (File.Exists(outFile)) {
|
||||
File.Delete(outFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyDeltaWithBothBsdiffAndNormalDiffDoesntFail()
|
||||
{
|
||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.1.8-full.nupkg");
|
||||
var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.2.0-delta.nupkg");
|
||||
var outFile = Path.GetTempFileName() + ".nupkg";
|
||||
|
||||
try {
|
||||
var deltaBuilder = new DeltaPackage();
|
||||
deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
|
||||
|
||||
var result = new ZipPackage(outFile);
|
||||
|
||||
result.Id.ShouldEqual("slack");
|
||||
result.Version.ShouldEqual(SemanticVersion.Parse("1.2.0"));
|
||||
} finally {
|
||||
if (File.Exists(outFile)) {
|
||||
File.Delete(outFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMultipleDeltasFast()
|
||||
{
|
||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.287-full.nupkg");
|
||||
var deltaPackage1 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.288-delta.nupkg");
|
||||
var deltaPackage2 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.291-delta.nupkg");
|
||||
var deltaPackage3 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.292-delta.nupkg");
|
||||
|
||||
using var t1 = Utility.GetTempDirectory(out var appDir);
|
||||
using var t2 = Utility.GetTempDirectory(out var updateDir);
|
||||
|
||||
using var um = UpdateManagerTestImpl.FromLocalPackageTempDir(updateDir, "theApp", appDir);
|
||||
var pkgDir = um.Config.PackagesDir;
|
||||
|
||||
File.Copy(basePackage, Path.Combine(pkgDir, Path.GetFileName(basePackage)));
|
||||
File.Copy(deltaPackage1, Path.Combine(pkgDir, Path.GetFileName(deltaPackage1)));
|
||||
File.Copy(deltaPackage2, Path.Combine(pkgDir, Path.GetFileName(deltaPackage2)));
|
||||
File.Copy(deltaPackage3, Path.Combine(pkgDir, Path.GetFileName(deltaPackage3)));
|
||||
|
||||
var baseEntry = ReleaseEntry.GenerateFromFile(basePackage);
|
||||
|
||||
var toApply = new [] {
|
||||
ReleaseEntry.GenerateFromFile(deltaPackage1),
|
||||
ReleaseEntry.GenerateFromFile(deltaPackage2),
|
||||
ReleaseEntry.GenerateFromFile(deltaPackage3),
|
||||
};
|
||||
|
||||
List<int> progress = new List<int>();
|
||||
|
||||
var newEntry = um.createFullPackagesFromDeltas(toApply, baseEntry, progress.Add);
|
||||
|
||||
var outFile = Path.Combine(pkgDir, newEntry.Filename);
|
||||
var result = new ZipPackage(outFile);
|
||||
result.Id.ShouldEqual("Clowd");
|
||||
result.Version.ShouldEqual(SemanticVersion.Parse("3.4.292"));
|
||||
}
|
||||
|
||||
[Fact(Skip = "Rewrite this test, the original uses too many heavyweight fixtures")]
|
||||
public void ApplyMultipleDeltaPackagesGeneratesCorrectHash()
|
||||
{
|
||||
Assert.Fail("Rewrite this test, the original uses too many heavyweight fixtures");
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateDeltaPackageTests : IEnableLogger
|
||||
{
|
||||
[Fact]
|
||||
public void CreateDeltaPackageIntegrationTest()
|
||||
{
|
||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||
|
||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
var tempFiles = Enumerable.Range(0, 3)
|
||||
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||
.ToArray();
|
||||
|
||||
try {
|
||||
baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||
fixture.CreateReleasePackage(tempFiles[1]);
|
||||
|
||||
(new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
(new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
|
||||
var deltaBuilder = new DeltaPackageBuilder();
|
||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||
|
||||
var fullPkg = new ZipPackage(tempFiles[1]);
|
||||
var deltaPkg = new ZipPackage(tempFiles[2]);
|
||||
|
||||
//
|
||||
// Package Checks
|
||||
//
|
||||
|
||||
fullPkg.Id.ShouldEqual(deltaPkg.Id);
|
||||
fullPkg.Version.CompareTo(deltaPkg.Version).ShouldEqual(0);
|
||||
|
||||
// Delta packages should be smaller than the original!
|
||||
var fileInfos = tempFiles.Select(x => new FileInfo(x)).ToArray();
|
||||
this.Log().Info("Base Size: {0}, Current Size: {1}, Delta Size: {2}",
|
||||
fileInfos[0].Length, fileInfos[1].Length, fileInfos[2].Length);
|
||||
|
||||
(fileInfos[2].Length - fileInfos[1].Length).ShouldBeLessThan(0);
|
||||
|
||||
//
|
||||
// File Checks
|
||||
///
|
||||
|
||||
var deltaPkgFiles = deltaPkg.Files.ToList();
|
||||
deltaPkgFiles.Count.ShouldBeGreaterThan(0);
|
||||
|
||||
this.Log().Info("Files in delta package:");
|
||||
deltaPkgFiles.ForEach(x => this.Log().Info(x.Path));
|
||||
|
||||
var newFilesAdded = new[] {
|
||||
"Newtonsoft.Json.dll",
|
||||
//"Refit.dll",
|
||||
//"Refit-Portable.dll",
|
||||
//"Castle.Core.dll",
|
||||
}.Select(x => x.ToLowerInvariant());
|
||||
|
||||
// vNext adds a dependency on Refit
|
||||
newFilesAdded
|
||||
.All(x => deltaPkgFiles.Any(y => y.Path.ToLowerInvariant().Contains(x)))
|
||||
.ShouldBeTrue();
|
||||
|
||||
// All the other files should be diffs and shasums
|
||||
deltaPkgFiles
|
||||
.Where(x => !newFilesAdded.Any(y => x.Path.ToLowerInvariant().Contains(y)))
|
||||
.All(x => x.Path.ToLowerInvariant().EndsWith("bsdiff") || x.Path.ToLowerInvariant().EndsWith("shasum"))
|
||||
.ShouldBeTrue();
|
||||
|
||||
// Every .diff file should have a shasum file
|
||||
deltaPkg.Files.Any(x => x.Path.ToLowerInvariant().EndsWith(".bsdiff")).ShouldBeTrue();
|
||||
deltaPkg.Files
|
||||
.Where(x => x.Path.ToLowerInvariant().EndsWith(".bsdiff"))
|
||||
.ForEach(x => {
|
||||
var lookingFor = x.Path.Replace(".bsdiff", ".shasum");
|
||||
this.Log().Info("Looking for corresponding shasum file: {0}", lookingFor);
|
||||
deltaPkg.Files.Any(y => y.Path == lookingFor).ShouldBeTrue();
|
||||
});
|
||||
} finally {
|
||||
tempFiles.ForEach(File.Delete);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenBasePackageIsNewerThanNewPackageThrowException()
|
||||
{
|
||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
|
||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
var tempFiles = Enumerable.Range(0, 3)
|
||||
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||
.ToArray();
|
||||
|
||||
try {
|
||||
baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||
fixture.CreateReleasePackage(tempFiles[1]);
|
||||
|
||||
(new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
(new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => {
|
||||
var deltaBuilder = new DeltaPackageBuilder();
|
||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||
});
|
||||
} finally {
|
||||
tempFiles.ForEach(File.Delete);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenBasePackageReleaseIsNullThrowsException()
|
||||
{
|
||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0.nupkg");
|
||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
|
||||
|
||||
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
|
||||
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
|
||||
|
||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
var tempFile = Path.GetTempPath() + Guid.NewGuid() + ".nupkg";
|
||||
|
||||
try {
|
||||
Assert.Throws<ArgumentException>(() => {
|
||||
var deltaBuilder = new DeltaPackageBuilder();
|
||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFile);
|
||||
});
|
||||
} finally {
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenBasePackageDoesNotExistThrowException()
|
||||
{
|
||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||
|
||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
var tempFiles = Enumerable.Range(0, 3)
|
||||
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||
.ToArray();
|
||||
|
||||
try {
|
||||
baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||
fixture.CreateReleasePackage(tempFiles[1]);
|
||||
|
||||
(new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
(new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
|
||||
// NOW WATCH AS THE FILE DISAPPEARS
|
||||
File.Delete(baseFixture.ReleasePackageFile);
|
||||
|
||||
Assert.Throws<FileNotFoundException>(() => {
|
||||
var deltaBuilder = new DeltaPackageBuilder();
|
||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||
});
|
||||
} finally {
|
||||
tempFiles.ForEach(File.Delete);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenNewPackageDoesNotExistThrowException()
|
||||
{
|
||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||
|
||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||
var fixture = new ReleasePackageBuilder(newPackage);
|
||||
|
||||
var tempFiles = Enumerable.Range(0, 3)
|
||||
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||
.ToArray();
|
||||
|
||||
try {
|
||||
baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||
fixture.CreateReleasePackage(tempFiles[1]);
|
||||
|
||||
(new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
(new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||
|
||||
// NOW WATCH AS THE FILE DISAPPEARS
|
||||
File.Delete(fixture.ReleasePackageFile);
|
||||
|
||||
Assert.Throws<FileNotFoundException>(() => {
|
||||
var deltaBuilder = new DeltaPackageBuilder();
|
||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||
});
|
||||
} finally {
|
||||
tempFiles.ForEach(File.Delete);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleBsDiffWithoutExtraData()
|
||||
{
|
||||
var baseFileData = new byte[] { 1, 1, 1, 1 };
|
||||
var newFileData = new byte[] { 2, 1, 1, 1 };
|
||||
|
||||
byte[] patchData;
|
||||
|
||||
using (var patchOut = new MemoryStream()) {
|
||||
Bsdiff.BinaryPatchUtility.Create(baseFileData, newFileData, patchOut);
|
||||
patchData = patchOut.ToArray();
|
||||
}
|
||||
|
||||
using (var toPatch = new MemoryStream(baseFileData))
|
||||
using (var patched = new MemoryStream()) {
|
||||
Bsdiff.BinaryPatchUtility.Apply(toPatch, () => new MemoryStream(patchData), patched);
|
||||
|
||||
Assert.Equal(newFileData, patched.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Squirrel.SimpleSplat;
|
||||
using Squirrel.Tests.TestHelpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public class DownloadReleasesTests
|
||||
{
|
||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
||||
public void ChecksumShouldFailIfFilesAreMissing()
|
||||
{
|
||||
Assert.Fail("Rewrite this to be an integration test");
|
||||
|
||||
/*
|
||||
var filename = "Squirrel.Core.1.0.0.0.nupkg";
|
||||
var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
|
||||
var fs = new Mock<IFileSystemFactory>();
|
||||
var urlDownloader = new Mock<IUrlDownloader>();
|
||||
|
||||
ReleaseEntry entry;
|
||||
using (var f = File.OpenRead(nuGetPkg)) {
|
||||
entry = ReleaseEntry.GenerateFromFile(f, filename);
|
||||
}
|
||||
|
||||
var fileInfo = new Mock<FileInfoBase>();
|
||||
fileInfo.Setup(x => x.OpenRead()).Returns(File.OpenRead(nuGetPkg));
|
||||
fileInfo.Setup(x => x.Exists).Returns(false);
|
||||
|
||||
fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
|
||||
|
||||
var fixture = ExposedObject.From(
|
||||
new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
|
||||
|
||||
bool shouldDie = true;
|
||||
try {
|
||||
// NB: We can't use Assert.Throws here because the binder
|
||||
// will try to pick the wrong method
|
||||
fixture.checksumPackage(entry);
|
||||
} catch (Exception) {
|
||||
shouldDie = false;
|
||||
}
|
||||
|
||||
shouldDie.ShouldBeFalse();
|
||||
*/
|
||||
}
|
||||
|
||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
||||
public void ChecksumShouldFailIfFilesAreBogus()
|
||||
{
|
||||
Assert.Fail("Rewrite this to be an integration test");
|
||||
|
||||
/*
|
||||
var filename = "Squirrel.Core.1.0.0.0.nupkg";
|
||||
var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
|
||||
var fs = new Mock<IFileSystemFactory>();
|
||||
var urlDownloader = new Mock<IUrlDownloader>();
|
||||
|
||||
ReleaseEntry entry;
|
||||
using (var f = File.OpenRead(nuGetPkg)) {
|
||||
entry = ReleaseEntry.GenerateFromFile(f, filename);
|
||||
}
|
||||
|
||||
var fileInfo = new Mock<FileInfoBase>();
|
||||
fileInfo.Setup(x => x.OpenRead()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("Lol broken")));
|
||||
fileInfo.Setup(x => x.Exists).Returns(true);
|
||||
fileInfo.Setup(x => x.Length).Returns(new FileInfo(nuGetPkg).Length);
|
||||
fileInfo.Setup(x => x.Delete()).Verifiable();
|
||||
|
||||
fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
|
||||
|
||||
var fixture = ExposedObject.From(
|
||||
new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
|
||||
|
||||
bool shouldDie = true;
|
||||
try {
|
||||
fixture.checksumPackage(entry);
|
||||
} catch (Exception ex) {
|
||||
this.Log().InfoException("Checksum failure", ex);
|
||||
shouldDie = false;
|
||||
}
|
||||
|
||||
shouldDie.ShouldBeFalse();
|
||||
fileInfo.Verify(x => x.Delete(), Times.Once());
|
||||
*/
|
||||
}
|
||||
|
||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
||||
public async Task DownloadReleasesFromHttpServerIntegrationTest()
|
||||
{
|
||||
Assert.Fail("Rewrite this to not use the SampleUpdatingApp");
|
||||
|
||||
/*
|
||||
string tempDir = null;
|
||||
|
||||
var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
|
||||
|
||||
IDisposable disp;
|
||||
try {
|
||||
var httpServer = new StaticHttpServer(30405, updateDir.FullName);
|
||||
disp = httpServer.Start();
|
||||
} catch (HttpListenerException) {
|
||||
Assert.False(true, @"Windows sucks, go run 'netsh http add urlacl url=http://+:30405/ user=MYMACHINE\MyUser");
|
||||
return;
|
||||
}
|
||||
|
||||
var entriesToDownload = updateDir.GetFiles("*.nupkg")
|
||||
.Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
|
||||
.ToArray();
|
||||
|
||||
entriesToDownload.Count().ShouldBeGreaterThan(0);
|
||||
|
||||
using (disp)
|
||||
using (Utility.WithTempDirectory(out tempDir)) {
|
||||
// NB: This is normally done by CheckForUpdates, but since
|
||||
// we're skipping that in the test we have to do it ourselves
|
||||
Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
|
||||
|
||||
var fixture = new UpdateManager("http://localhost:30405", "SampleUpdatingApp", tempDir);
|
||||
using (fixture) {
|
||||
var progress = new List<int>();
|
||||
await fixture.DownloadReleases(entriesToDownload, progress.Add);
|
||||
|
||||
progress
|
||||
.Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
|
||||
.ShouldEqual(100);
|
||||
}
|
||||
|
||||
entriesToDownload.ForEach(x => {
|
||||
this.Log().Info("Looking for {0}", x.Filename);
|
||||
var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
|
||||
File.Exists(actualFile).ShouldBeTrue();
|
||||
|
||||
var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
|
||||
actualEntry.SHA1.ShouldEqual(x.SHA1);
|
||||
actualEntry.Version.ShouldEqual(x.Version);
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
||||
public async Task DownloadReleasesFromFileDirectoryIntegrationTest()
|
||||
{
|
||||
Assert.Fail("Rewrite this to not use the SampleUpdatingApp");
|
||||
|
||||
/*
|
||||
string tempDir = null;
|
||||
|
||||
var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
|
||||
|
||||
var entriesToDownload = updateDir.GetFiles("*.nupkg")
|
||||
.Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
|
||||
.ToArray();
|
||||
|
||||
entriesToDownload.Count().ShouldBeGreaterThan(0);
|
||||
|
||||
using (Utility.WithTempDirectory(out tempDir)) {
|
||||
// NB: This is normally done by CheckForUpdates, but since
|
||||
// we're skipping that in the test we have to do it ourselves
|
||||
Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
|
||||
|
||||
var fixture = new UpdateManager(updateDir.FullName, "SampleUpdatingApp", tempDir);
|
||||
using (fixture) {
|
||||
var progress = new List<int>();
|
||||
|
||||
await fixture.DownloadReleases(entriesToDownload, progress.Add);
|
||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
progress
|
||||
.Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
|
||||
.ShouldEqual(100);
|
||||
}
|
||||
|
||||
entriesToDownload.ForEach(x => {
|
||||
this.Log().Info("Looking for {0}", x.Filename);
|
||||
var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
|
||||
File.Exists(actualFile).ShouldBeTrue();
|
||||
|
||||
var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
|
||||
actualEntry.SHA1.ShouldEqual(x.SHA1);
|
||||
actualEntry.Version.ShouldEqual(x.Version);
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Squirrel.CommandLine;
|
||||
using Xunit.Abstractions;
|
||||
using Xunit.Sdk;
|
||||
|
||||
[assembly: Xunit.TestFramework("Squirrel.Tests.TestsInit", "Squirrel.Tests")]
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public class TestsInit : XunitTestFramework
|
||||
{
|
||||
public TestsInit(IMessageSink messageSink)
|
||||
: base(messageSink)
|
||||
{
|
||||
// Place initialization code here
|
||||
var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.Replace("file:///", ""));
|
||||
HelperFile.AddSearchPath(Path.Combine(baseDir, "..", "..", "..", "..", "..", "vendor"));
|
||||
HelperFile.AddSearchPath(Path.Combine(baseDir, "..", "..", "..", "..", "..", "vendor", "7zip"));
|
||||
HelperFile.AddSearchPath(Path.Combine(baseDir, "..", "..", "..", "..", "..", "vendor", "wix"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Squirrel.SimpleSplat;
|
||||
|
||||
namespace Squirrel.Tests.Legacy
|
||||
{
|
||||
@@ -25,7 +24,7 @@ namespace Squirrel.Tests.Legacy
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class ReleaseEntry : IEnableLogger, IReleaseEntry
|
||||
public class ReleaseEntry : IReleaseEntry
|
||||
{
|
||||
[DataMember] public string SHA1 { get; protected set; }
|
||||
[DataMember] public string BaseUrl { get; protected set; }
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Xunit;
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: CollectionBehavior(MaxParallelThreads=1, DisableTestParallelization=true)]
|
||||
[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NuGet.Versioning;
|
||||
using Squirrel.CommandLine;
|
||||
using Squirrel.Tests.TestHelpers;
|
||||
using Xunit;
|
||||
|
||||
@@ -190,88 +189,88 @@ namespace Squirrel.Tests
|
||||
ReleaseEntry.ParseReleaseEntry(entryAsString);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetLatestReleaseWithNullCollectionReturnsNull()
|
||||
{
|
||||
Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
||||
null, null, null, null));
|
||||
}
|
||||
//[Fact]
|
||||
//public void GetLatestReleaseWithNullCollectionReturnsNull()
|
||||
//{
|
||||
// Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
||||
// null, null, null, null));
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void GetLatestReleaseWithEmptyCollectionReturnsNull()
|
||||
{
|
||||
Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
||||
Enumerable.Empty<ReleaseEntry>(), null, null, null));
|
||||
}
|
||||
//[Fact]
|
||||
//public void GetLatestReleaseWithEmptyCollectionReturnsNull()
|
||||
//{
|
||||
// Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
||||
// Enumerable.Empty<ReleaseEntry>(), null, null, null));
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void WhenCurrentReleaseMatchesLastReleaseReturnNull()
|
||||
{
|
||||
var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
|
||||
//[Fact]
|
||||
//public void WhenCurrentReleaseMatchesLastReleaseReturnNull()
|
||||
//{
|
||||
// var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
|
||||
|
||||
var releaseEntries = new[] {
|
||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
|
||||
};
|
||||
Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
||||
releaseEntries, package, @"C:\temp\somefolder", null));
|
||||
}
|
||||
// var releaseEntries = new[] {
|
||||
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
|
||||
// };
|
||||
// Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
||||
// releaseEntries, package, @"C:\temp\somefolder", null));
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void WhenMultipleReleaseMatchesReturnEarlierResult()
|
||||
{
|
||||
var expected = SemanticVersion.Parse("1.7.5-beta");
|
||||
var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
|
||||
//[Fact]
|
||||
//public void WhenMultipleReleaseMatchesReturnEarlierResult()
|
||||
//{
|
||||
// var expected = SemanticVersion.Parse("1.7.5-beta");
|
||||
// var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
|
||||
|
||||
var releaseEntries = new[] {
|
||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
|
||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
|
||||
};
|
||||
// var releaseEntries = new[] {
|
||||
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
|
||||
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
|
||||
// };
|
||||
|
||||
var actual = ReleasePackageBuilder.GetPreviousRelease(
|
||||
releaseEntries,
|
||||
package,
|
||||
@"C:\temp\", null);
|
||||
// var actual = ReleasePackageBuilder.GetPreviousRelease(
|
||||
// releaseEntries,
|
||||
// package,
|
||||
// @"C:\temp\", null);
|
||||
|
||||
Assert.Equal(expected, actual.Version);
|
||||
}
|
||||
// Assert.Equal(expected, actual.Version);
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void WhenMultipleReleasesFoundReturnPreviousVersion()
|
||||
{
|
||||
var expected = SemanticVersion.Parse("1.7.6-beta");
|
||||
var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
|
||||
//[Fact]
|
||||
//public void WhenMultipleReleasesFoundReturnPreviousVersion()
|
||||
//{
|
||||
// var expected = SemanticVersion.Parse("1.7.6-beta");
|
||||
// var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
|
||||
|
||||
var releaseEntries = new[] {
|
||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
|
||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
|
||||
};
|
||||
// var releaseEntries = new[] {
|
||||
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
|
||||
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
|
||||
// };
|
||||
|
||||
var actual = ReleasePackageBuilder.GetPreviousRelease(
|
||||
releaseEntries,
|
||||
input,
|
||||
@"C:\temp\", null);
|
||||
// var actual = ReleasePackageBuilder.GetPreviousRelease(
|
||||
// releaseEntries,
|
||||
// input,
|
||||
// @"C:\temp\", null);
|
||||
|
||||
Assert.Equal(expected, actual.Version);
|
||||
}
|
||||
// Assert.Equal(expected, actual.Version);
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void WhenMultipleReleasesFoundInOtherOrderReturnPreviousVersion()
|
||||
{
|
||||
var expected = SemanticVersion.Parse("1.7.6-beta");
|
||||
var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
|
||||
//[Fact]
|
||||
//public void WhenMultipleReleasesFoundInOtherOrderReturnPreviousVersion()
|
||||
//{
|
||||
// var expected = SemanticVersion.Parse("1.7.6-beta");
|
||||
// var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
|
||||
|
||||
var releaseEntries = new[] {
|
||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg")),
|
||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
|
||||
};
|
||||
// var releaseEntries = new[] {
|
||||
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg")),
|
||||
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
|
||||
// };
|
||||
|
||||
var actual = ReleasePackageBuilder.GetPreviousRelease(
|
||||
releaseEntries,
|
||||
input,
|
||||
@"C:\temp\", null);
|
||||
// var actual = ReleasePackageBuilder.GetPreviousRelease(
|
||||
// releaseEntries,
|
||||
// input,
|
||||
// @"C:\temp\", null);
|
||||
|
||||
Assert.Equal(expected, actual.Version);
|
||||
}
|
||||
// Assert.Equal(expected, actual.Version);
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void WhenReleasesAreOutOfOrderSortByVersion()
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
using System.Runtime.Versioning;
|
||||
using Squirrel.MarkdownSharp;
|
||||
using Squirrel;
|
||||
using Squirrel.Tests.TestHelpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using Squirrel.SimpleSplat;
|
||||
using Xunit;
|
||||
using Squirrel.NuGet;
|
||||
using Xunit.Abstractions;
|
||||
using NuGet.Versioning;
|
||||
using Squirrel.CommandLine;
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public class CreateReleasePackageTests : TestLoggingBase
|
||||
{
|
||||
public CreateReleasePackageTests(ITestOutputHelper log) : base(log)
|
||||
{
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("1.2.3")]
|
||||
[InlineData("1.2.3-alpha13")]
|
||||
[InlineData("1.2.3-alpha135")]
|
||||
[InlineData("0.0.1")]
|
||||
[InlineData("1.299656.3-alpha")]
|
||||
public void SemanticVersionParsesValidVersion(string ver)
|
||||
{
|
||||
NugetUtil.ThrowIfVersionNotSemverCompliant(ver);
|
||||
Assert.True(SemanticVersion.TryParse(ver, out var _));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("1")]
|
||||
[InlineData("0")]
|
||||
[InlineData("1.2.3.4")]
|
||||
[InlineData("1.2.3.4-alpha")]
|
||||
[InlineData("0.0.0.0")]
|
||||
[InlineData("0.0.0")]
|
||||
[InlineData("0.0")]
|
||||
[InlineData("0.0.0-alpha")]
|
||||
public void SemanticVersionThrowsInvalidVersion(string ver)
|
||||
{
|
||||
Assert.ThrowsAny<Exception>(() => NugetUtil.ThrowIfVersionNotSemverCompliant(ver));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReleasePackageIntegrationTest()
|
||||
{
|
||||
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||
var outputPackage = Path.GetTempFileName() + ".nupkg";
|
||||
|
||||
var fixture = new ReleasePackageBuilder(inputPackage);
|
||||
|
||||
try {
|
||||
fixture.CreateReleasePackage(outputPackage);
|
||||
|
||||
this.Log().Info("Resulting package is at {0}", outputPackage);
|
||||
var pkg = new ZipPackage(outputPackage);
|
||||
|
||||
int refs = pkg.FrameworkAssemblies.Count();
|
||||
this.Log().Info("Found {0} refs", refs);
|
||||
refs.ShouldEqual(0);
|
||||
|
||||
this.Log().Info("Files in release package:");
|
||||
|
||||
List<ZipPackageFile> files = pkg.Files.ToList();
|
||||
files.ForEach(x => this.Log().Info(x.Path));
|
||||
|
||||
List<string> nonDesktopPaths = new[] { "sl", "winrt", "netcore", "win8", "windows8", "MonoAndroid", "MonoTouch", "MonoMac", "wp", }
|
||||
.Select(x => @"lib\" + x)
|
||||
.ToList();
|
||||
|
||||
files.Any(x => nonDesktopPaths.Any(y => x.Path.ToLowerInvariant().Contains(y.ToLowerInvariant()))).ShouldBeFalse();
|
||||
files.Any(x => x.Path.ToLowerInvariant().EndsWith(@".xml")).ShouldBeFalse();
|
||||
} finally {
|
||||
File.Delete(outputPackage);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanLoadPackageWhichHasNoDependencies()
|
||||
{
|
||||
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.NoDependencies.1.0.0.0.nupkg");
|
||||
var outputPackage = Path.GetTempFileName() + ".nupkg";
|
||||
var fixture = new ReleasePackageBuilder(inputPackage);
|
||||
try {
|
||||
fixture.CreateReleasePackage(outputPackage);
|
||||
} finally {
|
||||
File.Delete(outputPackage);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThrowsIfLoadsPackageWithDependencies()
|
||||
{
|
||||
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectDependsOnJsonDotNet.1.0.nupkg");
|
||||
var outputPackage = Path.GetTempFileName() + ".nupkg";
|
||||
var fixture = new ReleasePackageBuilder(inputPackage);
|
||||
try {
|
||||
Assert.Throws<InvalidOperationException>(() => fixture.CreateReleasePackage(outputPackage));
|
||||
} finally {
|
||||
if (File.Exists(outputPackage))
|
||||
File.Delete(outputPackage);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SpecFileMarkdownRenderingTest()
|
||||
{
|
||||
var dontcare = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
|
||||
var inputSpec = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nuspec");
|
||||
var fixture = new ReleasePackageBuilder(dontcare);
|
||||
|
||||
var targetFile = Path.GetTempFileName();
|
||||
File.Copy(inputSpec, targetFile, true);
|
||||
|
||||
try {
|
||||
var processor = new Func<string, string>(input =>
|
||||
(new Markdown()).Transform(input));
|
||||
|
||||
// NB: For No Reason At All, renderReleaseNotesMarkdown is
|
||||
// invulnerable to ExposedObject. Whyyyyyyyyy
|
||||
var renderMinfo = fixture.GetType().GetMethod("renderReleaseNotesMarkdown",
|
||||
BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
renderMinfo.Invoke(fixture, new object[] { targetFile, processor });
|
||||
|
||||
var mani = NuspecManifest.ParseFromFile(targetFile);
|
||||
this.Log().Info("HTML Text:\n{0}", mani.ReleaseNotesHtml);
|
||||
|
||||
mani.ReleaseNotes.Contains("## Release Notes").ShouldBeTrue();
|
||||
mani.ReleaseNotesHtml.Contains("## Release Notes").ShouldBeFalse();
|
||||
mani.ReleaseNotesHtml.Contains("<h2>Release Notes").ShouldBeTrue();
|
||||
} finally {
|
||||
File.Delete(targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContentFilesAreIncludedInCreatedPackage()
|
||||
{
|
||||
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectWithContent.1.0.0.0-beta.nupkg");
|
||||
var outputPackage = Path.GetTempFileName() + ".zip";
|
||||
var fixture = new ReleasePackageBuilder(inputPackage);
|
||||
|
||||
try {
|
||||
fixture.CreateReleasePackage(outputPackage);
|
||||
|
||||
this.Log().Info("Resulting package is at {0}", outputPackage);
|
||||
var pkg = new ZipPackage(outputPackage);
|
||||
|
||||
int refs = pkg.FrameworkAssemblies.Count();
|
||||
this.Log().Info("Found {0} refs", refs);
|
||||
refs.ShouldEqual(0);
|
||||
|
||||
this.Log().Info("Files in release package:");
|
||||
|
||||
var contentFiles = pkg.Files.Where(f => f.IsContentFile()).ToArray();
|
||||
Assert.Equal(2, contentFiles.Count());
|
||||
|
||||
var contentFilePaths = contentFiles.Select(f => f.EffectivePath);
|
||||
|
||||
Assert.Contains("some-words.txt", contentFilePaths);
|
||||
Assert.Contains("dir\\item-in-subdirectory.txt", contentFilePaths);
|
||||
|
||||
Assert.Equal(1, pkg.Files.Where(f => f.IsLibFile()).Count());
|
||||
} finally {
|
||||
File.Delete(outputPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,11 @@ namespace Squirrel.Tests
|
||||
{
|
||||
public class RuntimeTests
|
||||
{
|
||||
// we are upgrading net6 to a minimum version of 6.0.2 to work
|
||||
// around a dotnet SDK bug right now.
|
||||
[Theory]
|
||||
[InlineData("net6", "net6.0.2-x64-desktop")]
|
||||
[InlineData("net6.0", "net6.0.2-x64-desktop")]
|
||||
[InlineData("net6-x64", "net6.0.2-x64-desktop")]
|
||||
[InlineData("net6-x86", "net6.0.2-x86-desktop")]
|
||||
[InlineData("net6", "net6-x64-desktop")]
|
||||
[InlineData("net6.0", "net6-x64-desktop")]
|
||||
[InlineData("net6-x64", "net6-x64-desktop")]
|
||||
[InlineData("net6-x86", "net6-x86-desktop")]
|
||||
[InlineData("net3.1", "netcoreapp3.1-x64-desktop")]
|
||||
[InlineData("netcoreapp3.1", "netcoreapp3.1-x64-desktop")]
|
||||
[InlineData("net3.1-x86", "netcoreapp3.1-x86-desktop")]
|
||||
@@ -21,7 +19,7 @@ namespace Squirrel.Tests
|
||||
[InlineData("net6.0.2-x86", "net6.0.2-x86-desktop")]
|
||||
[InlineData("net6.0.1-x86", "net6.0.1-x86-desktop")]
|
||||
[InlineData("net6.0.0", "net6-x64-desktop")]
|
||||
[InlineData("net6.0-x64-desktop", "net6.0.2-x64-desktop")]
|
||||
[InlineData("net6.0-x64-desktop", "net6-x64-desktop")]
|
||||
[InlineData("net7.0-x64-runtime", "net7-x64-runtime")]
|
||||
[InlineData("net7.0-x64-asp", "net7-x64-asp")]
|
||||
[InlineData("net7.0-desktop", "net7-x64-desktop")]
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
<PackageReference Include="xunit" Version="2.6.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5" PrivateAssets="All" />
|
||||
<PackageReference Include="System.IO.Packaging" Version="8.0.0" />
|
||||
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
|
||||
<PackageReference Include="Divergic.Logging.Xunit" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Squirrel.CommandLine\Squirrel.CommandLine.csproj" />
|
||||
<ProjectReference Include="..\..\src\Squirrel\Squirrel.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Squirrel.Tests.TestHelpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public class SquirrelAwareExecutableDetectorTests
|
||||
{
|
||||
[Fact]
|
||||
public void AtomShellShouldBeSquirrelAware()
|
||||
{
|
||||
var target = IntegrationTestHelper.GetPath("fixtures", "atom.exe");
|
||||
|
||||
Assert.True(File.Exists(target));
|
||||
Assert.True(SquirrelAwareExecutableDetector.GetSquirrelAwareVersion(target) == 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SquirrelAwareViaLanguageNeutralVersionBlock()
|
||||
{
|
||||
var target = IntegrationTestHelper.GetPath("fixtures", "SquirrelAwareTweakedNetCoreApp.exe");
|
||||
Assert.True(File.Exists(target));
|
||||
|
||||
var ret = SquirrelAwareExecutableDetector.GetSquirrelAwareVersion(target);
|
||||
Assert.Equal(1, ret.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotSquirrelAwareTestAppShouldNotBeSquirrelAware()
|
||||
{
|
||||
var target = IntegrationTestHelper.GetPath("fixtures", "NotSquirrelAwareApp.exe");
|
||||
Assert.True(File.Exists(target));
|
||||
|
||||
Assert.Null(SquirrelAwareExecutableDetector.GetSquirrelAwareVersion(target));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SquirrelAwareViaManifest()
|
||||
{
|
||||
var target = IntegrationTestHelper.GetPath("fixtures", "PublishSingleFileAwareApp.exe");
|
||||
Assert.True(File.Exists(target));
|
||||
|
||||
var ret = SquirrelAwareExecutableDetector.GetSquirrelAwareVersion(target);
|
||||
Assert.Equal(1, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Squirrel;
|
||||
using Squirrel.SimpleSplat;
|
||||
using Xunit;
|
||||
using System.Text;
|
||||
using Squirrel.CommandLine;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace Squirrel.Tests.TestHelpers
|
||||
@@ -70,42 +68,42 @@ namespace Squirrel.Tests.TestHelpers
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static string CreateFakeInstalledApp(string version, string outputDir, string nuspecFile = null)
|
||||
{
|
||||
string targetDir;
|
||||
//public static string CreateFakeInstalledApp(string version, string outputDir, string nuspecFile = null)
|
||||
//{
|
||||
// string targetDir;
|
||||
|
||||
nuspecFile = nuspecFile ?? "SquirrelInstalledApp.nuspec";
|
||||
// nuspecFile = nuspecFile ?? "SquirrelInstalledApp.nuspec";
|
||||
|
||||
using (var clearTemp = Utility.GetTempDirectory(out targetDir)) {
|
||||
var nuspec = File.ReadAllText(IntegrationTestHelper.GetPath("fixtures", nuspecFile), Encoding.UTF8);
|
||||
var nuspecPath = Path.Combine(targetDir, nuspecFile);
|
||||
// using (var clearTemp = Utility.GetTempDirectory(out targetDir)) {
|
||||
// var nuspec = File.ReadAllText(IntegrationTestHelper.GetPath("fixtures", nuspecFile), Encoding.UTF8);
|
||||
// var nuspecPath = Path.Combine(targetDir, nuspecFile);
|
||||
|
||||
File.WriteAllText(nuspecPath, nuspec.Replace("0.1.0", version), Encoding.UTF8);
|
||||
// File.WriteAllText(nuspecPath, nuspec.Replace("0.1.0", version), Encoding.UTF8);
|
||||
|
||||
File.Copy(
|
||||
IntegrationTestHelper.GetPath("fixtures", "PublishSingleFileAwareApp.exe"),
|
||||
Path.Combine(targetDir, "SquirrelAwareApp.exe"));
|
||||
File.Copy(
|
||||
IntegrationTestHelper.GetPath("fixtures", "NotSquirrelAwareApp.exe"),
|
||||
Path.Combine(targetDir, "NotSquirrelAwareApp.exe"));
|
||||
// File.Copy(
|
||||
// IntegrationTestHelper.GetPath("fixtures", "PublishSingleFileAwareApp.exe"),
|
||||
// Path.Combine(targetDir, "SquirrelAwareApp.exe"));
|
||||
// File.Copy(
|
||||
// IntegrationTestHelper.GetPath("fixtures", "NotSquirrelAwareApp.exe"),
|
||||
// Path.Combine(targetDir, "NotSquirrelAwareApp.exe"));
|
||||
|
||||
new NugetConsole().Pack(nuspecPath, targetDir, targetDir);
|
||||
// new NugetConsole().Pack(nuspecPath, targetDir, targetDir);
|
||||
|
||||
var di = new DirectoryInfo(targetDir);
|
||||
var pkg = di.EnumerateFiles("*.nupkg").First();
|
||||
// var di = new DirectoryInfo(targetDir);
|
||||
// var pkg = di.EnumerateFiles("*.nupkg").First();
|
||||
|
||||
var targetPkgFile = Path.Combine(outputDir, pkg.Name);
|
||||
File.Copy(pkg.FullName, targetPkgFile);
|
||||
return targetPkgFile;
|
||||
}
|
||||
}
|
||||
// var targetPkgFile = Path.Combine(outputDir, pkg.Name);
|
||||
// File.Copy(pkg.FullName, targetPkgFile);
|
||||
// return targetPkgFile;
|
||||
// }
|
||||
//}
|
||||
|
||||
public static void CreateNewVersionInPackageDir(string version, string outputDir, string nuspecFile = null)
|
||||
{
|
||||
var pkgFile = CreateFakeInstalledApp(version, outputDir, nuspecFile);
|
||||
var pkgs = ReleaseEntry.BuildReleasesFile(outputDir);
|
||||
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(outputDir, "RELEASES"));
|
||||
}
|
||||
//public static void CreateNewVersionInPackageDir(string version, string outputDir, string nuspecFile = null)
|
||||
//{
|
||||
// var pkgFile = CreateFakeInstalledApp(version, outputDir, nuspecFile);
|
||||
// var pkgs = ReleaseEntry.BuildReleasesFile(outputDir);
|
||||
// ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(outputDir, "RELEASES"));
|
||||
//}
|
||||
|
||||
public static IDisposable WithFakeInstallDirectory(out string path)
|
||||
{
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Squirrel.SimpleSplat;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public interface ITestLogging
|
||||
{
|
||||
IFullLogger Log();
|
||||
}
|
||||
|
||||
public class TestLogger : ILogger
|
||||
{
|
||||
public LogLevel Level { get; set; }
|
||||
public ITestOutputHelper OutputHelper { get; }
|
||||
|
||||
public TestLogger(ITestOutputHelper outputHelper)
|
||||
{
|
||||
OutputHelper = outputHelper;
|
||||
}
|
||||
|
||||
public void Write([Localizable(false)] string message, LogLevel logLevel)
|
||||
{
|
||||
OutputHelper.WriteLine(message);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class TestLoggingBase : ITestLogging
|
||||
{
|
||||
public ITestOutputHelper OutputHelper { get; }
|
||||
public IFullLogger Logger { get; }
|
||||
|
||||
public TestLoggingBase(ITestOutputHelper log)
|
||||
{
|
||||
OutputHelper = log;
|
||||
Logger = new WrappingFullLogger(new TestLogger(OutputHelper), typeof(TestLogger));
|
||||
}
|
||||
|
||||
public IFullLogger Log()
|
||||
{
|
||||
return Logger;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Squirrel.Sources;
|
||||
|
||||
namespace Squirrel.Tests.TestHelpers
|
||||
{
|
||||
class UpdateManagerTestImpl : UpdateManager
|
||||
{
|
||||
protected UpdateManagerTestImpl(IUpdateSource source, AppDesc config) : base(source, config)
|
||||
{
|
||||
}
|
||||
|
||||
public static UpdateManagerTestImpl FromLocalPackageTempDir(string updatePackageDir, string appId, string installTempDir)
|
||||
{
|
||||
var di = String.IsNullOrWhiteSpace(updatePackageDir) ? null : new DirectoryInfo(updatePackageDir);
|
||||
return FromLocalPackageTempDir(di, appId, installTempDir);
|
||||
}
|
||||
|
||||
public static UpdateManagerTestImpl FromLocalPackageTempDir(DirectoryInfo updatePackageDir, string appId, string installTempDir)
|
||||
{
|
||||
var appPath = Path.Combine(installTempDir, appId);
|
||||
Directory.CreateDirectory(appPath);
|
||||
var desc = new AppDescWindows(appPath, appId);
|
||||
return new UpdateManagerTestImpl(new SimpleFileSource(updatePackageDir), desc);
|
||||
}
|
||||
|
||||
public static UpdateManagerTestImpl FromFakeWebSource(string packageUrl, string appId, string installTempDir, IFileDownloader downloader = null)
|
||||
{
|
||||
var appPath = Path.Combine(installTempDir, appId);
|
||||
Directory.CreateDirectory(appPath);
|
||||
var desc = new AppDescWindows(appPath, appId);
|
||||
return new UpdateManagerTestImpl(new SimpleWebSource(packageUrl, downloader), desc);
|
||||
}
|
||||
|
||||
public Task<string> ApplyReleasesPublic(UpdateInfo updateInfo, bool silentInstall, bool attemptingFullInstall, Action<int> progress = null)
|
||||
{
|
||||
return this.ApplyReleases(updateInfo, silentInstall, attemptingFullInstall, progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
527
test/Squirrel.Tests/UpdateManager/ApplyReleasesTests.cs
Normal file
527
test/Squirrel.Tests/UpdateManager/ApplyReleasesTests.cs
Normal file
@@ -0,0 +1,527 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Diagnostics;
|
||||
//using System.IO;
|
||||
//using System.Linq;
|
||||
//using System.Reflection;
|
||||
//using System.Text;
|
||||
//using System.Threading;
|
||||
//using System.Threading.Tasks;
|
||||
//using NuGet.Versioning;
|
||||
//using Squirrel.NuGet;
|
||||
//using Squirrel.Tests.TestHelpers;
|
||||
//using Xunit;
|
||||
//using Xunit.Abstractions;
|
||||
|
||||
//namespace Squirrel.Tests
|
||||
//{
|
||||
// public class ApplyReleasesTests : TestLoggingBase
|
||||
// {
|
||||
// public ApplyReleasesTests(ITestOutputHelper log) : base(log)
|
||||
// {
|
||||
// }
|
||||
|
||||
// public const string APP_ID = "theFakeApp";
|
||||
|
||||
// [Fact]
|
||||
// public async Task CleanInstallRunsSquirrelAwareAppsWithInstallFlag()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir);
|
||||
// await fixture.FullInstall();
|
||||
|
||||
// // NB: We execute the Squirrel-aware apps, so we need to give
|
||||
// // them a minute to settle or else the using statement will
|
||||
// // try to blow away a running process
|
||||
// await Task.Delay(1000);
|
||||
|
||||
// Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "current", "args2.txt")));
|
||||
// Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "current", "args.txt")));
|
||||
|
||||
// var text = File.ReadAllText(Path.Combine(tempDir, APP_ID, "current", "args.txt"), Encoding.UTF8);
|
||||
// Assert.Contains("firstrun", text);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task UpgradeRunsSquirrelAwareAppsWithUpgradeFlag()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
// await fixture.FullInstall();
|
||||
// }
|
||||
|
||||
// await Task.Delay(1000);
|
||||
|
||||
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
||||
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
// await fixture.UpdateApp();
|
||||
// }
|
||||
|
||||
// await Task.Delay(1000);
|
||||
|
||||
// Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args2.txt")));
|
||||
// Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args.txt")));
|
||||
|
||||
// var text = File.ReadAllText(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args.txt"), Encoding.UTF8);
|
||||
// Assert.Contains("updated", text);
|
||||
// Assert.Contains("0.2.0", text);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task RunningUpgradeAppTwiceDoesntCrash()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
// await fixture.FullInstall();
|
||||
// }
|
||||
|
||||
// await Task.Delay(1000);
|
||||
|
||||
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
||||
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
// await fixture.UpdateApp();
|
||||
// }
|
||||
|
||||
// await Task.Delay(1000);
|
||||
|
||||
// // NB: The 2nd time we won't have any updates to apply. We should just do nothing!
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
// await fixture.UpdateApp();
|
||||
// }
|
||||
|
||||
// await Task.Delay(1000);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task FullUninstallRemovesAllVersions()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
// await fixture.FullInstall();
|
||||
// }
|
||||
|
||||
// await Task.Delay(1000);
|
||||
|
||||
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
||||
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
// await fixture.UpdateApp();
|
||||
// }
|
||||
|
||||
// await Task.Delay(1000);
|
||||
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||
// await fixture.FullUninstall();
|
||||
// }
|
||||
|
||||
// Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "app-0.1.0", "args.txt")));
|
||||
// Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "app-0.2.0", "args.txt")));
|
||||
// Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, ".dead")));
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CanInstallAndUpdatePackageWithDotsInId()
|
||||
// {
|
||||
// string tempDir;
|
||||
// string remotePkgDir;
|
||||
// const string pkgName = "Squirrel.Installed.App";
|
||||
|
||||
// using (Utility.GetTempDirectory(out tempDir))
|
||||
// using (Utility.GetTempDirectory(out remotePkgDir)) {
|
||||
// // install 0.1.0
|
||||
// IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir, "SquirrelInstalledAppWithDots.nuspec");
|
||||
// var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
|
||||
// ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
|
||||
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
||||
// await fixture.FullInstall();
|
||||
// }
|
||||
|
||||
// //Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "app-0.1.0")));
|
||||
// Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "current")));
|
||||
|
||||
// var info = new AppDescWindows(Path.Combine(tempDir, pkgName), pkgName);
|
||||
|
||||
// var version = info.GetVersions().Single();
|
||||
// Assert.True(version.IsCurrent);
|
||||
// Assert.Equal(new SemanticVersion(0, 1, 0), version.Manifest.Version);
|
||||
|
||||
// await Task.Delay(1000);
|
||||
// Assert.True(File.ReadAllText(Path.Combine(version.DirectoryPath, "args.txt")).Contains("--squirrel-firstrun"));
|
||||
|
||||
// // update top 0.2.0
|
||||
// IntegrationTestHelper.CreateFakeInstalledApp("0.2.0", remotePkgDir, "SquirrelInstalledAppWithDots.nuspec");
|
||||
// pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
|
||||
// ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
|
||||
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
||||
// await fixture.UpdateApp();
|
||||
// }
|
||||
|
||||
// info.UpdateAndRetrieveCurrentFolder(false);
|
||||
|
||||
// var versions = info.GetVersions().ToArray();
|
||||
// Assert.Equal(2, versions.Count());
|
||||
// Assert.Equal(new SemanticVersion(0, 2, 0), versions.Single(s => s.IsCurrent).Version);
|
||||
|
||||
// //Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "app-0.2.0")));
|
||||
// await Task.Delay(1000);
|
||||
|
||||
// // uninstall
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
||||
// await fixture.FullUninstall();
|
||||
// }
|
||||
|
||||
// Assert.False(File.Exists(Path.Combine(tempDir, pkgName, "app-0.1.0", "args.txt")));
|
||||
// Assert.False(File.Exists(Path.Combine(tempDir, pkgName, "app-0.2.0", "args.txt")));
|
||||
// Assert.True(File.Exists(Path.Combine(tempDir, pkgName, ".dead")));
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void WhenNoNewReleasesAreAvailableTheListIsEmpty()
|
||||
// {
|
||||
// using var _ = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
// var appDir = Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
||||
// var packages = Path.Combine(appDir.FullName, "packages");
|
||||
// Directory.CreateDirectory(packages);
|
||||
|
||||
// var package = "Squirrel.Core.1.0.0.0-full.nupkg";
|
||||
// File.Copy(IntegrationTestHelper.GetPath("fixtures", package), Path.Combine(packages, package));
|
||||
|
||||
// var aGivenPackage = Path.Combine(packages, package);
|
||||
// var baseEntry = ReleaseEntry.GenerateFromFile(aGivenPackage);
|
||||
|
||||
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { baseEntry }, "dontcare");
|
||||
|
||||
// Assert.Empty(updateInfo.ReleasesToApply);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void ThrowsWhenOnlyDeltaReleasesAreAvailable()
|
||||
// {
|
||||
// string tempDir;
|
||||
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||
// var appDir = Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
||||
// var packages = Path.Combine(appDir.FullName, "packages");
|
||||
// Directory.CreateDirectory(packages);
|
||||
|
||||
// var baseFile = "Squirrel.Core.1.0.0.0-full.nupkg";
|
||||
// File.Copy(IntegrationTestHelper.GetPath("fixtures", baseFile),
|
||||
// Path.Combine(packages, baseFile));
|
||||
// var basePackage = Path.Combine(packages, baseFile);
|
||||
// var baseEntry = ReleaseEntry.GenerateFromFile(basePackage);
|
||||
|
||||
// var deltaFile = "Squirrel.Core.1.1.0.0-delta.nupkg";
|
||||
// File.Copy(IntegrationTestHelper.GetPath("fixtures", deltaFile),
|
||||
// Path.Combine(packages, deltaFile));
|
||||
// var deltaPackage = Path.Combine(packages, deltaFile);
|
||||
// var deltaEntry = ReleaseEntry.GenerateFromFile(deltaPackage);
|
||||
|
||||
// Assert.Throws<Exception>(
|
||||
// () => UpdateInfo.Create(baseEntry, new[] { deltaEntry }, "dontcare"));
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task ApplyReleasesWithOneReleaseFile()
|
||||
// {
|
||||
// string tempDir;
|
||||
|
||||
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||
// string packagesDir = Path.Combine(appDir, "packages");
|
||||
// Directory.CreateDirectory(packagesDir);
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.0.0.0-full.nupkg"));
|
||||
// var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||
|
||||
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
||||
// updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
||||
|
||||
// var progress = new List<int>();
|
||||
|
||||
// await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
// progress
|
||||
// .Aggregate(0, (acc, x) => {
|
||||
// (x >= acc).ShouldBeTrue();
|
||||
// return x;
|
||||
// })
|
||||
// .ShouldEqual(100);
|
||||
|
||||
// var filesToFind = new[] {
|
||||
// new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||
// new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||
// };
|
||||
|
||||
// filesToFind.ForEach(x => {
|
||||
// var path = Path.Combine(tempDir, APP_ID, "staging", "app-1.1.0.0", x.Name);
|
||||
// this.Log().Info("Looking for {0}", path);
|
||||
// File.Exists(path).ShouldBeTrue();
|
||||
|
||||
// var vi = FileVersionInfo.GetVersionInfo(path);
|
||||
// var verInfo = new Version(vi.FileVersion ?? "1.0.0.0");
|
||||
// x.Version.ShouldEqual(verInfo);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task ApplyReleaseWhichRemovesAFile()
|
||||
// {
|
||||
// string tempDir;
|
||||
|
||||
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||
// string packagesDir = Path.Combine(appDir, "packages");
|
||||
// Directory.CreateDirectory(packagesDir);
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.2.0.0-full.nupkg",
|
||||
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||
// var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.2.0.0-full.nupkg"));
|
||||
|
||||
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
||||
// updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
||||
|
||||
// var progress = new List<int>();
|
||||
// await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
// progress
|
||||
// .Aggregate(0, (acc, x) => {
|
||||
// (x >= acc).ShouldBeTrue();
|
||||
// return x;
|
||||
// })
|
||||
// .ShouldEqual(100);
|
||||
|
||||
// var rootDirectory = Path.Combine(tempDir, APP_ID, "staging", "app-1.2.0.0");
|
||||
|
||||
// new[] {
|
||||
// new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||
// new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||
// }.ForEach(x => {
|
||||
// var path = Path.Combine(rootDirectory, x.Name);
|
||||
// this.Log().Info("Looking for {0}", path);
|
||||
// File.Exists(path).ShouldBeTrue();
|
||||
// });
|
||||
|
||||
// var removedFile = Path.Combine("sub", "Ionic.Zip.dll");
|
||||
// var deployedPath = Path.Combine(rootDirectory, removedFile);
|
||||
// File.Exists(deployedPath).ShouldBeFalse();
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task ApplyReleaseWhichMovesAFileToADifferentDirectory()
|
||||
// {
|
||||
// string tempDir;
|
||||
|
||||
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||
// string packagesDir = Path.Combine(appDir, "packages");
|
||||
// Directory.CreateDirectory(packagesDir);
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.3.0.0-full.nupkg",
|
||||
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||
// var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.3.0.0-full.nupkg"));
|
||||
|
||||
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
||||
// updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
||||
|
||||
// var progress = new List<int>();
|
||||
// await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
// progress
|
||||
// .Aggregate(0, (acc, x) => {
|
||||
// (x >= acc).ShouldBeTrue();
|
||||
// return x;
|
||||
// })
|
||||
// .ShouldEqual(100);
|
||||
|
||||
// var rootDirectory = Path.Combine(tempDir, APP_ID, "staging", "app-1.3.0.0");
|
||||
|
||||
// new[] {
|
||||
// new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||
// new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||
// }.ForEach(x => {
|
||||
// var path = Path.Combine(rootDirectory, x.Name);
|
||||
// this.Log().Info("Looking for {0}", path);
|
||||
// File.Exists(path).ShouldBeTrue();
|
||||
// });
|
||||
|
||||
// var oldFile = Path.Combine(rootDirectory, "sub", "Ionic.Zip.dll");
|
||||
// File.Exists(oldFile).ShouldBeFalse();
|
||||
|
||||
// var newFile = Path.Combine(rootDirectory, "other", "Ionic.Zip.dll");
|
||||
// File.Exists(newFile).ShouldBeTrue();
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task ApplyReleasesWithDeltaReleases()
|
||||
// {
|
||||
// string tempDir;
|
||||
|
||||
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||
// string packagesDir = Path.Combine(appDir, "packages");
|
||||
// Directory.CreateDirectory(packagesDir);
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.0.0.0-full.nupkg"));
|
||||
// var deltaEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-delta.nupkg"));
|
||||
// var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||
|
||||
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { deltaEntry, latestFullEntry }, packagesDir);
|
||||
// updateInfo.ReleasesToApply.Contains(deltaEntry).ShouldBeTrue();
|
||||
|
||||
// var progress = new List<int>();
|
||||
|
||||
// await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
// // TODO: this is failing intermittently, not sure why but is not a big deal atm
|
||||
// // progress
|
||||
// // .Aggregate(0, (acc, x) => { (x >= acc).ShouldBeTrue(); return x; })
|
||||
// // .ShouldEqual(100);
|
||||
|
||||
// var filesToFind = new[] {
|
||||
// new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||
// new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||
// };
|
||||
|
||||
// filesToFind.ForEach(x => {
|
||||
// var path = Path.Combine(tempDir, APP_ID, "staging", "app-1.1.0.0", x.Name);
|
||||
// this.Log().Info("Looking for {0}", path);
|
||||
// File.Exists(path).ShouldBeTrue();
|
||||
|
||||
// var vi = FileVersionInfo.GetVersionInfo(path);
|
||||
// var verInfo = new Version(vi.FileVersion ?? "1.0.0.0");
|
||||
// x.Version.ShouldEqual(verInfo);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CreateFullPackagesFromDeltaSmokeTest()
|
||||
// {
|
||||
// string tempDir;
|
||||
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||
// string packagesDir = Path.Combine(appDir, "packages");
|
||||
// Directory.CreateDirectory(packagesDir);
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-delta.nupkg"
|
||||
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(tempDir, APP_ID, "packages", x)));
|
||||
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||
|
||||
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(tempDir, APP_ID, "packages", "Squirrel.Core.1.0.0.0-full.nupkg"));
|
||||
// var deltaEntry = ReleaseEntry.GenerateFromFile(Path.Combine(tempDir, APP_ID, "packages", "Squirrel.Core.1.1.0.0-delta.nupkg"));
|
||||
|
||||
// var result = fixture.createFullPackagesFromDeltas(new[] { deltaEntry }, baseEntry, null);
|
||||
|
||||
// var zp = new ZipPackage(Path.Combine(tempDir, APP_ID, "packages", result.Filename));
|
||||
// zp.Version.ToString().ShouldEqual("1.1.0.0");
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CreateShortcutsRoundTrip()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir);
|
||||
// await fixture.FullInstall();
|
||||
|
||||
// fixture.CreateShortcutsForExecutable("SquirrelAwareApp.exe",
|
||||
// ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot, false, null, null);
|
||||
|
||||
// Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "PublishSingleFileAwareApp.lnk")));
|
||||
|
||||
// // NB: COM is Weird.
|
||||
// Thread.Sleep(1000);
|
||||
// fixture.RemoveShortcutsForExecutable("SquirrelAwareApp.exe",
|
||||
// ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot);
|
||||
|
||||
// // NB: Squirrel-Aware first-run might still be running, slow
|
||||
// // our roll before blowing away the temp path
|
||||
// Thread.Sleep(1000);
|
||||
// }
|
||||
|
||||
// //[Fact]
|
||||
// //public async Task GetShortcutsSmokeTest()
|
||||
// //{
|
||||
// // string remotePkgPath;
|
||||
// // string path;
|
||||
|
||||
// // using (Utility.WithTempDirectory(out path)) {
|
||||
// // using (Utility.WithTempDirectory(out remotePkgPath))
|
||||
// // using (var mgr = new UpdateManager(remotePkgPath, APP_ID, path)) {
|
||||
// // IntegrationTestHelper.CreateFakeInstalledApp("1.0.0.1", remotePkgPath);
|
||||
// // await mgr.FullInstall();
|
||||
// // }
|
||||
|
||||
// // var fixture = new ApplyReleasesImpl(Path.Combine(path, APP_ID));
|
||||
// // var result = fixture.GetShortcutsForExecutable("SquirrelAwareApp.exe", ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup, null);
|
||||
|
||||
// // Assert.Equal(3, result.Keys.Count);
|
||||
|
||||
// // // NB: Squirrel-Aware first-run might still be running, slow
|
||||
// // // our roll before blowing away the temp path
|
||||
// // Thread.Sleep(1000);
|
||||
// // }
|
||||
// //}
|
||||
// }
|
||||
//}
|
||||
178
test/Squirrel.Tests/UpdateManager/CheckForUpdateTests.cs
Normal file
178
test/Squirrel.Tests/UpdateManager/CheckForUpdateTests.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
//using System;
|
||||
//using System.IO;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
//using System.Web;
|
||||
//using Squirrel.Tests.TestHelpers;
|
||||
//using Xunit;
|
||||
|
||||
//namespace Squirrel.Tests
|
||||
//{
|
||||
// public class CheckForUpdateTests
|
||||
// {
|
||||
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||
// public void NewReleasesShouldBeDetected()
|
||||
// {
|
||||
// Assert.Fail("Rewrite this to be an integration test");
|
||||
// /*
|
||||
// string localReleasesFile = Path.Combine(".", "theApp", "packages", "RELEASES");
|
||||
|
||||
// var fileInfo = new Mock<FileInfoBase>();
|
||||
// fileInfo.Setup(x => x.OpenRead())
|
||||
// .Returns(File.OpenRead(IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOh")));
|
||||
|
||||
// var fs = new Mock<IFileSystemFactory>();
|
||||
// fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
||||
|
||||
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||
// var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
|
||||
// urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
||||
// .Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
|
||||
|
||||
// var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
||||
// var result = default(UpdateInfo);
|
||||
|
||||
// using (fixture) {
|
||||
// result = fixture.CheckForUpdate().First();
|
||||
// }
|
||||
|
||||
// Assert.NotNull(result);
|
||||
// Assert.Equal(1, result.ReleasesToApply.Single().Version.Major);
|
||||
// Assert.Equal(1, result.ReleasesToApply.Single().Version.Minor);
|
||||
// */
|
||||
// }
|
||||
|
||||
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||
// public void CorruptedReleaseFileMeansWeStartFromScratch()
|
||||
// {
|
||||
// Assert.Fail("Rewrite this to be an integration test");
|
||||
|
||||
// /*
|
||||
// string localPackagesDir = Path.Combine(".", "theApp", "packages");
|
||||
// string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
|
||||
|
||||
// var fileInfo = new Mock<FileInfoBase>();
|
||||
// fileInfo.Setup(x => x.Exists).Returns(true);
|
||||
// fileInfo.Setup(x => x.OpenRead())
|
||||
// .Returns(new MemoryStream(Encoding.UTF8.GetBytes("lol this isn't right")));
|
||||
|
||||
// var dirInfo = new Mock<DirectoryInfoBase>();
|
||||
// dirInfo.Setup(x => x.Exists).Returns(true);
|
||||
|
||||
// var fs = new Mock<IFileSystemFactory>();
|
||||
// fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
||||
// fs.Setup(x => x.CreateDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||
// fs.Setup(x => x.DeleteDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||
// fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
|
||||
|
||||
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||
// var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
|
||||
// urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
||||
// .Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
|
||||
|
||||
// var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
||||
// using (fixture) {
|
||||
// fixture.CheckForUpdate().First();
|
||||
// }
|
||||
|
||||
// fs.Verify(x => x.CreateDirectoryRecursive(localPackagesDir), Times.Once());
|
||||
// fs.Verify(x => x.DeleteDirectoryRecursive(localPackagesDir), Times.Once());
|
||||
// */
|
||||
// }
|
||||
|
||||
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||
// public void CorruptRemoteFileShouldThrowOnCheck()
|
||||
// {
|
||||
// Assert.Fail("Rewrite this to be an integration test");
|
||||
|
||||
// /*
|
||||
// string localPackagesDir = Path.Combine(".", "theApp", "packages");
|
||||
// string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
|
||||
|
||||
// var fileInfo = new Mock<FileInfoBase>();
|
||||
// fileInfo.Setup(x => x.Exists).Returns(false);
|
||||
|
||||
// var dirInfo = new Mock<DirectoryInfoBase>();
|
||||
// dirInfo.Setup(x => x.Exists).Returns(true);
|
||||
|
||||
// var fs = new Mock<IFileSystemFactory>();
|
||||
// fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
||||
// fs.Setup(x => x.CreateDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||
// fs.Setup(x => x.DeleteDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||
// fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
|
||||
|
||||
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||
// urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
||||
// .Returns(Observable.Return("lol this isn't right"));
|
||||
|
||||
// var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
||||
|
||||
// using (fixture) {
|
||||
// Assert.Throws<Exception>(() => fixture.CheckForUpdate().First());
|
||||
// }
|
||||
// */
|
||||
// }
|
||||
|
||||
// [Fact(Skip = "TODO")]
|
||||
// public void IfLocalVersionGreaterThanRemoteWeRollback()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// [Fact(Skip = "TODO")]
|
||||
// public void IfLocalAndRemoteAreEqualThenDoNothing()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// [Theory]
|
||||
// [InlineData(@"94689fede03fed7ab59c24337673a27837f0c3ec MyCoolApp-1.0.nupkg 1004502", "MyCoolApp", null)]
|
||||
// [InlineData(@"0000000000000000000000000000000000000000 https://www.test.org/Folder/MyCoolApp-1.2-delta.nupkg?query=param 1231953", "MyCoolApp", "https://www.test.org/Folder")]
|
||||
// public async Task WebSourceRequestsExpectedUrls(string releaseEntry, string releaseName, string baseUrl)
|
||||
// {
|
||||
// baseUrl = baseUrl ?? "https://example.com/files";
|
||||
// var dl = new FakeDownloader();
|
||||
// var source = new Sources.SimpleWebSource("https://example.com/files", dl);
|
||||
|
||||
// dl.MockedResponseBytes = Encoding.UTF8.GetBytes(releaseEntry);
|
||||
// var releases = await source.GetReleaseFeed(null, null);
|
||||
// Assert.True(releases.Count() == 1);
|
||||
// Assert.Equal(releaseName, releases[0].PackageName);
|
||||
// Assert.Equal("https://example.com/files/RELEASES", new Uri(dl.LastUrl).GetLeftPart(UriPartial.Path));
|
||||
|
||||
// await source.DownloadReleaseEntry(releases[0], "test", null);
|
||||
// Assert.Equal(baseUrl + "/" + releases[0].Filename, new Uri(dl.LastUrl).GetLeftPart(UriPartial.Path));
|
||||
// }
|
||||
|
||||
// [Theory]
|
||||
// [InlineData("http://example.com", "MyPackage.nupkg", "http://example.com/MyPackage.nupkg")]
|
||||
// [InlineData("http://example.com?auth=hello", "MyPackage.nupkg", "http://example.com/MyPackage.nupkg?auth=hello")]
|
||||
// [InlineData("http://example.com?auth=hello", "https://my.packages.domain/MyPackage-1.0.0.nupkg", "https://my.packages.domain/MyPackage-1.0.0.nupkg")]
|
||||
// public async Task SimpleWebSourcePreservesQueryParametersAndAbsoluteReleaseUri(string baseUri, string releaseUri, string expectedPackageUrl)
|
||||
// {
|
||||
// var dl = new FakeDownloader();
|
||||
// var source = new Sources.SimpleWebSource(baseUri, dl);
|
||||
// var baseKvp = HttpUtility.ParseQueryString(new Uri(baseUri).Query);
|
||||
// var baseDict = baseKvp.AllKeys.Where(k => k != null).ToDictionary(k => k, k => baseKvp[k]);
|
||||
|
||||
// var releaseEntry = $"94689fede03fed7ab59c24337673a27837f0c3ec {releaseUri} 1004502";
|
||||
// dl.MockedResponseBytes = Encoding.UTF8.GetBytes(releaseEntry);
|
||||
|
||||
// var releases = await source.GetReleaseFeed();
|
||||
// var expected = new Uri(baseUri).GetLeftPart(UriPartial.Path).TrimEnd('/') + "/RELEASES";
|
||||
// Assert.StartsWith(expected, dl.LastUrl);
|
||||
|
||||
// // check that each query parameter in base url is in the releases string
|
||||
// var releasesUri = new Uri(dl.LastUrl);
|
||||
// var releasesKvp = HttpUtility.ParseQueryString(releasesUri.Query);
|
||||
// var releasesDict = releasesKvp.AllKeys.Where(k => k != null).ToDictionary(k => k, k => releasesKvp[k]);
|
||||
// foreach (var kvp in baseDict) {
|
||||
// Assert.Equal(releasesDict[kvp.Key], kvp.Value);
|
||||
// }
|
||||
|
||||
// await source.DownloadReleaseEntry(releases[0], "test", null);
|
||||
// Assert.Equal(expectedPackageUrl, dl.LastUrl);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
194
test/Squirrel.Tests/UpdateManager/DownloadReleasesTests.cs
Normal file
194
test/Squirrel.Tests/UpdateManager/DownloadReleasesTests.cs
Normal file
@@ -0,0 +1,194 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.IO;
|
||||
//using System.Linq;
|
||||
//using System.Net;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
//using Squirrel.SimpleSplat;
|
||||
//using Squirrel.Tests.TestHelpers;
|
||||
//using Xunit;
|
||||
|
||||
//namespace Squirrel.Tests
|
||||
//{
|
||||
// public class DownloadReleasesTests
|
||||
// {
|
||||
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||
// public void ChecksumShouldFailIfFilesAreMissing()
|
||||
// {
|
||||
// Assert.Fail("Rewrite this to be an integration test");
|
||||
|
||||
// /*
|
||||
// var filename = "Squirrel.Core.1.0.0.0.nupkg";
|
||||
// var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
|
||||
// var fs = new Mock<IFileSystemFactory>();
|
||||
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||
|
||||
// ReleaseEntry entry;
|
||||
// using (var f = File.OpenRead(nuGetPkg)) {
|
||||
// entry = ReleaseEntry.GenerateFromFile(f, filename);
|
||||
// }
|
||||
|
||||
// var fileInfo = new Mock<FileInfoBase>();
|
||||
// fileInfo.Setup(x => x.OpenRead()).Returns(File.OpenRead(nuGetPkg));
|
||||
// fileInfo.Setup(x => x.Exists).Returns(false);
|
||||
|
||||
// fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
|
||||
|
||||
// var fixture = ExposedObject.From(
|
||||
// new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
|
||||
|
||||
// bool shouldDie = true;
|
||||
// try {
|
||||
// // NB: We can't use Assert.Throws here because the binder
|
||||
// // will try to pick the wrong method
|
||||
// fixture.checksumPackage(entry);
|
||||
// } catch (Exception) {
|
||||
// shouldDie = false;
|
||||
// }
|
||||
|
||||
// shouldDie.ShouldBeFalse();
|
||||
// */
|
||||
// }
|
||||
|
||||
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||
// public void ChecksumShouldFailIfFilesAreBogus()
|
||||
// {
|
||||
// Assert.Fail("Rewrite this to be an integration test");
|
||||
|
||||
// /*
|
||||
// var filename = "Squirrel.Core.1.0.0.0.nupkg";
|
||||
// var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
|
||||
// var fs = new Mock<IFileSystemFactory>();
|
||||
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||
|
||||
// ReleaseEntry entry;
|
||||
// using (var f = File.OpenRead(nuGetPkg)) {
|
||||
// entry = ReleaseEntry.GenerateFromFile(f, filename);
|
||||
// }
|
||||
|
||||
// var fileInfo = new Mock<FileInfoBase>();
|
||||
// fileInfo.Setup(x => x.OpenRead()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("Lol broken")));
|
||||
// fileInfo.Setup(x => x.Exists).Returns(true);
|
||||
// fileInfo.Setup(x => x.Length).Returns(new FileInfo(nuGetPkg).Length);
|
||||
// fileInfo.Setup(x => x.Delete()).Verifiable();
|
||||
|
||||
// fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
|
||||
|
||||
// var fixture = ExposedObject.From(
|
||||
// new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
|
||||
|
||||
// bool shouldDie = true;
|
||||
// try {
|
||||
// fixture.checksumPackage(entry);
|
||||
// } catch (Exception ex) {
|
||||
// this.Log().InfoException("Checksum failure", ex);
|
||||
// shouldDie = false;
|
||||
// }
|
||||
|
||||
// shouldDie.ShouldBeFalse();
|
||||
// fileInfo.Verify(x => x.Delete(), Times.Once());
|
||||
// */
|
||||
// }
|
||||
|
||||
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||
// public async Task DownloadReleasesFromHttpServerIntegrationTest()
|
||||
// {
|
||||
// Assert.Fail("Rewrite this to not use the SampleUpdatingApp");
|
||||
|
||||
// /*
|
||||
// string tempDir = null;
|
||||
|
||||
// var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
|
||||
|
||||
// IDisposable disp;
|
||||
// try {
|
||||
// var httpServer = new StaticHttpServer(30405, updateDir.FullName);
|
||||
// disp = httpServer.Start();
|
||||
// } catch (HttpListenerException) {
|
||||
// Assert.False(true, @"Windows sucks, go run 'netsh http add urlacl url=http://+:30405/ user=MYMACHINE\MyUser");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// var entriesToDownload = updateDir.GetFiles("*.nupkg")
|
||||
// .Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
|
||||
// .ToArray();
|
||||
|
||||
// entriesToDownload.Count().ShouldBeGreaterThan(0);
|
||||
|
||||
// using (disp)
|
||||
// using (Utility.WithTempDirectory(out tempDir)) {
|
||||
// // NB: This is normally done by CheckForUpdates, but since
|
||||
// // we're skipping that in the test we have to do it ourselves
|
||||
// Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
|
||||
|
||||
// var fixture = new UpdateManager("http://localhost:30405", "SampleUpdatingApp", tempDir);
|
||||
// using (fixture) {
|
||||
// var progress = new List<int>();
|
||||
// await fixture.DownloadReleases(entriesToDownload, progress.Add);
|
||||
|
||||
// progress
|
||||
// .Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
|
||||
// .ShouldEqual(100);
|
||||
// }
|
||||
|
||||
// entriesToDownload.ForEach(x => {
|
||||
// this.Log().Info("Looking for {0}", x.Filename);
|
||||
// var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
|
||||
// File.Exists(actualFile).ShouldBeTrue();
|
||||
|
||||
// var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
|
||||
// actualEntry.SHA1.ShouldEqual(x.SHA1);
|
||||
// actualEntry.Version.ShouldEqual(x.Version);
|
||||
// });
|
||||
// }
|
||||
// */
|
||||
// }
|
||||
|
||||
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||
// public async Task DownloadReleasesFromFileDirectoryIntegrationTest()
|
||||
// {
|
||||
// Assert.Fail("Rewrite this to not use the SampleUpdatingApp");
|
||||
|
||||
// /*
|
||||
// string tempDir = null;
|
||||
|
||||
// var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
|
||||
|
||||
// var entriesToDownload = updateDir.GetFiles("*.nupkg")
|
||||
// .Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
|
||||
// .ToArray();
|
||||
|
||||
// entriesToDownload.Count().ShouldBeGreaterThan(0);
|
||||
|
||||
// using (Utility.WithTempDirectory(out tempDir)) {
|
||||
// // NB: This is normally done by CheckForUpdates, but since
|
||||
// // we're skipping that in the test we have to do it ourselves
|
||||
// Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
|
||||
|
||||
// var fixture = new UpdateManager(updateDir.FullName, "SampleUpdatingApp", tempDir);
|
||||
// using (fixture) {
|
||||
// var progress = new List<int>();
|
||||
|
||||
// await fixture.DownloadReleases(entriesToDownload, progress.Add);
|
||||
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||
|
||||
// progress
|
||||
// .Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
|
||||
// .ShouldEqual(100);
|
||||
// }
|
||||
|
||||
// entriesToDownload.ForEach(x => {
|
||||
// this.Log().Info("Looking for {0}", x.Filename);
|
||||
// var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
|
||||
// File.Exists(actualFile).ShouldBeTrue();
|
||||
|
||||
// var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
|
||||
// actualEntry.SHA1.ShouldEqual(x.SHA1);
|
||||
// actualEntry.Version.ShouldEqual(x.Version);
|
||||
// });
|
||||
// }
|
||||
// */
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
367
test/Squirrel.Tests/UpdateManager/UpdateManagerTests.cs
Normal file
367
test/Squirrel.Tests/UpdateManager/UpdateManagerTests.cs
Normal file
@@ -0,0 +1,367 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.IO;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading;
|
||||
//using System.Threading.Tasks;
|
||||
//using Microsoft.Win32;
|
||||
//using Squirrel;
|
||||
//using Squirrel.Tests.TestHelpers;
|
||||
//using Xunit;
|
||||
//using System.Net;
|
||||
//using Squirrel.NuGet;
|
||||
//using System.Net.Http;
|
||||
//using NuGet.Versioning;
|
||||
//using Squirrel.Sources;
|
||||
|
||||
//namespace Squirrel.Tests
|
||||
//{
|
||||
// public class UpdateManagerTests
|
||||
// {
|
||||
// public const string APP_ID = "theFakeApp";
|
||||
|
||||
// public class CreateUninstallerRegKeyTests
|
||||
// {
|
||||
// [Fact]
|
||||
// public async Task CallingMethodTwiceShouldUpdateInstaller()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var path);
|
||||
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, path))
|
||||
// await fixture.FullInstall();
|
||||
|
||||
// using (var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, path)) {
|
||||
// await mgr.CreateUninstallerRegistryEntry();
|
||||
// var regKey = await mgr.CreateUninstallerRegistryEntry();
|
||||
|
||||
// Assert.False(String.IsNullOrWhiteSpace((string) regKey.GetValue("DisplayName")));
|
||||
|
||||
// mgr.RemoveUninstallerRegistryEntry();
|
||||
// }
|
||||
|
||||
// // NB: Squirrel-Aware first-run might still be running, slow
|
||||
// // our roll before blowing away the temp path
|
||||
// Thread.Sleep(1000);
|
||||
|
||||
// var key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default)
|
||||
// .OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
|
||||
// using (key) {
|
||||
// Assert.False(key.GetSubKeyNames().Contains(APP_ID));
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class UpdateLocalReleasesTests
|
||||
// {
|
||||
// [Fact]
|
||||
// public async Task UpdateLocalReleasesSmokeTest()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
// var appDir = Path.Combine(tempDir, APP_ID);
|
||||
// var packageDir = Directory.CreateDirectory(Path.Combine(appDir, "packages"));
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(tempDir, APP_ID, "packages", x)));
|
||||
|
||||
// var info = new AppDescWindows(appDir, APP_ID);
|
||||
// ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||
|
||||
// var releasePath = Path.Combine(packageDir.FullName, "RELEASES");
|
||||
// File.Exists(releasePath).ShouldBeTrue();
|
||||
|
||||
// var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
||||
// entries.Count().ShouldEqual(3);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task InitialInstallSmokeTest()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
// var remotePackageDir = Directory.CreateDirectory(Path.Combine(tempDir, "remotePackages"));
|
||||
// var localAppDir = Path.Combine(tempDir, APP_ID);
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(remotePackageDir.FullName, x)));
|
||||
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackageDir.FullName, APP_ID, tempDir);
|
||||
// await fixture.FullInstall();
|
||||
|
||||
// var releasePath = Path.Combine(localAppDir, "packages", "RELEASES");
|
||||
// File.Exists(releasePath).ShouldBeTrue();
|
||||
|
||||
// var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
||||
// entries.Count().ShouldEqual(1);
|
||||
|
||||
// Assert.True(File.Exists(Path.Combine(localAppDir, "current", "ReactiveUI.dll")));
|
||||
// Assert.True(File.Exists(Path.Combine(localAppDir, "current", "NSync.Core.dll")));
|
||||
|
||||
// var manifest = NuspecManifest.ParseFromFile(Path.Combine(localAppDir, "current", Utility.SpecVersionFileName));
|
||||
// Assert.Equal(new NuGetVersion(1, 0, 0, 0), manifest.Version);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task SpecialCharactersInitialInstallTest()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
// var remotePackageDir = Directory.CreateDirectory(Path.Combine(tempDir, "remotePackages"));
|
||||
// var localAppDir = Path.Combine(tempDir, APP_ID);
|
||||
|
||||
// new[] {
|
||||
// "SpecialCharacters-0.1.0-full.nupkg",
|
||||
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(remotePackageDir.FullName, x)));
|
||||
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackageDir.FullName, APP_ID, tempDir);
|
||||
// await fixture.FullInstall();
|
||||
|
||||
// var releasePath = Path.Combine(localAppDir, "packages", "RELEASES");
|
||||
// File.Exists(releasePath).ShouldBeTrue();
|
||||
|
||||
// var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
||||
// entries.Count().ShouldEqual(1);
|
||||
|
||||
// new[] {
|
||||
// "file space name.txt"
|
||||
// }.ForEach(x => File.Exists(Path.Combine(localAppDir, "current", x)).ShouldBeTrue());
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task WhenBothFilesAreInSyncNoUpdatesAreApplied()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
// var appDir = Path.Combine(tempDir, APP_ID);
|
||||
// var localPackages = Path.Combine(appDir, "packages");
|
||||
// var remotePackages = Path.Combine(tempDir, "releases");
|
||||
// Directory.CreateDirectory(localPackages);
|
||||
// Directory.CreateDirectory(remotePackages);
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
// }.ForEach(x => {
|
||||
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
// File.Copy(path, Path.Combine(localPackages, x));
|
||||
// File.Copy(path, Path.Combine(remotePackages, x));
|
||||
// });
|
||||
|
||||
// // sync both release files
|
||||
// var info = new AppDescWindows(appDir, APP_ID);
|
||||
// ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||
// ReleaseEntry.BuildReleasesFile(remotePackages);
|
||||
|
||||
// // check for an update
|
||||
// using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
||||
// UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
||||
|
||||
// Assert.NotNull(updateInfo);
|
||||
// Assert.Empty(updateInfo.ReleasesToApply);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task WhenRemoteReleasesDoNotHaveDeltasNoUpdatesAreApplied()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
// var appDir = Path.Combine(tempDir, APP_ID);
|
||||
// var localPackages = Path.Combine(appDir, "packages");
|
||||
// var remotePackages = Path.Combine(tempDir, "releases");
|
||||
// Directory.CreateDirectory(localPackages);
|
||||
// Directory.CreateDirectory(remotePackages);
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
// }.ForEach(x => {
|
||||
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
// File.Copy(path, Path.Combine(localPackages, x));
|
||||
// });
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
// }.ForEach(x => {
|
||||
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
// File.Copy(path, Path.Combine(remotePackages, x));
|
||||
// });
|
||||
|
||||
// // sync both release files
|
||||
// var info = new AppDescWindows(appDir, APP_ID);
|
||||
// ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||
// ReleaseEntry.BuildReleasesFile(remotePackages);
|
||||
|
||||
// using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
||||
// UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
||||
|
||||
// Assert.NotNull(updateInfo);
|
||||
// Assert.Empty(updateInfo.ReleasesToApply);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task WhenTwoRemoteUpdatesAreAvailableChoosesDeltaVersion()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
// var appDir = Path.Combine(tempDir, APP_ID);
|
||||
// var localPackages = Path.Combine(appDir, "packages");
|
||||
// var remotePackages = Path.Combine(tempDir, "releases");
|
||||
// Directory.CreateDirectory(localPackages);
|
||||
// Directory.CreateDirectory(remotePackages);
|
||||
|
||||
// new[] { "Squirrel.Core.1.0.0.0-full.nupkg", }.ForEach(x => {
|
||||
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
// File.Copy(path, Path.Combine(localPackages, x));
|
||||
// });
|
||||
|
||||
// new[] {
|
||||
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
// }.ForEach(x => {
|
||||
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
// File.Copy(path, Path.Combine(remotePackages, x));
|
||||
// });
|
||||
|
||||
// // sync both release files
|
||||
// var info = new AppDescWindows(appDir, APP_ID);
|
||||
// ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||
// ReleaseEntry.BuildReleasesFile(remotePackages);
|
||||
|
||||
// using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
||||
// UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
||||
|
||||
// Assert.True(updateInfo.ReleasesToApply.First().IsDelta);
|
||||
|
||||
// updateInfo = await mgr.CheckForUpdate(ignoreDeltaUpdates: true);
|
||||
// Assert.False(updateInfo.ReleasesToApply.First().IsDelta);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task WhenFolderDoesNotExistThrowHelpfulError()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
// var directory = Path.Combine(tempDir, "missing-folder");
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
||||
// await Assert.ThrowsAsync<Exception>(() => fixture.CheckForUpdate());
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task WhenReleasesFileDoesntExistThrowACustomError()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
// var directory = Path.Combine(tempDir, "folder");
|
||||
// Directory.CreateDirectory(directory);
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
||||
// await Assert.ThrowsAsync<Exception>(() => fixture.CheckForUpdate());
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task WhenReleasesFileIsBlankThrowAnException()
|
||||
// {
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
// var directory = Path.Combine(tempDir, "folder");
|
||||
// Directory.CreateDirectory(directory);
|
||||
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
||||
// File.WriteAllText(Path.Combine(directory, "RELEASES"), "");
|
||||
// await Assert.ThrowsAsync(typeof(Exception), () => fixture.CheckForUpdate());
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task WhenUrlResultsInWebExceptionWeShouldThrow()
|
||||
// {
|
||||
// // This should result in a WebException (which gets caught) unless you can actually access http://lol
|
||||
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
// using var fixture = UpdateManagerTestImpl.FromFakeWebSource("http://lol", APP_ID, tempDir);
|
||||
// await Assert.ThrowsAsync(typeof(HttpRequestException), () => fixture.CheckForUpdate());
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void IsInstalledHandlesInvalidDirectoryStructure()
|
||||
// {
|
||||
// using (Utility.GetTempDirectory(out var tempDir)) {
|
||||
// Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
||||
// Directory.CreateDirectory(Path.Combine(tempDir, APP_ID, "app-1.0.1"));
|
||||
// Directory.CreateDirectory(Path.Combine(tempDir, APP_ID, "wrongDir"));
|
||||
// File.WriteAllText(Path.Combine(tempDir, APP_ID, "Update.exe"), "1");
|
||||
// using (var fixture = UpdateManagerTestImpl.FromFakeWebSource("http://lol", APP_ID, tempDir)) {
|
||||
// Assert.Null(new AppDescWindows(Path.Combine(tempDir, "app.exe")).CurrentlyInstalledVersion);
|
||||
// Assert.Null(new AppDescWindows(Path.Combine(tempDir, APP_ID, "app.exe")).CurrentlyInstalledVersion);
|
||||
// Assert.Null(new AppDescWindows(Path.Combine(tempDir, APP_ID, "wrongDir", "app.exe")).CurrentlyInstalledVersion);
|
||||
// Assert.Equal(new SemanticVersion(1, 0, 9),
|
||||
// new AppDescWindows(Path.Combine(tempDir, APP_ID, "app-1.0.9", "app.exe")).CurrentlyInstalledVersion);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void CurrentlyInstalledVersionDoesNotThrow()
|
||||
// {
|
||||
// using var fixture = new UpdateManager();
|
||||
// Assert.Null(fixture.CurrentlyInstalledVersion());
|
||||
// Assert.False(fixture.IsInstalledApp);
|
||||
// }
|
||||
|
||||
// [Theory]
|
||||
// [InlineData(0, 0, 25, 0)]
|
||||
// [InlineData(12, 0, 25, 3)]
|
||||
// [InlineData(55, 0, 25, 13)]
|
||||
// [InlineData(100, 0, 25, 25)]
|
||||
// [InlineData(0, 25, 50, 25)]
|
||||
// [InlineData(12, 25, 50, 28)]
|
||||
// [InlineData(55, 25, 50, 38)]
|
||||
// [InlineData(100, 25, 50, 50)]
|
||||
// public void CalculatesPercentageCorrectly(int percentageOfCurrentStep, int stepStartPercentage, int stepEndPercentage, int expectedPercentage)
|
||||
// {
|
||||
// var percentage = Utility.CalculateProgress(percentageOfCurrentStep, stepStartPercentage, stepEndPercentage);
|
||||
|
||||
// Assert.Equal(expectedPercentage, percentage);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public void CalculatesPercentageCorrectlyForUpdateExe()
|
||||
// {
|
||||
// // Note: this mimicks the update.exe progress reporting of multiple steps
|
||||
|
||||
// var progress = new List<int>();
|
||||
|
||||
// // 3 % (3 stages), check for updates
|
||||
// foreach (var step in new[] { 0, 33, 66, 100 }) {
|
||||
// progress.Add(Utility.CalculateProgress(step, 0, 3));
|
||||
|
||||
// Assert.InRange(progress.Last(), 0, 3);
|
||||
// }
|
||||
|
||||
// Assert.Equal(3, progress.Last());
|
||||
|
||||
// // 3 - 30 %, download releases
|
||||
// for (var step = 0; step <= 100; step++) {
|
||||
// progress.Add(Utility.CalculateProgress(step, 3, 30));
|
||||
|
||||
// Assert.InRange(progress.Last(), 3, 30);
|
||||
// }
|
||||
|
||||
// Assert.Equal(30, progress.Last());
|
||||
|
||||
// // 30 - 100 %, apply releases
|
||||
// for (var step = 0; step <= 100; step++) {
|
||||
// progress.Add(Utility.CalculateProgress(step, 30, 100));
|
||||
|
||||
// Assert.InRange(progress.Last(), 30, 100);
|
||||
// }
|
||||
|
||||
// Assert.Equal(100, progress.Last());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -1,367 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Win32;
|
||||
using Squirrel;
|
||||
using Squirrel.Tests.TestHelpers;
|
||||
using Xunit;
|
||||
using System.Net;
|
||||
using Squirrel.NuGet;
|
||||
using System.Net.Http;
|
||||
using NuGet.Versioning;
|
||||
using Squirrel.Sources;
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public class UpdateManagerTests
|
||||
{
|
||||
public const string APP_ID = "theFakeApp";
|
||||
|
||||
public class CreateUninstallerRegKeyTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task CallingMethodTwiceShouldUpdateInstaller()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var path);
|
||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||
|
||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, path))
|
||||
await fixture.FullInstall();
|
||||
|
||||
using (var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, path)) {
|
||||
await mgr.CreateUninstallerRegistryEntry();
|
||||
var regKey = await mgr.CreateUninstallerRegistryEntry();
|
||||
|
||||
Assert.False(String.IsNullOrWhiteSpace((string) regKey.GetValue("DisplayName")));
|
||||
|
||||
mgr.RemoveUninstallerRegistryEntry();
|
||||
}
|
||||
|
||||
// NB: Squirrel-Aware first-run might still be running, slow
|
||||
// our roll before blowing away the temp path
|
||||
Thread.Sleep(1000);
|
||||
|
||||
var key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default)
|
||||
.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
|
||||
using (key) {
|
||||
Assert.False(key.GetSubKeyNames().Contains(APP_ID));
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateLocalReleasesTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task UpdateLocalReleasesSmokeTest()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
var appDir = Path.Combine(tempDir, APP_ID);
|
||||
var packageDir = Directory.CreateDirectory(Path.Combine(appDir, "packages"));
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(tempDir, APP_ID, "packages", x)));
|
||||
|
||||
var info = new AppDescWindows(appDir, APP_ID);
|
||||
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||
|
||||
var releasePath = Path.Combine(packageDir.FullName, "RELEASES");
|
||||
File.Exists(releasePath).ShouldBeTrue();
|
||||
|
||||
var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
||||
entries.Count().ShouldEqual(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitialInstallSmokeTest()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
var remotePackageDir = Directory.CreateDirectory(Path.Combine(tempDir, "remotePackages"));
|
||||
var localAppDir = Path.Combine(tempDir, APP_ID);
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(remotePackageDir.FullName, x)));
|
||||
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackageDir.FullName, APP_ID, tempDir);
|
||||
await fixture.FullInstall();
|
||||
|
||||
var releasePath = Path.Combine(localAppDir, "packages", "RELEASES");
|
||||
File.Exists(releasePath).ShouldBeTrue();
|
||||
|
||||
var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
||||
entries.Count().ShouldEqual(1);
|
||||
|
||||
Assert.True(File.Exists(Path.Combine(localAppDir, "current", "ReactiveUI.dll")));
|
||||
Assert.True(File.Exists(Path.Combine(localAppDir, "current", "NSync.Core.dll")));
|
||||
|
||||
var manifest = NuspecManifest.ParseFromFile(Path.Combine(localAppDir, "current", Utility.SpecVersionFileName));
|
||||
Assert.Equal(new NuGetVersion(1, 0, 0, 0), manifest.Version);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SpecialCharactersInitialInstallTest()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
var remotePackageDir = Directory.CreateDirectory(Path.Combine(tempDir, "remotePackages"));
|
||||
var localAppDir = Path.Combine(tempDir, APP_ID);
|
||||
|
||||
new[] {
|
||||
"SpecialCharacters-0.1.0-full.nupkg",
|
||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(remotePackageDir.FullName, x)));
|
||||
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackageDir.FullName, APP_ID, tempDir);
|
||||
await fixture.FullInstall();
|
||||
|
||||
var releasePath = Path.Combine(localAppDir, "packages", "RELEASES");
|
||||
File.Exists(releasePath).ShouldBeTrue();
|
||||
|
||||
var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
||||
entries.Count().ShouldEqual(1);
|
||||
|
||||
new[] {
|
||||
"file space name.txt"
|
||||
}.ForEach(x => File.Exists(Path.Combine(localAppDir, "current", x)).ShouldBeTrue());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WhenBothFilesAreInSyncNoUpdatesAreApplied()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
var appDir = Path.Combine(tempDir, APP_ID);
|
||||
var localPackages = Path.Combine(appDir, "packages");
|
||||
var remotePackages = Path.Combine(tempDir, "releases");
|
||||
Directory.CreateDirectory(localPackages);
|
||||
Directory.CreateDirectory(remotePackages);
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
}.ForEach(x => {
|
||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
File.Copy(path, Path.Combine(localPackages, x));
|
||||
File.Copy(path, Path.Combine(remotePackages, x));
|
||||
});
|
||||
|
||||
// sync both release files
|
||||
var info = new AppDescWindows(appDir, APP_ID);
|
||||
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||
ReleaseEntry.BuildReleasesFile(remotePackages);
|
||||
|
||||
// check for an update
|
||||
using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
||||
UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
||||
|
||||
Assert.NotNull(updateInfo);
|
||||
Assert.Empty(updateInfo.ReleasesToApply);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WhenRemoteReleasesDoNotHaveDeltasNoUpdatesAreApplied()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
var appDir = Path.Combine(tempDir, APP_ID);
|
||||
var localPackages = Path.Combine(appDir, "packages");
|
||||
var remotePackages = Path.Combine(tempDir, "releases");
|
||||
Directory.CreateDirectory(localPackages);
|
||||
Directory.CreateDirectory(remotePackages);
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
}.ForEach(x => {
|
||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
File.Copy(path, Path.Combine(localPackages, x));
|
||||
});
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
}.ForEach(x => {
|
||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
File.Copy(path, Path.Combine(remotePackages, x));
|
||||
});
|
||||
|
||||
// sync both release files
|
||||
var info = new AppDescWindows(appDir, APP_ID);
|
||||
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||
ReleaseEntry.BuildReleasesFile(remotePackages);
|
||||
|
||||
using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
||||
UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
||||
|
||||
Assert.NotNull(updateInfo);
|
||||
Assert.Empty(updateInfo.ReleasesToApply);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WhenTwoRemoteUpdatesAreAvailableChoosesDeltaVersion()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
var appDir = Path.Combine(tempDir, APP_ID);
|
||||
var localPackages = Path.Combine(appDir, "packages");
|
||||
var remotePackages = Path.Combine(tempDir, "releases");
|
||||
Directory.CreateDirectory(localPackages);
|
||||
Directory.CreateDirectory(remotePackages);
|
||||
|
||||
new[] { "Squirrel.Core.1.0.0.0-full.nupkg", }.ForEach(x => {
|
||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
File.Copy(path, Path.Combine(localPackages, x));
|
||||
});
|
||||
|
||||
new[] {
|
||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
||||
}.ForEach(x => {
|
||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||
File.Copy(path, Path.Combine(remotePackages, x));
|
||||
});
|
||||
|
||||
// sync both release files
|
||||
var info = new AppDescWindows(appDir, APP_ID);
|
||||
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||
ReleaseEntry.BuildReleasesFile(remotePackages);
|
||||
|
||||
using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
||||
UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
||||
|
||||
Assert.True(updateInfo.ReleasesToApply.First().IsDelta);
|
||||
|
||||
updateInfo = await mgr.CheckForUpdate(ignoreDeltaUpdates: true);
|
||||
Assert.False(updateInfo.ReleasesToApply.First().IsDelta);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WhenFolderDoesNotExistThrowHelpfulError()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
var directory = Path.Combine(tempDir, "missing-folder");
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
||||
await Assert.ThrowsAsync<Exception>(() => fixture.CheckForUpdate());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WhenReleasesFileDoesntExistThrowACustomError()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
var directory = Path.Combine(tempDir, "folder");
|
||||
Directory.CreateDirectory(directory);
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
||||
await Assert.ThrowsAsync<Exception>(() => fixture.CheckForUpdate());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WhenReleasesFileIsBlankThrowAnException()
|
||||
{
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
var directory = Path.Combine(tempDir, "folder");
|
||||
Directory.CreateDirectory(directory);
|
||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
||||
File.WriteAllText(Path.Combine(directory, "RELEASES"), "");
|
||||
await Assert.ThrowsAsync(typeof(Exception), () => fixture.CheckForUpdate());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WhenUrlResultsInWebExceptionWeShouldThrow()
|
||||
{
|
||||
// This should result in a WebException (which gets caught) unless you can actually access http://lol
|
||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||
using var fixture = UpdateManagerTestImpl.FromFakeWebSource("http://lol", APP_ID, tempDir);
|
||||
await Assert.ThrowsAsync(typeof(HttpRequestException), () => fixture.CheckForUpdate());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsInstalledHandlesInvalidDirectoryStructure()
|
||||
{
|
||||
using (Utility.GetTempDirectory(out var tempDir)) {
|
||||
Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
||||
Directory.CreateDirectory(Path.Combine(tempDir, APP_ID, "app-1.0.1"));
|
||||
Directory.CreateDirectory(Path.Combine(tempDir, APP_ID, "wrongDir"));
|
||||
File.WriteAllText(Path.Combine(tempDir, APP_ID, "Update.exe"), "1");
|
||||
using (var fixture = UpdateManagerTestImpl.FromFakeWebSource("http://lol", APP_ID, tempDir)) {
|
||||
Assert.Null(new AppDescWindows(Path.Combine(tempDir, "app.exe")).CurrentlyInstalledVersion);
|
||||
Assert.Null(new AppDescWindows(Path.Combine(tempDir, APP_ID, "app.exe")).CurrentlyInstalledVersion);
|
||||
Assert.Null(new AppDescWindows(Path.Combine(tempDir, APP_ID, "wrongDir", "app.exe")).CurrentlyInstalledVersion);
|
||||
Assert.Equal(new SemanticVersion(1, 0, 9),
|
||||
new AppDescWindows(Path.Combine(tempDir, APP_ID, "app-1.0.9", "app.exe")).CurrentlyInstalledVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CurrentlyInstalledVersionDoesNotThrow()
|
||||
{
|
||||
using var fixture = new UpdateManager();
|
||||
Assert.Null(fixture.CurrentlyInstalledVersion());
|
||||
Assert.False(fixture.IsInstalledApp);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0, 25, 0)]
|
||||
[InlineData(12, 0, 25, 3)]
|
||||
[InlineData(55, 0, 25, 13)]
|
||||
[InlineData(100, 0, 25, 25)]
|
||||
[InlineData(0, 25, 50, 25)]
|
||||
[InlineData(12, 25, 50, 28)]
|
||||
[InlineData(55, 25, 50, 38)]
|
||||
[InlineData(100, 25, 50, 50)]
|
||||
public void CalculatesPercentageCorrectly(int percentageOfCurrentStep, int stepStartPercentage, int stepEndPercentage, int expectedPercentage)
|
||||
{
|
||||
var percentage = Utility.CalculateProgress(percentageOfCurrentStep, stepStartPercentage, stepEndPercentage);
|
||||
|
||||
Assert.Equal(expectedPercentage, percentage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CalculatesPercentageCorrectlyForUpdateExe()
|
||||
{
|
||||
// Note: this mimicks the update.exe progress reporting of multiple steps
|
||||
|
||||
var progress = new List<int>();
|
||||
|
||||
// 3 % (3 stages), check for updates
|
||||
foreach (var step in new[] { 0, 33, 66, 100 }) {
|
||||
progress.Add(Utility.CalculateProgress(step, 0, 3));
|
||||
|
||||
Assert.InRange(progress.Last(), 0, 3);
|
||||
}
|
||||
|
||||
Assert.Equal(3, progress.Last());
|
||||
|
||||
// 3 - 30 %, download releases
|
||||
for (var step = 0; step <= 100; step++) {
|
||||
progress.Add(Utility.CalculateProgress(step, 3, 30));
|
||||
|
||||
Assert.InRange(progress.Last(), 3, 30);
|
||||
}
|
||||
|
||||
Assert.Equal(30, progress.Last());
|
||||
|
||||
// 30 - 100 %, apply releases
|
||||
for (var step = 0; step <= 100; step++) {
|
||||
progress.Add(Utility.CalculateProgress(step, 30, 100));
|
||||
|
||||
Assert.InRange(progress.Last(), 30, 100);
|
||||
}
|
||||
|
||||
Assert.Equal(100, progress.Last());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Squirrel.SimpleSplat;
|
||||
using Squirrel;
|
||||
using Squirrel.Tests.TestHelpers;
|
||||
using Xunit;
|
||||
@@ -15,10 +14,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Squirrel.Tests
|
||||
{
|
||||
public class UtilityTests : TestLoggingBase
|
||||
public class UtilityTests
|
||||
{
|
||||
public UtilityTests(ITestOutputHelper log) : base(log)
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public UtilityTests(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -122,6 +124,7 @@ namespace Squirrel.Tests
|
||||
[Fact]
|
||||
public void CanDeleteDeepRecursiveDirectoryStructure()
|
||||
{
|
||||
using var logger = _output.BuildLoggerFor<UtilityTests>();
|
||||
string tempDir;
|
||||
using (Utility.GetTempDirectory(out tempDir)) {
|
||||
for (var i = 0; i < 50; i++) {
|
||||
@@ -133,27 +136,27 @@ namespace Squirrel.Tests
|
||||
|
||||
var count = files.Count();
|
||||
|
||||
this.Log().Info("Created {0} files under directory {1}", count, tempDir);
|
||||
logger.Info($"Created {count} files under directory {tempDir}");
|
||||
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
Utility.DeleteFileOrDirectoryHard(tempDir);
|
||||
sw.Stop();
|
||||
this.Log().Info("Delete took {0}ms", sw.ElapsedMilliseconds);
|
||||
logger.Info($"Delete took {sw.ElapsedMilliseconds}ms");
|
||||
|
||||
Assert.False(Directory.Exists(tempDir));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateFakePackageSmokeTest()
|
||||
{
|
||||
string path;
|
||||
using (Utility.GetTempDirectory(out path)) {
|
||||
var output = IntegrationTestHelper.CreateFakeInstalledApp("0.3.0", path);
|
||||
Assert.True(File.Exists(output));
|
||||
}
|
||||
}
|
||||
//[Fact]
|
||||
//public void CreateFakePackageSmokeTest()
|
||||
//{
|
||||
// string path;
|
||||
// using (Utility.GetTempDirectory(out path)) {
|
||||
// var output = IntegrationTestHelper.CreateFakeInstalledApp("0.3.0", path);
|
||||
// Assert.True(File.Exists(output));
|
||||
// }
|
||||
//}
|
||||
|
||||
[Theory]
|
||||
[InlineData("foo.dll", true)]
|
||||
|
||||
Reference in New Issue
Block a user