[tests] Upgrade tests/msbuild to NUnit v4 Assert.That syntax#25431
Conversation
Convert classic NUnit assertions (Assert.AreEqual, Assert.IsTrue, Assert.IsNotNull, etc.) to NUnit v4's constraint-based Assert.That syntax across all msbuild test projects. Also update NUnit package references to use centralized version properties from Directory.Build.props. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR modernizes the MSBuild test suites by moving them to NUnit’s constraint-based assertion style (Assert.That) and by centralizing test package versions via properties in Directory.Build.props (bringing these projects in line with other test projects in the repo).
Changes:
- Converted classic NUnit assertions (
Assert.AreEqual,Assert.IsTrue, etc.) to constraint syntax acrosstests/msbuildand shared test helpers. - Updated MSBuild test project package references to use centralized version properties (
$(NUnitPackageVersion),$(NUnit3TestAdapterPackageVersion),$(MicrosoftNETTestSdkPackageVersion)). - Updated shared test utilities in
tests/commonto useAssert.That(compatible with NUnit 3/4).
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj | Switch NUnit/Test SDK package references to centralized version properties. |
| tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/TestBase.cs | Convert helper assertions to Assert.That and adjust assertion messages. |
| tests/msbuild/Xamarin.MacDev.Tests/TargetTests/TargetTests.cs | Convert target test assertions to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tests/TargetTests/DetectSigningIdentityTests.cs | Convert assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tests/TargetTests/CollectAppManifestsTests.cs | Convert assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj | Switch NUnit/Test SDK package references to centralized version properties. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/UtilityTests.cs | Convert assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs | Convert engine/task execution assertions to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs | Convert assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ReadAppManifestTaskTests.cs | Convert assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/PropertyListEditorTaskTests.cs | Convert plist comparison assertions to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ParseBundlerArgumentsTests.cs | Convert argument parsing assertions (including equivalents) to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/MergeAppBundleTaskTest.cs | Convert bundle merge assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationStringTest.cs | Convert translation/resource assertions to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/IBToolTaskTests.cs | Convert IBTool execution/resource assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs | Convert value assertions to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetBundleNameTaskTests.cs | Convert assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetAvailableDevicesTest.cs | Convert device parsing/execution assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_iOS.cs | Convert assertions to constraint syntax in iOS plist tests. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_iOS_AppExtension.cs | Convert assertions to constraint syntax in app extension plist tests. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_Core.cs | Convert core plist assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/DetectSigningIdentityTaskTests.cs | Convert assertions to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/DetectSdkLocationsTaskTests.cs | Convert assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CreateBindingResourceTaskTests.cs | Convert extraction/resource assertions to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs | Convert warning-count and related assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs | Convert entitlement validation assertions to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs | Convert manifest/plist assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CollectITunesArtworkTaskTests.cs | Convert artwork assertions to constraint syntax. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/BundleResourceTests.cs | Convert virtual path assertions to Assert.That. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ACToolTaskTest.cs | Convert asset catalog task assertions to Assert.That. |
| tests/common/mac/ProjectTestHelpers.cs | Convert shared helper assertions to Assert.That. |
| tests/common/DotNet.cs | Convert shared dotnet command assertions to constraint syntax. |
Comments suppressed due to low confidence (4)
tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_Core.cs:134
- These
Assert.Thatcalls have the expected/actual order inverted (constant/expected value passed as the actual argument, and the plist value insideIs.EqualTo(...)). This will produce confusing failure messages; pass the plist value as the actual and the constant/expected as the constraint value instead.
Assert.That (CompiledPlist.ContainsKey (ManifestKeys.CFBundleName), "#1");
Assert.That (appBundleName, Is.EqualTo (CompiledPlist.Get<PString> (ManifestKeys.CFBundleName)?.Value), "#2");
}
tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_Core.cs:141
- These
Assert.Thatcalls have the expected/actual order inverted (constant/expected value passed as the actual argument, and the plist value insideIs.EqualTo(...)). This will produce confusing failure messages; pass the plist value as the actual and the constant/expected as the constraint value instead.
Assert.That (CompiledPlist.ContainsKey (ManifestKeys.CFBundleIdentifier), "#1");
Assert.That (bundleIdentifier, Is.EqualTo (CompiledPlist.Get<PString> (ManifestKeys.CFBundleIdentifier)?.Value), "#2");
}
tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_Core.cs:155
- These
Assert.Thatcalls have the expected/actual order inverted (constant/expected value passed as the actual argument, and the plist value insideIs.EqualTo(...)). This will produce confusing failure messages; pass the plist value as the actual and the constant/expected as the constraint value instead.
Assert.That (CompiledPlist.ContainsKey (ManifestKeys.CFBundlePackageType), "#1");
Assert.That ("APPL", Is.EqualTo (CompiledPlist.Get<PString> (ManifestKeys.CFBundlePackageType)?.Value), "#2");
}
tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_Core.cs:162
- These
Assert.Thatcalls have the expected/actual order inverted (constant/expected value passed as the actual argument, and the plist value insideIs.EqualTo(...)). This will produce confusing failure messages; pass the plist value as the actual and the constant/expected as the constraint value instead.
Assert.That (CompiledPlist.ContainsKey (ManifestKeys.CFBundleSignature), "#1");
Assert.That ("????", Is.EqualTo (CompiledPlist.Get<PString> (ManifestKeys.CFBundleSignature)?.Value), "#2");
}
|
|
||
| var archived = PDictionary.FromFile (archivedEntitlements); | ||
| Assert.IsTrue (compiled.ContainsKey ("application-identifier"), "archived"); | ||
| Assert.That (compiled.ContainsKey ("application-identifier"), Is.True, "archived"); |
| Assert.That (CompiledPlist.ContainsKey (ManifestKeys.CFBundleExecutable), "#1"); | ||
| Assert.AreEqual (CompiledPlist.Get<PString> (ManifestKeys.CFBundleExecutable)?.Value, assemblyName, "#2"); | ||
| Assert.That (assemblyName, Is.EqualTo (CompiledPlist.Get<PString> (ManifestKeys.CFBundleExecutable)?.Value), "#2"); | ||
| } |
| { | ||
| Assert.That (CompiledPlist.ContainsKey (ManifestKeys.CFBundleName), "#1"); | ||
| Assert.AreEqual (CompiledPlist.Get<PString> (ManifestKeys.CFBundleName)?.Value, appBundleName, "#2"); | ||
| Assert.That (appBundleName, Is.EqualTo (CompiledPlist.Get<PString> (ManifestKeys.CFBundleName)?.Value), "#2"); |
| { | ||
| Assert.That (CompiledPlist.ContainsKey (ManifestKeys.CFBundlePackageType), "#1"); | ||
| Assert.AreEqual (CompiledPlist.Get<PString> (ManifestKeys.CFBundlePackageType)?.Value, "XPC!", "#2"); | ||
| Assert.That ("XPC!", Is.EqualTo (CompiledPlist.Get<PString> (ManifestKeys.CFBundlePackageType)?.Value), "#2"); |
✅ [PR Build #5f5478d] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #5f5478d] Build passed (Build packages) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [PR Build #5f5478d] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #5f5478d] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 175 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Convert classic NUnit assertions (
Assert.AreEqual,Assert.IsTrue,Assert.IsNotNull, etc.) to NUnit v4's constraint-basedAssert.Thatsyntax in the msbuild test projects.Also update package references to use centralized version properties from
Directory.Build.props:NUnit→$(NUnitPackageVersion)NUnit3TestAdapter→$(NUnit3TestAdapterPackageVersion)Microsoft.NET.Test.Sdk→$(MicrosoftNETTestSdkPackageVersion)Two shared files (
tests/common/DotNet.cs,tests/common/mac/ProjectTestHelpers.cs) are also converted — theAssert.Thatconstraint syntax is compatible with both NUnit 3 and 4, so other projects referencing these files are unaffected.All
tests-msbuildtests pass (495 passed, 0 failed).🤖 Pull request created by Copilot