Skip to content

Commit

Permalink
Added a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mgesing committed Dec 17, 2024
1 parent f109147 commit 0fd90a7
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
Expand Down Expand Up @@ -134,6 +135,29 @@ public async Task Can_find_attribute_combination_by_hashcode(
Assert.That(variant2, Is.Null);
}

[Test]
public void Can_create_consistent_attribute_combination_hashcodes()
{
var selection = new ProductVariantAttributeSelection(null);
selection.AddAttribute(1234, [987654]);
selection.AddAttribute(556677, [1234, 56789]);

var expectedHashCodes = new Dictionary<string, int>
{
["{\"Attributes\":[{\"Key\":5141,\"Value\":[7546]}]}"] = 2063729868,
["{\"Attributes\":[{\"Key\":5141,\"Value\":[7547]}]}"] = -1960489098,
["{\"Attributes\":[{\"Key\":5141,\"Value\":[7569]}]}"] = -2032748638,
["{\"Attributes\":[{\"Key\":5141,\"Value\":[7570]}]}"] = -755678158,
[selection.AsJson()] = -1989637677
};

foreach (var pair in expectedHashCodes)
{
var hashCode = new ProductVariantAttributeSelection(pair.Key).GetHashCode();
Assert.That(hashCode, Is.EqualTo(pair.Value));
}
}

private static ProductVariantAttributeSelection CreateAttributeSelection(
int? anyNumber = null,
bool includeGiftCard = false,
Expand Down

0 comments on commit 0fd90a7

Please sign in to comment.