Skip to content

Commit 7df2ca5

Browse files
Merge pull request #3207 from windows-toolkit/testsCI+UnitTestFixes
✔ Fix Unit Tests for Integration with CI Builds 🎉🎉🎉
2 parents 5e01ab6 + 59174fe commit 7df2ca5

24 files changed

+274
-176
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</PropertyGroup>
2121

2222
<PropertyGroup>
23-
<SignAssembly Condition="'$(SignAssembly)' == '' and '$(IsUwpProject)' != 'true'" >true</SignAssembly>
23+
<SignAssembly Condition="'$(SignAssembly)' == '' and '$(IsUwpProject)' != 'true' and '$(IsTestSampleProject)' != 'true'" >true</SignAssembly>
2424
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)toolkit.snk</AssemblyOriginatorKeyFile>
2525
</PropertyGroup>
2626

GazeInputTest/App.xaml.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
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.Input.GazeInteraction;
65
using System;
6+
using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
77
using Windows.ApplicationModel;
88
using Windows.ApplicationModel.Activation;
99
using Windows.UI.Xaml;
@@ -15,9 +15,10 @@ namespace GazeInputTest
1515
/// <summary>
1616
/// Provides application-specific behavior to supplement the default Application class.
1717
/// </summary>
18-
sealed partial class App : Application
18+
public sealed partial class App : Application
1919
{
2020
/// <summary>
21+
/// Initializes a new instance of the <see cref="App"/> class.
2122
/// Initializes the singleton application object. This is the first line of authored code
2223
/// executed, and as such is the logical equivalent of main() or WinMain().
2324
/// </summary>
@@ -47,7 +48,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
4748

4849
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
4950
{
50-
//TODO: Load state from previously suspended application
51+
// TODO: Load state from previously suspended application
5152
}
5253

5354
// Place the frame in the current Window
@@ -63,6 +64,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
6364
// parameter
6465
rootFrame.Navigate(typeof(MainPage), e.Arguments);
6566
}
67+
6668
// Ensure the current window is active
6769
Window.Current.Activate();
6870
}
@@ -75,7 +77,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
7577
/// </summary>
7678
/// <param name="sender">The Frame which failed navigation</param>
7779
/// <param name="e">Details about the navigation failure</param>
78-
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
80+
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
7981
{
8082
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
8183
}
@@ -90,7 +92,8 @@ void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
9092
private void OnSuspending(object sender, SuspendingEventArgs e)
9193
{
9294
var deferral = e.SuspendingOperation.GetDeferral();
93-
//TODO: Save application state and stop any background activity
95+
96+
// TODO: Save application state and stop any background activity
9497
deferral.Complete();
9598
}
9699
}

GazeInputTest/GazeInputTest.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
153153
<Version>6.2.9</Version>
154154
</PackageReference>
155+
<PackageReference Include="StyleCop.Analyzers">
156+
<Version>1.0.2</Version>
157+
</PackageReference>
155158
</ItemGroup>
156159
<ItemGroup>
157160
<ProjectReference Include="..\Microsoft.Toolkit.UWP.Input.GazeInteraction\Microsoft.Toolkit.Uwp.Input.GazeInteraction.vcxproj">

GazeInputTest/MainPage.xaml.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
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.Input.GazeInteraction;
65
using System;
6+
using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
77
using Windows.ApplicationModel.Core;
88
using Windows.UI.Core;
99
using Windows.UI.ViewManagement;
@@ -50,18 +50,18 @@ private void ShowCursor_Toggle(object sender, RoutedEventArgs e)
5050
}
5151
}
5252

53-
int clickCount;
53+
private int _clickCount;
5454

5555
private void OnLegacyInvoked(object sender, RoutedEventArgs e)
5656
{
57-
clickCount++;
58-
HowButton.Content = string.Format("{0}: Legacy click", clickCount);
57+
_clickCount++;
58+
HowButton.Content = string.Format("{0}: Legacy click", _clickCount);
5959
}
6060

6161
private void OnGazeInvoked(object sender, DwellInvokedRoutedEventArgs e)
6262
{
63-
clickCount++;
64-
HowButton.Content = string.Format("{0}: Accessible click", clickCount);
63+
_clickCount++;
64+
HowButton.Content = string.Format("{0}: Accessible click", _clickCount);
6565
e.Handled = true;
6666
}
6767

