diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index cfa9f6a..b864fe1 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -11,13 +11,12 @@ jobs: steps: - uses: actions/checkout@v2 - name: Setup .NET Core - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 7.0.x + dotnet-version: | + 6.0.x + 7.0.x + 8.0.x - name: Build and test shell: pwsh working-directory: ./scripts diff --git a/src/RolandK.AvaloniaExtensions.DependencyInjection.Tests/RolandK.AvaloniaExtensions.DependencyInjection.Tests.csproj b/src/RolandK.AvaloniaExtensions.DependencyInjection.Tests/RolandK.AvaloniaExtensions.DependencyInjection.Tests.csproj index f256c53..0752a5f 100644 --- a/src/RolandK.AvaloniaExtensions.DependencyInjection.Tests/RolandK.AvaloniaExtensions.DependencyInjection.Tests.csproj +++ b/src/RolandK.AvaloniaExtensions.DependencyInjection.Tests/RolandK.AvaloniaExtensions.DependencyInjection.Tests.csproj @@ -8,17 +8,17 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/src/RolandK.AvaloniaExtensions.DependencyInjection/RolandK.AvaloniaExtensions.DependencyInjection.csproj b/src/RolandK.AvaloniaExtensions.DependencyInjection/RolandK.AvaloniaExtensions.DependencyInjection.csproj index 3b22c3f..dcfd085 100644 --- a/src/RolandK.AvaloniaExtensions.DependencyInjection/RolandK.AvaloniaExtensions.DependencyInjection.csproj +++ b/src/RolandK.AvaloniaExtensions.DependencyInjection/RolandK.AvaloniaExtensions.DependencyInjection.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/RolandK.AvaloniaExtensions.TestApp/RolandK.AvaloniaExtensions.TestApp.csproj b/src/RolandK.AvaloniaExtensions.TestApp/RolandK.AvaloniaExtensions.TestApp.csproj index 6ca5984..f8bbc52 100644 --- a/src/RolandK.AvaloniaExtensions.TestApp/RolandK.AvaloniaExtensions.TestApp.csproj +++ b/src/RolandK.AvaloniaExtensions.TestApp/RolandK.AvaloniaExtensions.TestApp.csproj @@ -23,9 +23,9 @@ - - - + + + diff --git a/src/RolandK.AvaloniaExtensions.Tests/Mvvm/MvvmWindowTests.cs b/src/RolandK.AvaloniaExtensions.Tests/Mvvm/MvvmWindowTests.cs index 2e7a0af..2dda49f 100644 --- a/src/RolandK.AvaloniaExtensions.Tests/Mvvm/MvvmWindowTests.cs +++ b/src/RolandK.AvaloniaExtensions.Tests/Mvvm/MvvmWindowTests.cs @@ -61,7 +61,7 @@ await UnitTestApplication.RunInApplicationContextAsync(() => [Fact] public async Task Attach_MvvmWindow_to_ViewModel_then_close_using_ViewModel_with_dialog_result() { - await UnitTestApplication.RunInApplicationContextAsync(() => + await UnitTestApplication.RunInApplicationContextAsync(async Task () => { // Arrange var testViewModel = new TestViewModel(); @@ -76,9 +76,11 @@ await UnitTestApplication.RunInApplicationContextAsync(() => var dialogResult = new object(); testViewModel.TriggerCloseWindowRequest(dialogResult); + var showDialogTaskResult = await showDialogTask; + // Assert Assert.Equal(TaskStatus.RanToCompletion, showDialogTask.Status); - Assert.Equal(dialogResult, showDialogTask.Result); + Assert.Equal(dialogResult, showDialogTaskResult); Assert.False(mvvmWindow.IsVisible); Assert.Null(testViewModel.AssociatedView); diff --git a/src/RolandK.AvaloniaExtensions.Tests/RolandK.AvaloniaExtensions.Tests.csproj b/src/RolandK.AvaloniaExtensions.Tests/RolandK.AvaloniaExtensions.Tests.csproj index 9c7241c..4c6ecd7 100644 --- a/src/RolandK.AvaloniaExtensions.Tests/RolandK.AvaloniaExtensions.Tests.csproj +++ b/src/RolandK.AvaloniaExtensions.Tests/RolandK.AvaloniaExtensions.Tests.csproj @@ -9,15 +9,15 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/RolandK.AvaloniaExtensions.Tests/Util/UnitTestApplication.cs b/src/RolandK.AvaloniaExtensions.Tests/Util/UnitTestApplication.cs index aca2102..c5fddfd 100644 --- a/src/RolandK.AvaloniaExtensions.Tests/Util/UnitTestApplication.cs +++ b/src/RolandK.AvaloniaExtensions.Tests/Util/UnitTestApplication.cs @@ -19,25 +19,27 @@ public static async Task RunInApplicationContextAsync(Action? action = null) return; } - var taskComplSource = new TaskCompletionSource(); - var uiThread = new Thread(_ => - { - AppBuilder.Configure() - .LogToTrace() - .UseHeadless(new AvaloniaHeadlessPlatformOptions()) - .AfterSetup(_ => taskComplSource.SetResult()) - .StartWithClassicDesktopLifetime(Array.Empty(), ShutdownMode.OnExplicitShutdown); - }); - uiThread.Start(); - - await taskComplSource.Task; - + await StartApplicationAsync(); + if (action != null) { await Dispatcher.UIThread.InvokeAsync(action); } } + public static async Task RunInApplicationContextAsync(Func asyncAction) + { + if (Application.Current != null) + { + await Dispatcher.UIThread.InvokeAsync(asyncAction); + return; + } + + await StartApplicationAsync(); + + await Dispatcher.UIThread.InvokeAsync(asyncAction); + } + public static async Task StopAsync() { var application = Application.Current; @@ -48,4 +50,20 @@ public static async Task StopAsync() await Dispatcher.UIThread.InvokeAsync(() => appLifetime.Shutdown()); } + + private static async Task StartApplicationAsync() + { + var taskComplSource = new TaskCompletionSource(); + var uiThread = new Thread(_ => + { + AppBuilder.Configure() + .LogToTrace() + .UseHeadless(new AvaloniaHeadlessPlatformOptions()) + .AfterSetup(_ => taskComplSource.SetResult()) + .StartWithClassicDesktopLifetime(Array.Empty(), ShutdownMode.OnExplicitShutdown); + }); + uiThread.Start(); + + await taskComplSource.Task; + } } \ No newline at end of file diff --git a/src/RolandK.AvaloniaExtensions/RolandK.AvaloniaExtensions.csproj b/src/RolandK.AvaloniaExtensions/RolandK.AvaloniaExtensions.csproj index 1aca86d..96d67ed 100644 --- a/src/RolandK.AvaloniaExtensions/RolandK.AvaloniaExtensions.csproj +++ b/src/RolandK.AvaloniaExtensions/RolandK.AvaloniaExtensions.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive