mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Update tests
This commit is contained in:
@@ -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:
|
||||
// <StartupObject>CSharpWpf.App</StartupObject>
|
||||
[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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,14 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- This overrides the default Program.Main that WPF creates for you, and allows you to add VelopackApp -->
|
||||
<StartupObject>CSharpWpf.Program</StartupObject>
|
||||
<StartupObject>CSharpWpf.App</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Remove="App.xaml" />
|
||||
<Page Include="App.xaml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!--Condition below is only needed to test this sample project against the local projects instead of the NuGet package. Remove it in your app.-->
|
||||
<PackageReference Include="Velopack" Version="0.*" Condition="$(UseLocalVelopack) == ''" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
// <StartupObject>CSharpWpf.Program</StartupObject>
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,13 +80,18 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user