From 1cd5d01f1c3239fac7e38e1161ca01caff45e82f Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 27 Oct 2021 14:52:26 -0600 Subject: [PATCH] The test tests didn't work so well --- Wabbajack.App.Test/AvaloniaApp.cs | 31 ----- Wabbajack.App.Test/AvaloniaUiTestFramework.cs | 111 ------------------ Wabbajack.App.Test/Extensions.cs | 47 -------- Wabbajack.App.Test/GalleryItemTests.cs | 74 ------------ Wabbajack.App.Test/MainWindowTests.cs | 55 --------- Wabbajack.App.Test/Startup.cs | 20 ---- Wabbajack.App.Test/Wabbajack.App.Test.csproj | 34 ------ Wabbajack.App/Assets/Wabbajack.axaml | 4 + Wabbajack.App/Screens/SettingsView.axaml | 4 +- .../ViewModels/MainWindowViewModel.cs | 4 - Wabbajack.sln | 6 - global.json | 5 + 12 files changed, 11 insertions(+), 384 deletions(-) delete mode 100644 Wabbajack.App.Test/AvaloniaApp.cs delete mode 100644 Wabbajack.App.Test/AvaloniaUiTestFramework.cs delete mode 100644 Wabbajack.App.Test/Extensions.cs delete mode 100644 Wabbajack.App.Test/GalleryItemTests.cs delete mode 100644 Wabbajack.App.Test/MainWindowTests.cs delete mode 100644 Wabbajack.App.Test/Startup.cs delete mode 100644 Wabbajack.App.Test/Wabbajack.App.Test.csproj create mode 100644 global.json diff --git a/Wabbajack.App.Test/AvaloniaApp.cs b/Wabbajack.App.Test/AvaloniaApp.cs deleted file mode 100644 index 13b55ee0..00000000 --- a/Wabbajack.App.Test/AvaloniaApp.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using Avalonia; -using Avalonia.Controls.ApplicationLifetimes; -using Avalonia.Headless; -using Avalonia.ReactiveUI; -using Avalonia.Threading; -using Wabbajack.App.Views; - -namespace Wabbajack.App.Test; - -public static class AvaloniaApp -{ - - public static void Stop() - { - var app = GetApp(); - if (app is IDisposable disposable) - Dispatcher.UIThread.Post(disposable.Dispose); - Dispatcher.UIThread.Post(() => app.Shutdown()); - } - - public static MainWindow GetMainWindow() => (MainWindow) GetApp().MainWindow; - public static IClassicDesktopStyleApplicationLifetime GetApp() => - (IClassicDesktopStyleApplicationLifetime) Application.Current.ApplicationLifetime; - - public static AppBuilder BuildAvaloniaApp() => - AppBuilder.Configure() - .UsePlatformDetect() - .UseReactiveUI() - .UseHeadless(); -} \ No newline at end of file diff --git a/Wabbajack.App.Test/AvaloniaUiTestFramework.cs b/Wabbajack.App.Test/AvaloniaUiTestFramework.cs deleted file mode 100644 index dee1b918..00000000 --- a/Wabbajack.App.Test/AvaloniaUiTestFramework.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; -using Avalonia; -using Xunit; -using Xunit.Abstractions; -using Xunit.Sdk; - - - -[assembly: TestFramework("Wabbajack.App.Test.AvaloniaUiTestFramework", "Wabbajack.App.Test")] -[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, DisableTestParallelization = false, MaxParallelThreads = 1)] -namespace Wabbajack.App.Test -{ - public class AvaloniaUiTestFramework : XunitTestFramework - { - public AvaloniaUiTestFramework(IMessageSink messageSink) - : base(messageSink) - { - - } - - protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName) - => new Executor(assemblyName, SourceInformationProvider, DiagnosticMessageSink); - - private class Executor : XunitTestFrameworkExecutor - { - public Executor( - AssemblyName assemblyName, - ISourceInformationProvider sourceInformationProvider, - IMessageSink diagnosticMessageSink) - : base( - assemblyName, - sourceInformationProvider, - diagnosticMessageSink) - { - - } - - protected override async void RunTestCases(IEnumerable testCases, - IMessageSink executionMessageSink, - ITestFrameworkExecutionOptions executionOptions) - { - executionOptions.SetValue("xunit.execution.DisableParallelization", false); - using var assemblyRunner = new Runner( - TestAssembly, testCases, DiagnosticMessageSink, executionMessageSink, - executionOptions); - - await assemblyRunner.RunAsync(); - } - } - - private class Runner : XunitTestAssemblyRunner - { - public Runner( - ITestAssembly testAssembly, - IEnumerable testCases, - IMessageSink diagnosticMessageSink, - IMessageSink executionMessageSink, - ITestFrameworkExecutionOptions executionOptions) - : base( - testAssembly, - testCases, - diagnosticMessageSink, - executionMessageSink, - executionOptions) - { - - } - - public override void Dispose() - { - AvaloniaApp.Stop(); - - base.Dispose(); - } - - protected override void SetupSyncContext(int maxParallelThreads) - { - var tcs = new TaskCompletionSource(); - var thread = new Thread(() => - { - try - { - AvaloniaApp - .BuildAvaloniaApp() - .AfterSetup(_ => - { - tcs.SetResult(SynchronizationContext.Current); - }) - .StartWithClassicDesktopLifetime(new string[0]); - } - catch (Exception e) - { - tcs.SetException(e); - } - }) - { - IsBackground = true - }; - thread.SetApartmentState(ApartmentState.STA); - - thread.Start(); - - SynchronizationContext.SetSynchronizationContext(tcs.Task.Result); - } - } - } -} \ No newline at end of file diff --git a/Wabbajack.App.Test/Extensions.cs b/Wabbajack.App.Test/Extensions.cs deleted file mode 100644 index 024bbceb..00000000 --- a/Wabbajack.App.Test/Extensions.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Threading.Tasks; -using Avalonia.Threading; -using Wabbajack.App.Models; -using Wabbajack.App.ViewModels; -using Wabbajack.App.Views; - -namespace Wabbajack.App.Test; - -public static class Extensions -{ - public static async Task WaitUntil(this T src, Predicate check, Action? doFunc = null) - { - Dispatcher.UIThread.RunJobs(); - - while (!check(src)) - { - doFunc?.Invoke(); - await Task.Delay(100); - } - } - - public static async Task WaitForLock(this LoadingLock l) - { - Dispatcher.UIThread.RunJobs(); - while (!l.IsLoading) - { - Dispatcher.UIThread.RunJobs(); - await Task.Delay(100); - } - } - - public static async Task WaitForUnlock(this LoadingLock l) - { - Dispatcher.UIThread.RunJobs(); - while (l.IsLoading) - { - Dispatcher.UIThread.RunJobs(); - await Task.Delay(100); - } - } - - public static T GetScreen(this MainWindow view) - { - return (T) view.Contents.Content; - } -} \ No newline at end of file diff --git a/Wabbajack.App.Test/GalleryItemTests.cs b/Wabbajack.App.Test/GalleryItemTests.cs deleted file mode 100644 index a062a563..00000000 --- a/Wabbajack.App.Test/GalleryItemTests.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Wabbajack.App.Controls; -using Wabbajack.App.Messages; -using Wabbajack.App.Screens; -using Wabbajack.App.ViewModels; -using Wabbajack.Common; -using Wabbajack.Paths.IO; -using Wabbajack.RateLimiter; -using Xunit; - -namespace Wabbajack.App.Test; - -public class GalleryItemTests -{ - private readonly Configuration _config; - private readonly BrowseViewModel _gallery; - - public GalleryItemTests(BrowseViewModel bvm, Configuration config) - { - _config = config; - _gallery = bvm; - } - - [Fact] - public async Task CanDownloadGalleryItem() - { - _config.ModListsDownloadLocation.CreateDirectory(); - foreach (var file in _config.ModListsDownloadLocation.EnumerateFiles().Where(f => f.Extension == Ext.Wabbajack)) - file.Delete(); - - using var _ = _gallery.Activator.Activate(); - await _gallery.LoadingLock.WaitForLock(); - await _gallery.LoadingLock.WaitForUnlock(); - Assert.True(_gallery.ModLists.Count > 0); - - foreach (var item in _gallery.ModLists) - { - Assert.NotEqual(ModListState.Downloading, item.State); - if (item.State == ModListState.Downloaded) - Assert.True(item.ModListLocation.FileExists()); - else - Assert.False(item.ModListLocation.FileExists()); - - Assert.Equal(Percent.Zero, item.Progress); - } - - var modList = _gallery.ModLists.First(); - modList.ExecuteCommand.Execute().Subscribe().Dispose(); - - var progress = Percent.Zero; - await modList.WaitUntil(x => x.State == ModListState.Downloading); - await modList.WaitUntil(x => x.State != ModListState.Downloading, () => - { - Assert.True(modList.Progress >= progress); - progress = modList.Progress; - }); - - Assert.Equal(Percent.Zero, modList.Progress); - Assert.Equal(ModListState.Downloaded, modList.State); - - - modList.ExecuteCommand.Execute().Subscribe().Dispose(); - - /* - var configure = msgs.OfType().First(); - Assert.Equal(modList.ModListLocation, configure.ModList); - - var navigate = msgs.OfType().First(); - Assert.Equal(typeof(InstallConfigurationViewModel), navigate.ViewModel); - */ - } -} \ No newline at end of file diff --git a/Wabbajack.App.Test/MainWindowTests.cs b/Wabbajack.App.Test/MainWindowTests.cs deleted file mode 100644 index aaa8b0ad..00000000 --- a/Wabbajack.App.Test/MainWindowTests.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Avalonia.Threading; -using Avalonia.VisualTree; -using Wabbajack.App.Controls; -using Wabbajack.App.Interfaces; -using Wabbajack.App.Screens; -using Wabbajack.App.Views; -using Xunit; - -namespace Wabbajack.App.Test; - -public class MainWindowTests -{ - private static TimeSpan StandardDelay = new TimeSpan(250); - - [Fact(DisplayName = "Can Open and Close MainWindow")] - public async Task CanOpenMainApp() - { - var app = AvaloniaApp.GetApp(); - var window = AvaloniaApp.GetMainWindow(); - - var msv = await GoHome(window); - msv.BrowseButton.Button.Command.Execute(null); - msv.BrowseButton.Button.Command.Execute(null); - - var yu = Dispatcher.UIThread; - - await Task.Delay(StandardDelay * 4); - - var gallery = window.GetScreen(); - gallery.SearchBox.Text = "Halgaris Helper"; - await Task.Delay(StandardDelay); - var itms = gallery.GalleryList.FindDescendantOfType(); - - - - - } - - private async Task GoHome(MainWindow mainWindow) - { - while (mainWindow.BackButton.Command.CanExecute(null)) - { - mainWindow.BackButton.Command.Execute(null); - await Task.Delay(StandardDelay); - } - - if (mainWindow.Contents.Content is ModeSelectionView msv) - return msv; - - throw new Exception("Top screen is not ModeSelectionView"); - } -} \ No newline at end of file diff --git a/Wabbajack.App.Test/Startup.cs b/Wabbajack.App.Test/Startup.cs deleted file mode 100644 index 0d3e030e..00000000 --- a/Wabbajack.App.Test/Startup.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Xunit.DependencyInjection; -using Xunit.DependencyInjection.Logging; - -namespace Wabbajack.App.Test; - -public class Startup -{ - public void ConfigureServices(IServiceCollection service) - { - service.AddAppServices(); - } - - public void Configure(ILoggerFactory loggerFactory, ITestOutputHelperAccessor accessor) - { - loggerFactory.AddProvider(new XunitTestOutputLoggerProvider(accessor, delegate { return true; })); - } -} diff --git a/Wabbajack.App.Test/Wabbajack.App.Test.csproj b/Wabbajack.App.Test/Wabbajack.App.Test.csproj deleted file mode 100644 index 4e96d3de..00000000 --- a/Wabbajack.App.Test/Wabbajack.App.Test.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - - Exe - net6.0-windows - net6.0 - enable - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - - - - diff --git a/Wabbajack.App/Assets/Wabbajack.axaml b/Wabbajack.App/Assets/Wabbajack.axaml index f1a943c4..3d9c8975 100644 --- a/Wabbajack.App/Assets/Wabbajack.axaml +++ b/Wabbajack.App/Assets/Wabbajack.axaml @@ -34,6 +34,10 @@ + + \ No newline at end of file diff --git a/Wabbajack.App/Screens/SettingsView.axaml b/Wabbajack.App/Screens/SettingsView.axaml index 6d34aab9..fb56369c 100644 --- a/Wabbajack.App/Screens/SettingsView.axaml +++ b/Wabbajack.App/Screens/SettingsView.axaml @@ -6,7 +6,7 @@ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Wabbajack.App.Screens.SettingsView"> - + Logins @@ -34,7 +34,7 @@ - + Resource Limits diff --git a/Wabbajack.App/ViewModels/MainWindowViewModel.cs b/Wabbajack.App/ViewModels/MainWindowViewModel.cs index 5f03b40a..ef36998b 100644 --- a/Wabbajack.App/ViewModels/MainWindowViewModel.cs +++ b/Wabbajack.App/ViewModels/MainWindowViewModel.cs @@ -151,9 +151,5 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod { _resourcePoller.Dispose(); VMDisposables.Dispose(); - BackButton.Dispose(); - SettingsButton.Dispose(); - LogViewButton.Dispose(); - Activator.Dispose(); } } \ No newline at end of file diff --git a/Wabbajack.sln b/Wabbajack.sln index c1ef69d9..f7f3c5e0 100644 --- a/Wabbajack.sln +++ b/Wabbajack.sln @@ -116,8 +116,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Downloaders.GameF EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Launcher", "Wabbajack.Launcher\Wabbajack.Launcher.csproj", "{23D49FCC-A6CB-4873-879B-F90DA1871AA3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.App.Test", "Wabbajack.App.Test\Wabbajack.App.Test.csproj", "{05E7E8BB-1F44-4E3D-8443-110FD237AA92}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -324,10 +322,6 @@ Global {23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Debug|Any CPU.Build.0 = Debug|Any CPU {23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Release|Any CPU.ActiveCfg = Release|Any CPU {23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Release|Any CPU.Build.0 = Release|Any CPU - {05E7E8BB-1F44-4E3D-8443-110FD237AA92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {05E7E8BB-1F44-4E3D-8443-110FD237AA92}.Debug|Any CPU.Build.0 = Debug|Any CPU - {05E7E8BB-1F44-4E3D-8443-110FD237AA92}.Release|Any CPU.ActiveCfg = Release|Any CPU - {05E7E8BB-1F44-4E3D-8443-110FD237AA92}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {4057B668-8595-44FE-9805-007B284A838F} = {98B731EE-4FC0-4482-A069-BCBA25497871} diff --git a/global.json b/global.json new file mode 100644 index 00000000..4e0cd99f --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "6.0.*" + } +} \ No newline at end of file