@@ -71,13 +71,13 @@ private void OnInvokeProgress(object sender, DwellProgressEventArgs e)
7171
{
7272
ProgressShow.Value = 100.0 * e.Progress;
7373
}
74+
7475
ProgressShow.IsIndeterminate = e.State == DwellProgressState.Complete;
7576
e.Handled = true;
7677
}
7778

7879
private async void SpawnClicked(object sender, RoutedEventArgs e)
7980
{
80-
8181
var newView = CoreApplication.CreateNewView();
8282
var newViewId = 0;
8383

Microsoft.Toolkit.Parsers/Markdown/Blocks/HeaderBlock.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace Microsoft.Toolkit.Parsers.Markdown.Blocks
1111
{
1212
/// <summary>
1313
/// Represents a heading.
14+
/// <seealso href="https://spec.commonmark.org/0.29/#atx-headings">Single-Line Header CommonMark Spec</seealso>
15+
/// <seealso href="https://spec.commonmark.org/0.29/#setext-headings">Two-Line Header CommonMark Spec</seealso>
1416
/// </summary>
1517
public class HeaderBlock : MarkdownBlock
1618
{

Microsoft.Toolkit.Parsers/Markdown/MarkdownDocument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ internal static List<MarkdownBlock> Parse(string markdown, int start, int end, i
233233
realStartOfLine = startOfLine;
234234
endOfLine = startOfLine + 3;
235235
startOfNextLine = Common.FindNextSingleNewLine(markdown, startOfLine, end, out startOfNextLine);
236-
}
237236

238-
paragraphText.Clear();
237+
paragraphText.Clear();
238+
}
239239
}
240240

241241
if (newBlockElement == null && nonSpaceChar == '#' && nonSpacePos == startOfLine)

UnitTests/Extensions/Test_NullableBoolMarkupExtension.cs

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,18 @@ public void Test_NullableBool_Test_TestObject()
128128
Assert.AreEqual(null, obj.NullableBool, "Expected obj value to be null.");
129129
}
130130

