Skip to content
Open
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
28 changes: 27 additions & 1 deletion Adyen.Test/Core/IEnumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,32 @@ public async Task Given_JsonDeserialization_When_ExampleEnum_Is_A_Then_Deseriali
Assert.AreEqual(ExampleEnum.A, result.ExampleEnum);
}

[TestMethod]
public void Given_GetHashCode_When_SameValueDifferentCase_Then_HashCodesAreEqual()
{
ExampleEnum lower = (ExampleEnum)"active";
ExampleEnum upper = (ExampleEnum)"ACTIVE";

// Equals must be true (already works)
Assert.IsTrue(lower.Equals(upper));

// GetHashCode must also be equal — this is the contract being fixed
Assert.AreEqual(lower.GetHashCode(), upper.GetHashCode());
}

[TestMethod]
public void Given_DictionaryWithEnumKey_When_LookupWithDifferentCase_Then_FindsEntry()
{
var dict = new Dictionary<ExampleEnum, string>
{
{ (ExampleEnum)"active", "found" }
};

// Before the fix this would silently return false — key not found
Assert.IsTrue(dict.ContainsKey((ExampleEnum)"ACTIVE"));
Assert.AreEqual("found", dict[(ExampleEnum)"ACTIVE"]);
}

internal class ExampleModelResponse
{
/// <summary>
Expand Down Expand Up @@ -314,7 +340,7 @@ private ExampleEnum(string? value)

public override bool Equals(object? obj) => obj is ExampleEnum other && string.Equals(Value, other.Value, StringComparison.OrdinalIgnoreCase);

public override int GetHashCode() => Value?.GetHashCode() ?? 0;
public override int GetHashCode() => Value != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(Value) : 0;

public static bool operator ==(ExampleEnum? left, ExampleEnum? right) =>
string.Equals(left?.Value, right?.Value, StringComparison.OrdinalIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
/// <summary>
/// Returns a hash code for this <see cref="{{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}"/> instance.
/// </summary>
public override int GetHashCode() => Value?.GetHashCode() ?? 0;
public override int GetHashCode() => Value != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(Value) : 0;

/// <summary>
/// Returns the string value of the <see cref="{{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}"/> instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
/// <summary>
/// Returns a hash code for this <see cref="{{datatypeWithEnum}}"/> instance.
/// </summary>
public override int GetHashCode() => Value?.GetHashCode() ?? 0;
public override int GetHashCode() => Value != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(Value) : 0;

/// <summary>
/// Returns the string value of the <see cref="{{datatypeWithEnum}}"/> instance.
Expand Down