The test tests didn't work so well

This commit is contained in:
Timothy Baldridge 2021-10-27 14:52:26 -06:00
parent 1164cf61f3
commit 1cd5d01f1c
12 changed files with 11 additions and 384 deletions

View File

@ -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<App>()
.UsePlatformDetect()
.UseReactiveUI()
.UseHeadless();
}

View File

@ -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<IXunitTestCase> 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<IXunitTestCase> 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<SynchronizationContext>();
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);
}
}
}
}

View File

@ -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<T>(this T src, Predicate<T> 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<T>(this MainWindow view)
{
return (T) view.Contents.Content;
}
}

View File

@ -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<StartInstallConfiguration>().First();
Assert.Equal(modList.ModListLocation, configure.ModList);
var navigate = msgs.OfType<NavigateTo>().First();
Assert.Equal(typeof(InstallConfigurationViewModel), navigate.ViewModel);
*/
}
}

View File

@ -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<BrowseView>();
gallery.SearchBox.Text = "Halgaris Helper";
await Task.Delay(StandardDelay);
var itms = gallery.GalleryList.FindDescendantOfType<BrowseItemView>();
}
private async Task<ModeSelectionView> 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");
}
}

View File

@ -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; }));
}
}

View File

@ -1,34 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework Condition=" '$(OS)' == 'Windows_NT'">net6.0-windows</TargetFramework>
<TargetFramework Condition=" '$(OS)' != 'Windows_NT'">net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.9" />
<PackageReference Include="Avalonia.Headless" Version="0.10.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xunit.DependencyInjection" Version="8.1.0" />
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="8.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Wabbajack.App\Wabbajack.App.csproj" />
</ItemGroup>
<Target Name="AferBuild" AfterTargets="Build" Condition="!Exists('$(ProjectDir)$(OutDir)libcef.dll')">
<Message Text="Downloading Cef" />
<Exec Command="dotnet run --project $(ProjectDir)../Wabbajack.CLI/Wabbajack.CLI.csproj -- download-cef -f $(ProjectDir)$(OutDir)" />
</Target>
</Project>

View File

@ -35,5 +35,9 @@
<Setter Property="Foreground" Value="#121212" />
</Style>
<Style Selector="Border.Settings">
<Setter Property="BorderThickness" Value="2"></Setter>
</Style>
</Styles>

View File

@ -6,7 +6,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Screens.SettingsView">
<WrapPanel Margin="40">
<Border x:Name="LoginBorder" Margin="5" BorderThickness="1">
<Border x:Name="LoginBorder" Margin="5" BorderThickness="1" Classes="Settings">
<Grid RowDefinitions="Auto, Auto, Auto, Auto" ColumnDefinitions="20, 100, Auto, Auto">
<TextBlock FontSize="20" Grid.ColumnSpan="4">Logins</TextBlock>
@ -34,7 +34,7 @@
</Grid>
</Border>
<Border x:Name="ResourcesBorder" Margin="5" BorderThickness="1">
<Border x:Name="ResourcesBorder" Margin="5" BorderThickness="1" Classes="Settings">
<Grid RowDefinitions="Auto, Auto">
<TextBlock FontSize="20" Grid.ColumnSpan="4">Resource Limits</TextBlock>

View File

@ -151,9 +151,5 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod
{
_resourcePoller.Dispose();
VMDisposables.Dispose();
BackButton.Dispose();
SettingsButton.Dispose();
LogViewButton.Dispose();
Activator.Dispose();
}
}

View File

@ -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}

5
global.json Normal file
View File

@ -0,0 +1,5 @@
{
"sdk": {
"version": "6.0.*"
}
}