test(app): build the section templates pack URI after the Application exists
The Server screen smoke tests now run before any other WPF test, so ScreenHost's static pack:// URI was parsed before the scheme was registered and every later screen test failed with a type initializer exception. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
1 file changed
+5
-3
@@ -290,7 +290,6 @@ public sealed class ScreenSmokeTests
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class ScreenHost
|
internal static class ScreenHost
|
||||||
{
|
{
|
||||||
private static readonly Uri SectionTemplates = new("pack://application:,,,/Titano;component/Shell/SectionTemplates.xaml", UriKind.Absolute);
|
|
||||||
private static readonly Lazy<Dispatcher> Dispatcher = new(Start, LazyThreadSafetyMode.ExecutionAndPublication);
|
private static readonly Lazy<Dispatcher> Dispatcher = new(Start, LazyThreadSafetyMode.ExecutionAndPublication);
|
||||||
|
|
||||||
public static Task RunAsync(Func<Task> body) => Dispatcher.Value.InvokeAsync(body).Task.Unwrap();
|
public static Task RunAsync(Func<Task> body) => Dispatcher.Value.InvokeAsync(body).Task.Unwrap();
|
||||||
@@ -317,10 +316,13 @@ internal static class ScreenHost
|
|||||||
}
|
}
|
||||||
dispatcher!.Invoke(() =>
|
dispatcher!.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
// pack:// URIs parse only once an Application exists (it registers the scheme), so this one is built here,
|
||||||
|
// not in a static field: the first WPF test of a run may be the one that starts the Application.
|
||||||
|
var sectionTemplates = new Uri("pack://application:,,,/Titano;component/Shell/SectionTemplates.xaml", UriKind.Absolute);
|
||||||
var current = Application.Current;
|
var current = Application.Current;
|
||||||
AppResources.Merge(current);
|
AppResources.Merge(current);
|
||||||
if (!current.Resources.MergedDictionaries.Any(d => d.Source == SectionTemplates))
|
if (!current.Resources.MergedDictionaries.Any(d => d.Source == sectionTemplates))
|
||||||
current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = SectionTemplates });
|
current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = sectionTemplates });
|
||||||
});
|
});
|
||||||
return dispatcher;
|
return dispatcher;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user