Skip to content

Commit

Permalink
Merge pull request #3207 from windows-toolkit/testsCI+UnitTestFixes
Browse files Browse the repository at this point in the history
✔ Fix Unit Tests for Integration with CI Builds 🎉🎉🎉
  • Loading branch information
michael-hawker authored Apr 1, 2020
2 parents 5e01ab6 + 59174fe commit 7df2ca5
Show file tree
Hide file tree
Showing 24 changed files with 274 additions and 176 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<PropertyGroup>
<SignAssembly Condition="'$(SignAssembly)' == '' and '$(IsUwpProject)' != 'true'" >true</SignAssembly>
<SignAssembly Condition="'$(SignAssembly)' == '' and '$(IsUwpProject)' != 'true' and '$(IsTestSampleProject)' != 'true'" >true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)toolkit.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

Expand Down
13 changes: 8 additions & 5 deletions GazeInputTest/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
using System;
using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
Expand All @@ -15,9 +15,10 @@ namespace GazeInputTest
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
public sealed partial class App : Application
{
/// <summary>
/// Initializes a new instance of the <see cref="App"/> class.
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
Expand Down Expand Up @@ -47,7 +48,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)

if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
// TODO: Load state from previously suspended application
}

// Place the frame in the current Window
Expand All @@ -63,6 +64,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}

// Ensure the current window is active
Window.Current.Activate();
}
Expand All @@ -75,7 +77,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
Expand All @@ -90,7 +92,8 @@ void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity

// TODO: Save application state and stop any background activity
deferral.Complete();
}
}
Expand Down
3 changes: 3 additions & 0 deletions GazeInputTest/GazeInputTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.9</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.0.2</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Toolkit.UWP.Input.GazeInteraction\Microsoft.Toolkit.Uwp.Input.GazeInteraction.vcxproj">
Expand Down
14 changes: 7 additions & 7 deletions GazeInputTest/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
using System;
using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
Expand Down Expand Up @@ -50,18 +50,18 @@ private void ShowCursor_Toggle(object sender, RoutedEventArgs e)
}
}

int clickCount;
private int _clickCount;

private void OnLegacyInvoked(object sender, RoutedEventArgs e)
{
clickCount++;
HowButton.Content = string.Format("{0}: Legacy click", clickCount);
_clickCount++;
HowButton.Content = string.Format("{0}: Legacy click", _clickCount);
}

private void OnGazeInvoked(object sender, DwellInvokedRoutedEventArgs e)
{
clickCount++;
HowButton.Content = string.Format("{0}: Accessible click", clickCount);
_clickCount++;
HowButton.Content = string.Format("{0}: Accessible click", _clickCount);
e.Handled = true;
}

Expand All @@ -71,13 +71,13 @@ private void OnInvokeProgress(object sender, DwellProgressEventArgs e)
{
ProgressShow.Value = 100.0 * e.Progress;
}

ProgressShow.IsIndeterminate = e.State == DwellProgressState.Complete;
e.Handled = true;
}

private async void SpawnClicked(object sender, RoutedEventArgs e)
{

var newView = CoreApplication.CreateNewView();
var newViewId = 0;

Expand Down
2 changes: 2 additions & 0 deletions Microsoft.Toolkit.Parsers/Markdown/Blocks/HeaderBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Microsoft.Toolkit.Parsers.Markdown.Blocks
{
/// <summary>
/// Represents a heading.
/// <seealso href="https://spec.commonmark.org/0.29/#atx-headings">Single-Line Header CommonMark Spec</seealso>
/// <seealso href="https://spec.commonmark.org/0.29/#setext-headings">Two-Line Header CommonMark Spec</seealso>
/// </summary>
public class HeaderBlock : MarkdownBlock
{
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Toolkit.Parsers/Markdown/MarkdownDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ internal static List<MarkdownBlock> Parse(string markdown, int start, int end, i
realStartOfLine = startOfLine;
endOfLine = startOfLine + 3;
startOfNextLine = Common.FindNextSingleNewLine(markdown, startOfLine, end, out startOfNextLine);
}

paragraphText.Clear();
paragraphText.Clear();
}
}

if (newBlockElement == null && nonSpaceChar == '#' && nonSpacePos == startOfLine)
Expand Down
67 changes: 59 additions & 8 deletions UnitTests/Extensions/Test_NullableBoolMarkupExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,18 @@ public void Test_NullableBool_Test_TestObject()
Assert.AreEqual(null, obj.NullableBool, "Expected obj value to be null.");
}

