Skip to content

Conversation

@rmarinho
Copy link
Member

@rmarinho rmarinho commented Nov 7, 2025

Description of Change

Used copilot to move XAML unit tests to Xunit

Copilot AI review requested due to automatic review settings November 7, 2025 19:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors XAML unit tests from NUnit to xUnit, migrating test attributes, assertion syntax, and test lifecycle management across numerous test files in the Controls.Xaml.UnitTests project.

Key Changes

  • Converted NUnit test attributes ([Test], [TestFixture], [SetUp], [TearDown]) to xUnit equivalents ([Fact], [Theory], constructor, IDisposable)
  • Replaced NUnit assertions with xUnit assertion syntax (e.g., Assert.That → Assert.Equal)
  • Updated test class visibility from internal to public to meet xUnit requirements
  • Added System namespace imports and removed NUnit.Framework references

Reviewed Changes

Copilot reviewed 300 out of 403 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
Maui24900.xaml.cs Converted test class to xUnit with constructor setup and Dispose method; left incomplete test with TODO comment
Maui24849.xaml.cs Migrated NUnit assertions to xUnit equivalents; changed Color.FromHex usage with TODO note
Maui24500.xaml.cs Updated test structure to xUnit Theory with Values attribute
Maui23989.xaml.cs Converted BuildException verification with TODO for detailed exception validation
Maui23711.xaml.cs Migrated assertions and test lifecycle to xUnit patterns
Maui2418.rtsg.xaml.cs Added IDisposable implementation; converted InlineData usage for XamlInflator values
Multiple Issue files Systematic conversion of test attributes, assertions, and class structure across 100+ test files
Comments suppressed due to low confidence (1)

src/Controls/tests/Xaml.UnitTests/Issues/Gh7097.xaml.cs:1

  • The test method is decorated with [Fact] but accepts a parameter (XamlInflator inflator). [Fact] tests cannot have parameters. This should use [Theory] with appropriate data attributes like [Values] or [InlineData].
using System;

Comment on lines +37 to +39
[Theory]
[Values]
public void OnPlatformDoesNotThrow()
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test method is decorated with [Theory] and [Values] but has no parameters. This test will fail at runtime. The method signature should include XamlInflator inflator parameter to match the [Values] attribute usage pattern seen throughout the codebase.

Copilot uses AI. Check for mistakes.
Assert.That(page.button.IsEnabled, Is.False);
Assert.That(page.button.TextColor, Is.EqualTo(Color.FromHex("#3c3c3b")));
Assert.False(page.button.IsEnabled);
Assert.Equal(Color.FromArgb("#3c3c3b"), page.button.TextColor); // TODO: Was FromHex with 2 params, added actual value
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Color.FromArgb expects a color in ARGB format but is being passed a hex string that appears to be RGB only (6 characters after #). This should either use Color.FromRgb or the hex string should be prefixed with 'FF' to make it a valid ARGB value.

Copilot uses AI. Check for mistakes.
var page = new Maui24384(inflator);
var picker = page.Content as Picker;
Assert.That(picker.ItemsSource, Is.EquivalentTo(Maui24384.StaticLetters));
Assert.Equal(Maui24384.StaticLetters, picker.ItemsSource); // TODO: Was Assert.EquivalentTo
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.Equal checks for reference equality or exact sequence equality, but the original NUnit Assert.EquivalentTo checked for content equivalence regardless of order. This should use Assert.Equivalent or Assert.Equal with a comparer to maintain the original test behavior.

Copilot uses AI. Check for mistakes.
{
Console.WriteLine("event called");
Assert.Pass();
// TODO: XUnit has no // TODO: XUnit has no Assert.Pass() - test passes if no exception is thrown - test passes if no exception is thrown
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated TODO comment text ('XUnit has no' appears twice). The comment should be simplified to: '// In xUnit, test passes if no exception is thrown'.

Suggested change
// TODO: XUnit has no // TODO: XUnit has no Assert.Pass() - test passes if no exception is thrown - test passes if no exception is thrown
// In xUnit, test passes if no exception is thrown

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +43
// TODO: XUnit doesn't have Assert.Fail, use Assert.True(false, ...) or throw
throw new InvalidOperationException("no method invoked");
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test expects an exception to be thrown from button.SendClicked() but instead throws unconditionally after the call. The throw statement should be inside a catch block or the test logic should verify that SendClicked invokes the correct TestBtn overload and throws from there.

Copilot uses AI. Check for mistakes.
public void BindingToEmptyCollection([Values] XamlInflator inflator)
[Theory]
[Values]
public void BindingToEmptyCollection()
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test method signature is missing the XamlInflator inflator parameter but is decorated with [Theory] and [Values]. This will cause a runtime error. Add the inflator parameter and use it in the test method body.

Copilot uses AI. Check for mistakes.
public void BindingThrowsOnWrongConverterParameter([Values] XamlInflator inflator)
[Theory]
[Values]
public void BindingThrowsOnWrongConverterParameter()
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test method is decorated with [Theory] and [Values] but lacks the XamlInflator inflator parameter. Add the parameter to match the attribute usage pattern.

Suggested change
public void BindingThrowsOnWrongConverterParameter()
public void BindingThrowsOnWrongConverterParameter(XamlInflator inflator)

Copilot uses AI. Check for mistakes.
public void RectangleGeometryDoesntThrow([Values] XamlInflator inflator) => Assert.DoesNotThrow(() => new Gh11541(inflator));
[Theory]
[Values]
public void RectangleGeometryDoesntThrow()
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test method is decorated with [Theory] and [Values] but is missing the XamlInflator inflator parameter. This will fail at runtime.

Copilot uses AI. Check for mistakes.
Comment on lines 35 to 37
{
DispatcherProvider.SetCurrent(null);
}
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation in the Dispose method. The method body uses spaces instead of tabs, differing from the surrounding code style. Normalize to match the project's indentation style.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants