From 1518d1f0eac9375c4d32000c2ed6069b3a68e675 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 20 Aug 2014 17:15:57 -0700 Subject: [PATCH] Add a method to create fake squirrel-aware app packages at will --- test/TestHelpers/IntegrationTestHelper.cs | 43 +++++++++++++++++++++++ test/UtilityTests.cs | 10 ++++++ test/fixtures/SquirrelInstalledApp.nuspec | 14 ++++++++ 3 files changed, 67 insertions(+) create mode 100644 test/fixtures/SquirrelInstalledApp.nuspec diff --git a/test/TestHelpers/IntegrationTestHelper.cs b/test/TestHelpers/IntegrationTestHelper.cs index 09a2f59f..ac9b37ef 100644 --- a/test/TestHelpers/IntegrationTestHelper.cs +++ b/test/TestHelpers/IntegrationTestHelper.cs @@ -8,6 +8,7 @@ using Ionic.Zip; using Squirrel; using Splat; using Xunit; +using System.Text; namespace Squirrel.Tests.TestHelpers { @@ -69,6 +70,48 @@ namespace Squirrel.Tests.TestHelpers return ret; } + public static string CreateFakeInstalledApp(string version, string outputDir, string nuspecFile = null) + { + var targetDir = default(string); + + var nuget = IntegrationTestHelper.GetPath("..", ".nuget", "nuget.exe"); + nuspecFile = nuspecFile ?? "SquirrelInstalledApp.nuspec"; + + using (var clearTemp = Utility.WithTempDirectory(out targetDir)) { + var nuspec = File.ReadAllText(IntegrationTestHelper.GetPath("fixtures", nuspecFile), Encoding.UTF8); + File.WriteAllText(Path.Combine(targetDir, nuspecFile), nuspec.Replace("0.1.0", version), Encoding.UTF8); + + File.Copy( + IntegrationTestHelper.GetPath("fixtures", "SquirrelAwareApp.exe"), + Path.Combine(targetDir, "SquirrelAwareApp.exe")); + File.Copy( + IntegrationTestHelper.GetPath("fixtures", "NotSquirrelAwareApp.exe"), + Path.Combine(targetDir, "NotSquirrelAwareApp.exe")); + + var psi = new ProcessStartInfo(nuget, "pack " + Path.Combine(targetDir, nuspecFile)) { + RedirectStandardError = true, + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + WorkingDirectory = targetDir, + WindowStyle = ProcessWindowStyle.Hidden, + }; + + var pi = Process.Start(psi); + pi.WaitForExit(); + var output = pi.StandardOutput.ReadToEnd(); + var err = pi.StandardError.ReadToEnd(); + Console.WriteLine(output); Console.WriteLine(err); + + 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; + } + } + public static IDisposable WithFakeInstallDirectory(out string path) { return WithFakeInstallDirectory("SampleUpdatingApp.1.1.0.0.nupkg", out path); diff --git a/test/UtilityTests.cs b/test/UtilityTests.cs index 7b6d946b..7587c1be 100644 --- a/test/UtilityTests.cs +++ b/test/UtilityTests.cs @@ -52,6 +52,16 @@ namespace Squirrel.Tests.Core } } + [Fact] + public void CreateFakePackageSmokeTest() + { + string path; + using (Utility.WithTempDirectory(out path)) { + var output = IntegrationTestHelper.CreateFakeInstalledApp("0.3.0", path); + Assert.True(File.Exists(output)); + } + } + static void CreateSampleDirectory(string directory) { while (true) { diff --git a/test/fixtures/SquirrelInstalledApp.nuspec b/test/fixtures/SquirrelInstalledApp.nuspec new file mode 100644 index 00000000..3ac3e259 --- /dev/null +++ b/test/fixtures/SquirrelInstalledApp.nuspec @@ -0,0 +1,14 @@ + + + + SquirrelInstalledApp + 0.1.0 + paul + false + My package description. + + + + + + \ No newline at end of file