#pragma warning disable SA1124 // Do not use regions
#region System-based Unit Tests, See Issue #3198
#pragma warning restore SA1124 // Do not use regions
[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
[TestCategory("NullableBoolMarkupExtension")]

[UITestMethod]
public void Test_NullableBool_DependencyProperty_SystemTrueValueFails()
public void Test_NullableBool_DependencyProperty_SystemTrue()
{
// This is the failure case in the OS currently which causes us to need
// this markup extension.
var exception = Assert.ThrowsException<XamlParseException>(
() =>
{
var treeroot = XamlReader.Load(@"<Page
var treeroot = XamlReader.Load(@"<Page
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""
Expand All @@ -146,12 +148,61 @@ public void Test_NullableBool_DependencyProperty_SystemTrueValueFails()
<helpers:ObjectWithNullableBoolProperty x:Key=""OurObject"" NullableBool=""True""/>
</Page.Resources>
</Page>") as FrameworkElement;
}, "Expected assignment failure during parsing, OS now supports, update documentation.");

Assert.IsNotNull(exception);
var obj = treeroot.Resources["OurObject"] as ObjectWithNullableBoolProperty;

Assert.IsNotNull(obj, "Could not find object in resources.");

Assert.AreEqual(true, obj.NullableBool, "Expected obj value to be true.");
}

[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
[TestCategory("NullableBoolMarkupExtension")]
[UITestMethod]
public void Test_NullableBool_DependencyProperty_SystemFalse()
{
// This is the failure case in the OS currently which causes us to need
// this markup extension.
var treeroot = XamlReader.Load(@"<Page
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""
xmlns:helpers=""using:UnitTests.Extensions.Helpers"">
<Page.Resources>
<helpers:ObjectWithNullableBoolProperty x:Key=""OurObject"" NullableBool=""False""/>
</Page.Resources>
</Page>") as FrameworkElement;

var obj = treeroot.Resources["OurObject"] as ObjectWithNullableBoolProperty;

Assert.IsNotNull(obj, "Could not find object in resources.");

Assert.AreEqual(false, obj.NullableBool, "Expected obj value to be true.");
}

[TestCategory("NullableBoolMarkupExtension")]
[UITestMethod]
public void Test_NullableBool_DependencyProperty_SystemNull()
{
// This is the failure case in the OS currently which causes us to need
// this markup extension.
var treeroot = XamlReader.Load(@"<Page
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""
xmlns:helpers=""using:UnitTests.Extensions.Helpers"">
<Page.Resources>
<helpers:ObjectWithNullableBoolProperty x:Key=""OurObject"" NullableBool=""{x:Null}""/>
</Page.Resources>
</Page>") as FrameworkElement;

var obj = treeroot.Resources["OurObject"] as ObjectWithNullableBoolProperty;

Assert.IsNotNull(obj, "Could not find object in resources.");

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

[TestCategory("NullableBoolMarkupExtension")]
[UITestMethod]
Expand Down
23 changes: 23 additions & 0 deletions UnitTests/Helpers/TestCollectionCapableDeepLinkParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.Toolkit.Uwp.Helpers;

namespace UnitTests
{
internal class TestCollectionCapableDeepLinkParser : CollectionFormingDeepLinkParser
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Call stack reviewed.")]
public TestCollectionCapableDeepLinkParser(string uri)
: base(uri)
{
}

public TestCollectionCapableDeepLinkParser(Uri uri)
: base(uri)
{
}
}
}
20 changes: 3 additions & 17 deletions UnitTests/Helpers/TestDeepLinkParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.Toolkit.Uwp.Helpers;

namespace UnitTests
{
using System;
using Microsoft.Toolkit.Uwp.Helpers;

internal class TestDeepLinkParser : DeepLinkParser
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Call stack reviewed.")]
Expand All @@ -20,18 +20,4 @@ public TestDeepLinkParser(Uri uri)
{
}
}

internal class TestCollectionCapableDeepLinkParser : CollectionFormingDeepLinkParser
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Call stack reviewed.")]
public TestCollectionCapableDeepLinkParser(string uri)
: base(uri)
{
}

public TestCollectionCapableDeepLinkParser(Uri uri)
: base(uri)
{
}
}
}
7 changes: 4 additions & 3 deletions UnitTests/Helpers/Test_ConnectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@

namespace UnitTests.Helpers
{
//// TODO: Need Mock to WinRT Issue #3196 - https://github.com/windows-toolkit/WindowsCommunityToolkit/issues/3196
[TestClass]
public class Test_ConnectionHelper
{
public NetworkHelper NetworkHelper { get; private set; }

{
[Ignore]
[TestCategory("Helpers")]
[TestMethod]
public void Test_ConnectionHelper_IsInternetOnMeteredConnection()
{
Assert.IsFalse(NetworkHelper.Instance.ConnectionInformation.IsInternetOnMeteredConnection);
}

[Ignore]
[TestCategory("Helpers")]
[TestMethod]
public void Test_ConnectionHelper_IsInternetAvailable()
Expand Down
28 changes: 28 additions & 0 deletions UnitTests/Markdown/Parse/HeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using Microsoft.Toolkit.Parsers.Markdown.Blocks;
using Microsoft.Toolkit.Parsers.Markdown.Inlines;
using Microsoft.Toolkit.Parsers.Markdown;

namespace UnitTests.Markdown.Parse
{
Expand Down Expand Up @@ -56,6 +57,13 @@ public void Header_2()
[TestCategory("Parse - block")]
public void Header_2_Alt()
{
/***
* Note: This is a tricky scenario because Header 2's
* can be easily confused with thematic breaks, see specs:
* https://spec.commonmark.org/0.29/#setext-headings
* https://spec.commonmark.org/0.29/#thematic-breaks
***/

// Note: trailing spaces on the second line are okay.
AssertEqual(CollapseWhitespace(@"
Header 2
Expand All @@ -64,6 +72,26 @@ Header 2
new TextRunInline { Text = "Header 2" }));
}

[TestMethod]
[TestCategory("Parse - block")]
public void Header_2_Alt_NotHorizontalRule()
{
/***
* Note: This is a tricky scenario because Header 2's
* can be easily confused with thematic breaks, see specs:
* https://spec.commonmark.org/0.29/#setext-headings
* https://spec.commonmark.org/0.29/#thematic-breaks
***/

// Note: trailing spaces on the second line are okay.
AssertEqual(
CollapseWhitespace(@"
Header 2
--- "),
new HeaderBlock { HeaderLevel = 2 }.AddChildren(
new TextRunInline { Text = "Header 2" }));
}

[TestMethod]
[TestCategory("Parse - block")]
public void Header_3()
Expand Down
Loading

0 comments on commit 7df2ca5

Please sign in to comment.