Skip to content

Commit d2e5dfa

Browse files
authored
Convert Maui27202 and Maui28711 tests from NUnit to XUnit (dotnet#33061)
2 parents 0640831 + edd33aa commit d2e5dfa

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/Controls/tests/Xaml.UnitTests/Issues/Maui27202.xaml.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Linq;
33
using Microsoft.Maui.Controls.Core.UnitTests;
44
using Microsoft.Maui.Graphics;
5-
using NUnit.Framework;
5+
using Xunit;
66

77
namespace Microsoft.Maui.Controls.Xaml.UnitTests;
88

@@ -15,33 +15,32 @@ public Maui27202(bool useCompiledXaml)
1515
//this stub will be replaced at compile time
1616
}
1717

18-
[TestFixture]
19-
class Tests
18+
[Collection("Issue")]
19+
public class Tests : IDisposable
2020
{
21-
[SetUp]
22-
public void Setup()
21+
public Tests()
2322
{
24-
Application.Current = new MockApplication();
23+
Application.SetCurrentApplication(new MockApplication());
2524
}
2625

27-
[TearDown]
28-
public void TearDown()
26+
public void Dispose()
2927
{
3028
Application.Current = null;
3129
}
3230

33-
[Test]
34-
public void DerivedStylesInheritVisualStateManager([Values] XamlInflator inflator)
31+
[Theory]
32+
[XamlInflatorData]
33+
internal void DerivedStylesInheritVisualStateManager(XamlInflator inflator)
3534
{
3635
var page = new Maui27202(inflator);
3736

3837
// Verify styles are applied
39-
Assert.That(page.EnabledLabel1.TextColor, Is.EqualTo(Colors.Green));
38+
Assert.Equal(Colors.Green, page.EnabledLabel1.TextColor);
4039

4140
// Verify VSG exists
4241
var groups = VisualStateManager.GetVisualStateGroups(page.DisabledLabel1);
43-
Assert.That(groups, Is.Not.Null);
44-
Assert.That(groups.Count, Is.GreaterThan(0));
42+
Assert.NotNull(groups);
43+
Assert.True(groups.Count > 0);
4544

4645
// Check if GoToState succeeds
4746
var gotoResult = VisualStateManager.GoToState(page.DisabledLabel1, "Disabled");
@@ -51,9 +50,8 @@ public void DerivedStylesInheritVisualStateManager([Values] XamlInflator inflato
5150
Console.WriteLine($"TextColor after GoToState: {page.DisabledLabel1.TextColor}");
5251
Console.WriteLine($"Expected: Gray ({Colors.Gray})");
5352

54-
Assert.That(gotoResult, Is.True, "GoToState should succeed");
55-
Assert.That(page.DisabledLabel1.TextColor, Is.EqualTo(Colors.Gray),
56-
"VSM Disabled state should override derived style TextColor");
53+
Assert.True(gotoResult, "GoToState should succeed");
54+
Assert.Equal(Colors.Gray, page.DisabledLabel1.TextColor);
5755
}
5856
}
5957
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33
using Microsoft.Maui.Graphics;
4-
using NUnit.Framework;
4+
using Xunit;
55

66
namespace Microsoft.Maui.Controls.Xaml.UnitTests;
77

88
public partial class Maui28711 : ContentPage
99
{
1010
public Maui28711() => InitializeComponent();
1111

12-
[TestFixture]
13-
class Tests
12+
[Collection("Issue")]
13+
public class Tests
1414
{
15-
[Test]
16-
public void XNameOnResourceShouldNotCrash([Values] XamlInflator inflator)
15+
[Theory]
16+
[XamlInflatorData]
17+
internal void XNameOnResourceShouldNotCrash(XamlInflator inflator)
1718
{
1819
// This test reproduces issue #28711
1920
// When using x:Name on a SolidColorBrush in Resources, a NullReferenceException
2021
// was thrown because GetHashCode was called before Color was set.
2122
var page = new Maui28711(inflator);
2223

23-
Assert.That(page, Is.Not.Null);
24-
Assert.That(page.namedBrush, Is.Not.Null);
25-
Assert.That(page.namedBrush.Color, Is.EqualTo(Colors.Red));
24+
Assert.NotNull(page);
25+
Assert.NotNull(page.namedBrush);
26+
Assert.Equal(Colors.Red, page.namedBrush.Color);
2627
}
2728
}
2829
}

0 commit comments

Comments
 (0)