131+
#pragma warning disable SA1124 // Do not use regions
132+
#region System-based Unit Tests, See Issue #3198
133+
#pragma warning restore SA1124 // Do not use regions
134+
[Ignore] // This test has trouble running on CI in release mode for some reason, we should re-enable when we test WinUI 3 Issue #3106
131135
[TestCategory("NullableBoolMarkupExtension")]
136+
132137
[UITestMethod]
133-
public void Test_NullableBool_DependencyProperty_SystemTrueValueFails()
138+
public void Test_NullableBool_DependencyProperty_SystemTrue()
134139
{
135140
// This is the failure case in the OS currently which causes us to need
136141
// this markup extension.
137-
var exception = Assert.ThrowsException<XamlParseException>(
138-
() =>
139-
{
140-
var treeroot = XamlReader.Load(@"<Page
142+
var treeroot = XamlReader.Load(@"<Page
141143
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
142144
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
143145
xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""
@@ -146,12 +148,61 @@ public void Test_NullableBool_DependencyProperty_SystemTrueValueFails()
146148
<helpers:ObjectWithNullableBoolProperty x:Key=""OurObject"" NullableBool=""True""/>
147149
</Page.Resources>
148150
</Page>") as FrameworkElement;
149-
}, "Expected assignment failure during parsing, OS now supports, update documentation.");
150151

151-
Assert.IsNotNull(exception);
152+
var obj = treeroot.Resources["OurObject"] as ObjectWithNullableBoolProperty;
153+
154+
Assert.IsNotNull(obj, "Could not find object in resources.");
155+
156+
Assert.AreEqual(true, obj.NullableBool, "Expected obj value to be true.");
157+
}
158+
159+
[Ignore] // This test has trouble running on CI in release mode for some reason, we should re-enable when we test WinUI 3 Issue #3106
160+
[TestCategory("NullableBoolMarkupExtension")]
161+
[UITestMethod]
162+
public void Test_NullableBool_DependencyProperty_SystemFalse()
163+
{
164+
// This is the failure case in the OS currently which causes us to need
165+
// this markup extension.
166+
var treeroot = XamlReader.Load(@"<Page
167+
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
168+
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
169+
xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""
170+
xmlns:helpers=""using:UnitTests.Extensions.Helpers"">
171+
<Page.Resources>
172+
<helpers:ObjectWithNullableBoolProperty x:Key=""OurObject"" NullableBool=""False""/>
173+
</Page.Resources>
174+
</Page>") as FrameworkElement;
175+
176+
var obj = treeroot.Resources["OurObject"] as ObjectWithNullableBoolProperty;
177+
178+
Assert.IsNotNull(obj, "Could not find object in resources.");
179+
180+
Assert.AreEqual(false, obj.NullableBool, "Expected obj value to be true.");
181+
}
182+
183+
[TestCategory("NullableBoolMarkupExtension")]
184+
[UITestMethod]
185+
public void Test_NullableBool_DependencyProperty_SystemNull()
186+
{
187+
// This is the failure case in the OS currently which causes us to need
188+
// this markup extension.
189+
var treeroot = XamlReader.Load(@"<Page
190+
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
191+
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
192+
xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""
193+
xmlns:helpers=""using:UnitTests.Extensions.Helpers"">
194+
<Page.Resources>
195+
<helpers:ObjectWithNullableBoolProperty x:Key=""OurObject"" NullableBool=""{x:Null}""/>
196+
</Page.Resources>
197+
</Page>") as FrameworkElement;
198+
199+
var obj = treeroot.Resources["OurObject"] as ObjectWithNullableBoolProperty;
200+
201+
Assert.IsNotNull(obj, "Could not find object in resources.");
152202

153-
Assert.IsTrue(exception.Message.Contains("Failed to create a 'Windows.Foundation.IReference`1<Boolean>' from the text 'True'."));
203+
Assert.IsNull(obj.NullableBool, "Expected obj value to be null.");
154204
}
205+
#endregion
155206

156207
[TestCategory("NullableBoolMarkupExtension")]
157208
[UITestMethod]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 System;
6+
using Microsoft.Toolkit.Uwp.Helpers;
7+
8+
namespace UnitTests
9+
{
10+
internal class TestCollectionCapableDeepLinkParser : CollectionFormingDeepLinkParser
11+
{
12+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Call stack reviewed.")]
13+
public TestCollectionCapableDeepLinkParser(string uri)
14+
: base(uri)
15+
{
16+
}
17+
18+
public TestCollectionCapableDeepLinkParser(Uri uri)
19+
: base(uri)
20+
{
21+
}
22+
}
23+
}

UnitTests/Helpers/TestDeepLinkParser.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
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 System;
6+
using Microsoft.Toolkit.Uwp.Helpers;
7+
58
namespace UnitTests
69
{
7-
using System;
8-
using Microsoft.Toolkit.Uwp.Helpers;
9-
1010
internal class TestDeepLinkParser : DeepLinkParser
1111
{
1212
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Call stack reviewed.")]
@@ -20,18 +20,4 @@ public TestDeepLinkParser(Uri uri)
2020
{
2121
}
2222
}
23-
24-
internal class TestCollectionCapableDeepLinkParser : CollectionFormingDeepLinkParser
25-
{
26-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Call stack reviewed.")]
27-
public TestCollectionCapableDeepLinkParser(string uri)
28-
: base(uri)
29-
{
30-
}
31-
32-
public TestCollectionCapableDeepLinkParser(Uri uri)
33-
: base(uri)
34-
{
35-
}
36-
}
3723
}

UnitTests/Helpers/Test_ConnectionHelper.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77

88
namespace UnitTests.Helpers
99
{
10+
//// TODO: Need Mock to WinRT Issue #3196 - https://github.com/windows-toolkit/WindowsCommunityToolkit/issues/3196
1011
[TestClass]
1112
public class Test_ConnectionHelper
12-
{
13-
public NetworkHelper NetworkHelper { get; private set; }
14-
13+
{
14+
[Ignore]
1515
[TestCategory("Helpers")]
1616
[TestMethod]
1717
public void Test_ConnectionHelper_IsInternetOnMeteredConnection()
1818
{
1919
Assert.IsFalse(NetworkHelper.Instance.ConnectionInformation.IsInternetOnMeteredConnection);
2020
}
2121

22+
[Ignore]
2223
[TestCategory("Helpers")]
2324
[TestMethod]
2425
public void Test_ConnectionHelper_IsInternetAvailable()

0 commit comments

Comments
 (0)