-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathTestBase.cs
More file actions
72 lines (60 loc) · 2.56 KB
/
TestBase.cs
File metadata and controls
72 lines (60 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.Diagnostics.CodeAnalysis;
using System.Windows.Media;
using MaterialDesignThemes.UITests;
using MaterialDesignThemes.Wpf.Internal;
using TUnit.Core.Interfaces;
[assembly: ParallelLimiter<SingleParallelLimit>]
[assembly: GenerateHelpers(typeof(AutoSuggestBox))]
[assembly: GenerateHelpers(typeof(ColorPicker))]
[assembly: GenerateHelpers(typeof(DecimalUpDown))]
[assembly: GenerateHelpers(typeof(DialogHost))]
[assembly: GenerateHelpers(typeof(DrawerHost))]
[assembly: GenerateHelpers(typeof(NumericUpDown))]
[assembly: GenerateHelpers(typeof(PopupBox))]
[assembly: GenerateHelpers(typeof(SmartHint))]
[assembly: GenerateHelpers(typeof(TimePicker))]
[assembly: GenerateHelpers(typeof(TreeListView))]
[assembly: GenerateHelpers(typeof(TreeListViewItem))]
[assembly: GenerateHelpers(typeof(PaddedBringIntoViewStackPanel))]
namespace MaterialDesignThemes.UITests;
public record SingleParallelLimit : IParallelLimit
{
public int Limit => 1;
}
public abstract class TestBase()
{
protected bool AttachedDebuggerToRemoteProcess { get; set; } = true;
protected static TextWriter Output => TestContext.Current?.OutputWriter ?? throw new InvalidOperationException("Could not find output writer");
[NotNull]
protected IApp? App { get; set; }
protected async Task<Color> GetThemeColor(string name)
{
IResource resource = await App.GetResource(name);
return resource.GetAs<Color?>() ?? throw new Exception($"Failed to convert resource '{name}' to color");
}
protected async Task<IVisualElement<T>> LoadXaml<T>(string xaml, params (string namespacePrefix, Type type)[] additionalNamespaceDeclarations)
{
await App.InitializeWithMaterialDesign();
return await App.CreateWindowWith<T>(xaml, additionalNamespaceDeclarations);
}
protected Task<IVisualElement> LoadUserControl<TControl>()
where TControl : UserControl
=> LoadUserControl(typeof(TControl));
protected async Task<IVisualElement> LoadUserControl(Type userControlType)
{
await App.InitializeWithMaterialDesign();
return await App.CreateWindowWithUserControl(userControlType);
}
[Before(Test)]
public async ValueTask InitializeAsync() =>
App = await XamlTest.App.StartRemote(new AppOptions
{
#if !DEBUG
MinimizeOtherWindows = !System.Diagnostics.Debugger.IsAttached,
#endif
AllowVisualStudioDebuggerAttach = AttachedDebuggerToRemoteProcess,
LogMessage = Output.WriteLine
});
[After(Test)]
public async ValueTask DisposeAsync() => await App.DisposeAsync();
}