Skip to content

Commit 32be0c4

Browse files
Remove internal hardlink by using MVVM Messenger
Clean-up namespace orderings
1 parent f219907 commit 32be0c4

File tree

7 files changed

+46
-22
lines changed

7 files changed

+46
-22
lines changed

UITests/UITests.App/App.AppService.xaml.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Diagnostics;
7+
using Microsoft.Toolkit.Mvvm.Messaging;
78
using UITests.App.Pages;
89
using Windows.ApplicationModel.Activation;
910
using Windows.ApplicationModel.AppService;
@@ -51,17 +52,14 @@ private async void OnAppServiceRequestReceived(AppServiceConnection sender, AppS
5152

5253
ValueSet returnMessage = new ValueSet();
5354

54-
if (host != null)
55+
// We await the OpenPage method to ensure the navigation has finished.
56+
if (await WeakReferenceMessenger.Default.Send<RequestPageMessage>(new (pageName)))
5557
{
56-
// We await the OpenPage method to ensure the navigation has finished.
57-
if (await host.OpenPage(pageName))
58-
{
59-
returnMessage.Add("Status", "OK");
60-
}
61-
else
62-
{
63-
returnMessage.Add("Status", "BAD");
64-
}
58+
returnMessage.Add("Status", "OK");
59+
}
60+
else
61+
{
62+
returnMessage.Add("Status", "BAD");
6563
}
6664

6765
await args.Request.SendResponseAsync(returnMessage);

UITests/UITests.App/App.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
namespace UITests.App
1717
{
18+
/// <summary>
19+
/// Application class for hosting UI pages to test.
20+
/// </summary>
1821
public sealed partial class App
1922
{
20-
// TODO: Create a better pattern here to connect these.
21-
internal MainTestHost host;
22-
2323
public App()
2424
{
2525
this.InitializeComponent();

UITests/UITests.App/MainTestHost.xaml.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using Microsoft.Toolkit.Uwp.Extensions;
65
using System;
7-
using System.Collections.Generic;
86
using System.Reflection;
97
using System.Threading.Tasks;
8+
using Microsoft.Toolkit.Mvvm.Messaging;
9+
using Microsoft.Toolkit.Uwp.Extensions;
1010
using UITests.App.Pages;
1111
using Windows.System;
1212
using Windows.UI.Xaml;
1313
using Windows.UI.Xaml.Controls;
14-
using Windows.UI.Xaml.Input;
1514
using Windows.UI.Xaml.Media.Animation;
1615

1716
namespace UITests.App
1817
{
1918
/// <summary>
2019
/// MainPage hosting all other test pages.
2120
/// </summary>
22-
public sealed partial class MainTestHost
21+
public sealed partial class MainTestHost : IRecipient<RequestPageMessage>
2322
{
2423
private DispatcherQueue _queue;
2524

@@ -30,12 +29,19 @@ public sealed partial class MainTestHost
3029
public MainTestHost()
3130
{
3231
InitializeComponent();
33-
((App)Application.Current).host = this;
32+
33+
WeakReferenceMessenger.Default.RegisterAll(this);
34+
3435
_queue = DispatcherQueue.GetForCurrentThread();
3536
}
3637

37-
// TODO: we should better expose how to control the MainTestHost vs. making this internal.
38-
internal async Task<bool> OpenPage(string pageName)
38+
public void Receive(RequestPageMessage message)
39+
{
40+
// Reply with task back to so it can be properly awaited link:App.AppService.xaml.cs#L56
41+
message.Reply(OpenPage(message.PageName));
42+
}
43+
44+
private async Task<bool> OpenPage(string pageName)
3945
{
4046
try
4147
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.Toolkit.Mvvm.Messaging.Messages;
6+
7+
namespace UITests.App
8+
{
9+
public class RequestPageMessage : AsyncRequestMessage<bool>
10+
{
11+
public string PageName { get; private set; }
12+
13+
public RequestPageMessage(string name)
14+
{
15+
PageName = name;
16+
}
17+
}
18+
}

UITests/UITests.App/UITests.App.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<RootNamespace>UITests.App</RootNamespace>
1111
<AssemblyName>UITests.App</AssemblyName>
1212
<DefaultLanguage>en-US</DefaultLanguage>
13+
<LangVersion>9.0</LangVersion>
1314
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
1415
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.19041.0</TargetPlatformVersion>
1516
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
@@ -137,6 +138,7 @@
137138
<Compile Include="MainTestHost.xaml.cs">
138139
<DependentUpon>MainTestHost.xaml</DependentUpon>
139140
</Compile>
141+
<Compile Include="RequestPageMessage.cs" />
140142
<Compile Include="TestInterop.cs" />
141143
<Compile Include="Properties\AssemblyInfo.cs" />
142144
</ItemGroup>

UITests/UITests.Tests.Shared/UITestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Diagnostics;
67
using System.IO;
78
using System.Linq;
89
using System.Reflection;
@@ -12,7 +13,6 @@
1213
using Windows.Foundation.Collections;
1314
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Common;
1415
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra;
15-
using System.Diagnostics;
1616

1717
#if USING_TAEF
1818
using WEX.Logging.Interop;

UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_SystemInformation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Threading.Tasks;
6+
using Microsoft.Toolkit.Uwp.Extensions;
67
using Microsoft.Toolkit.Uwp.Helpers;
78
using Microsoft.VisualStudio.TestTools.UnitTesting;
89
using Windows.ApplicationModel.Activation;
9-
using Microsoft.Toolkit.Uwp.Extensions;
1010

1111
namespace UnitTests.XamlIslands.UWPApp
1212
{

0 commit comments

Comments
 (0)