Skip to content

Commit 9625aab

Browse files
Add/Fix System Unit Tests for Nullable Booleans, see Issue #3198
To be removed later with WinUI 3 transition.
1 parent 0b3429b commit 9625aab

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

UnitTests/Extensions/Test_NullableBoolMarkupExtension.cs

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,17 @@ 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
131134
[TestCategory("NullableBoolMarkupExtension")]
135+
132136
[UITestMethod]
133-
public void Test_NullableBool_DependencyProperty_SystemTrueValueFails()
137+
public void Test_NullableBool_DependencyProperty_SystemTrue()
134138
{
135139
// This is the failure case in the OS currently which causes us to need
136140
// this markup extension.
137-
var exception = Assert.ThrowsException<XamlParseException>(
138-
() =>
139-
{
140-
var treeroot = XamlReader.Load(@"<Page
141+
var treeroot = XamlReader.Load(@"<Page
141142
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
142143
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
143144
xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""
@@ -146,12 +147,60 @@ public void Test_NullableBool_DependencyProperty_SystemTrueValueFails()
146147
<helpers:ObjectWithNullableBoolProperty x:Key=""OurObject"" NullableBool=""True""/>
147148
</Page.Resources>
148149
</Page>") as FrameworkElement;
149-
}, "Expected assignment failure during parsing, OS now supports, update documentation.");
150150

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

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

156205
[TestCategory("NullableBoolMarkupExtension")]
157206
[UITestMethod]

0 commit comments

Comments
 (0)