From d31d152485b8f74a9db292d8ded1abedcf0820d0 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Wed, 20 Nov 2024 22:19:39 -0800 Subject: [PATCH] Update tests --- samples/CSharpWpf/App.xaml.cs | 27 ++++++++++++++ samples/CSharpWpf/CSharpWpf.csproj | 7 +++- samples/CSharpWpf/MainWindow.xaml.cs | 12 +++---- samples/CSharpWpf/Program.cs | 35 ------------------- .../CompatUtilTests.cs | 9 +++-- 5 files changed, 46 insertions(+), 44 deletions(-) delete mode 100644 samples/CSharpWpf/Program.cs diff --git a/samples/CSharpWpf/App.xaml.cs b/samples/CSharpWpf/App.xaml.cs index e1b69ac8..e1cc3bbb 100644 --- a/samples/CSharpWpf/App.xaml.cs +++ b/samples/CSharpWpf/App.xaml.cs @@ -1,8 +1,35 @@ using System.Windows; +using Velopack; namespace CSharpWpf { public partial class App : Application { + public static MemoryLogger Log { get; private set; } + + // Since WPF has an "automatic" Program.Main, we need to create our own. + // In order for this to work, you must also add the following to your .csproj: + // CSharpWpf.App + [STAThread] + private static void Main(string[] args) + { + try { + // Logging is essential for debugging! Ideally you should write it to a file. + Log = new MemoryLogger(); + + // It's important to Run() the VelopackApp as early as possible in app startup. + VelopackApp.Build() + .WithFirstRun((v) => { /* Your first run code here */ }) + .Run(Log); + + // We can now launch the WPF application as normal. + var app = new App(); + app.InitializeComponent(); + app.Run(); + + } catch (Exception ex) { + MessageBox.Show("Unhandled exception: " + ex.ToString()); + } + } } } diff --git a/samples/CSharpWpf/CSharpWpf.csproj b/samples/CSharpWpf/CSharpWpf.csproj index c5fafcbf..f0634209 100644 --- a/samples/CSharpWpf/CSharpWpf.csproj +++ b/samples/CSharpWpf/CSharpWpf.csproj @@ -10,9 +10,14 @@ - CSharpWpf.Program + CSharpWpf.App + + + + + diff --git a/samples/CSharpWpf/MainWindow.xaml.cs b/samples/CSharpWpf/MainWindow.xaml.cs index 93656d9b..1ad9f2f2 100644 --- a/samples/CSharpWpf/MainWindow.xaml.cs +++ b/samples/CSharpWpf/MainWindow.xaml.cs @@ -15,10 +15,10 @@ namespace CSharpWpf InitializeComponent(); string updateUrl = SampleHelper.GetReleasesDir(); // replace with your update url - _um = new UpdateManager(updateUrl, logger: Program.Log); + _um = new UpdateManager(updateUrl, logger: App.Log); - TextLog.Text = Program.Log.ToString(); - Program.Log.LogUpdated += LogUpdated; + TextLog.Text = App.Log.ToString(); + App.Log.LogUpdated += LogUpdated; UpdateStatus(); } @@ -29,7 +29,7 @@ namespace CSharpWpf // ConfigureAwait(true) so that UpdateStatus() is called on the UI thread _update = await _um.CheckForUpdatesAsync().ConfigureAwait(true); } catch (Exception ex) { - Program.Log.LogError(ex, "Error checking for updates"); + App.Log.LogError(ex, "Error checking for updates"); } UpdateStatus(); } @@ -41,7 +41,7 @@ namespace CSharpWpf // ConfigureAwait(true) so that UpdateStatus() is called on the UI thread await _um.DownloadUpdatesAsync(_update, Progress).ConfigureAwait(true); } catch (Exception ex) { - Program.Log.LogError(ex, "Error downloading updates"); + App.Log.LogError(ex, "Error downloading updates"); } UpdateStatus(); } @@ -70,7 +70,7 @@ namespace CSharpWpf private void Working() { - Program.Log.LogInformation(""); + App.Log.LogInformation(""); BtnCheckUpdate.IsEnabled = false; BtnDownloadUpdate.IsEnabled = false; BtnRestartApply.IsEnabled = false; diff --git a/samples/CSharpWpf/Program.cs b/samples/CSharpWpf/Program.cs deleted file mode 100644 index 339e04e2..00000000 --- a/samples/CSharpWpf/Program.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Windows; -using Velopack; - -namespace CSharpWpf -{ - // Since WPF has an "automatic" Program.Main, we need to create our own. - // In order for this to work, you must also add the following to your .csproj: - // CSharpWpf.Program - public class Program - { - public static MemoryLogger Log { get; private set; } - - [STAThread] - public static void Main(string[] args) - { - try { - // Logging is essential for debugging! Ideally you should write it to a file. - Log = new MemoryLogger(); - - // It's important to Run() the VelopackApp as early as possible in app startup. - VelopackApp.Build() - .WithFirstRun((v) => { /* Your first run code here */ }) - .Run(Log); - - // We can now launch the WPF application as normal. - var app = new App(); - app.InitializeComponent(); - app.Run(); - - } catch (Exception ex) { - MessageBox.Show("Unhandled exception: " + ex.ToString()); - } - } - } -} diff --git a/test/Velopack.Packaging.Tests/CompatUtilTests.cs b/test/Velopack.Packaging.Tests/CompatUtilTests.cs index 1d5467e4..049ba1ea 100644 --- a/test/Velopack.Packaging.Tests/CompatUtilTests.cs +++ b/test/Velopack.Packaging.Tests/CompatUtilTests.cs @@ -80,14 +80,19 @@ public class CompatUtilTests using var logger = GetCompat(out var compat); using var _1 = TempUtil.GetTempDirectory(out var dir); var sample = PathHelper.GetWpfSample(); - Exe.InvokeAndThrowIfNonZero( + string stdOut = Exe.InvokeAndThrowIfNonZero( "dotnet", new string[] { "publish", "-o", dir }, sample); var path = Path.Combine(dir, "VelopackCSharpWpf.exe"); Assert.NotNull(compat.Verify(path)); - + //We do not expect to see the warning about VelopackApp.Run() not being at the start of the main method + Assert.DoesNotContain(logger.Entries, logEntry => + logEntry.LogLevel == LogLevel.Warning && + logEntry.Message.Contains("VelopackApp.Run()") + ); + var newPath = Path.Combine(dir, "VelopackCSharpWpf-asd2.exe"); File.Move(path, newPath); Assert.NotNull(compat.Verify(newPath));