Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/Build.UnitTests/BackEnd/SdkResultItemComparison_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,47 @@
using Microsoft.Build.Framework;
using Shouldly;
using Xunit;
using SdkResult = Microsoft.Build.BackEnd.SdkResolution.SdkResult;

#nullable disable

namespace Microsoft.Build.Engine.UnitTests.BackEnd
{
public class SdkResultItemComparison_Tests
{
[Fact]
public void SdkResult_NotEqual_DifferentItemsCount()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a comment that this is a regression test for #13490

{
var sdkRef = new SdkReference("SdkName", "1.0.0", "1.0.0");

// One property, two items
var result1 = new SdkResult(
sdkRef,
"path",
"1.0.0",
warnings: null,
propertiesToAdd: new Dictionary<string, string> { { "p1", "v1" } },
itemsToAdd: new Dictionary<string, SdkResultItem>
{
{ "item1", new SdkResultItem("spec1", new Dictionary<string, string>()) },
{ "item2", new SdkResultItem("spec2", new Dictionary<string, string>()) },
});

// One property, one item (items count == properties count of result1, but different items count)
var result2 = new SdkResult(
sdkRef,
"path",
"1.0.0",
warnings: null,
propertiesToAdd: new Dictionary<string, string> { { "p1", "v1" } },
itemsToAdd: new Dictionary<string, SdkResultItem>
{
{ "item1", new SdkResultItem("spec1", new Dictionary<string, string>()) },
});

result1.ShouldNotBe(result2);
}

[Fact]
public void SdkResultItem_Equal_WithDefaultCtor()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/Components/SdkResolution/SdkResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public override bool Equals(object obj)
StringComparer.OrdinalIgnoreCase.Equals(_version, result._version) &&
_additionalPaths?.Count == result._additionalPaths?.Count &&
_propertiesToAdd?.Count == result._propertiesToAdd?.Count &&
_itemsToAdd?.Count == result._propertiesToAdd?.Count &&
_itemsToAdd?.Count == result._itemsToAdd?.Count &&
EqualityComparer<SdkReference>.Default.Equals(_sdkReference, result._sdkReference))
{
if (_additionalPaths != null)
Expand Down