Skip to content

Commit

Permalink
Add KeyValuePair tests with collections and IEquatable objects in the…
Browse files Browse the repository at this point in the history
… key slot
  • Loading branch information
bradwilson committed Dec 20, 2023
1 parent c729d7f commit 0cc026b
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions test/test.xunit.assert/Asserts/EqualityAssertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,32 @@ public void ComparerFunc_Throws()

public class KeyValuePair
{
[Fact]
public void CollectionKeys_Equal()
{
var expected = new KeyValuePair<IEnumerable<string>, int>(new List<string> { "Key1", "Key2" }, 42);
var actual = new KeyValuePair<IEnumerable<string>, int>(new List<string> { "Key1", "Key2" }, 42);

Assert.Equal(expected, actual);
}

[Fact]
public void CollectionKeys_NotEqual()
{
var expected = new KeyValuePair<IEnumerable<string>, int>(new List<string> { "Key1", "Key2" }, 42);
var actual = new KeyValuePair<IEnumerable<string>, int>(new List<string> { "Key1", "Key3" }, 42);

var ex = Record.Exception(() => Assert.Equal(expected, actual));

Assert.IsType<EqualException>(ex);
Assert.Equal(
"Assert.Equal() Failure: Values differ" + Environment.NewLine +
"Expected: [[\"Key1\", \"Key2\"]] = 42" + Environment.NewLine +
"Actual: [[\"Key1\", \"Key3\"]] = 42",
ex.Message
);
}

[Fact]
public void CollectionValues_Equal()
{
Expand All @@ -1535,6 +1561,32 @@ public void CollectionValues_NotEqual()
);
}

[Fact]
public void EquatableKeys_Equal()
{
var expected = new KeyValuePair<EquatableObject, int>(new() { Char = 'a' }, 42);
var actual = new KeyValuePair<EquatableObject, int>(new() { Char = 'a' }, 42);

Assert.Equal(expected, actual);
}

[Fact]
public void EquatableKeys_NotEqual()
{
var expected = new KeyValuePair<EquatableObject, int>(new() { Char = 'a' }, 42);
var actual = new KeyValuePair<EquatableObject, int>(new() { Char = 'b' }, 42);

var ex = Record.Exception(() => Assert.Equal(expected, actual));

Assert.IsType<EqualException>(ex);
Assert.Equal(
"Assert.Equal() Failure: Values differ" + Environment.NewLine +
"Expected: [EquatableObject { Char = 'a' }] = 42" + Environment.NewLine +
"Actual: [EquatableObject { Char = 'b' }] = 42",
ex.Message
);
}

[Fact]
public void EquatableValues_Equal()
{
Expand Down Expand Up @@ -3545,6 +3597,32 @@ public void Truncation()

public class KeyValuePair
{
[Fact]
public void CollectionKeys_Equal()
{
var expected = new KeyValuePair<IEnumerable<string>, int>(new List<string> { "Key1", "Key2" }, 42);
var actual = new KeyValuePair<IEnumerable<string>, int>(new List<string> { "Key1", "Key2" }, 42);

var ex = Record.Exception(() => Assert.NotEqual(expected, actual));

Assert.IsType<NotEqualException>(ex);
Assert.Equal(
"Assert.NotEqual() Failure: Values are equal" + Environment.NewLine +
"Expected: Not [[\"Key1\", \"Key2\"]] = 42" + Environment.NewLine +
"Actual: [[\"Key1\", \"Key2\"]] = 42",
ex.Message
);
}

[Fact]
public void CollectionKeys_NotEqual()
{
var expected = new KeyValuePair<IEnumerable<string>, int>(new List<string> { "Key1", "Key2" }, 42);
var actual = new KeyValuePair<IEnumerable<string>, int>(new List<string> { "Key1", "Key3" }, 42);

Assert.NotEqual(expected, actual);
}

[Fact]
public void CollectionValues_Equal()
{
Expand All @@ -3571,6 +3649,32 @@ public void CollectionValues_NotEqual()
Assert.NotEqual(expected, actual);
}

[Fact]
public void EquatableKeys_Equal()
{
var expected = new KeyValuePair<EquatableObject, int>(new() { Char = 'a' }, 42);
var actual = new KeyValuePair<EquatableObject, int>(new() { Char = 'a' }, 42);

var ex = Record.Exception(() => Assert.NotEqual(expected, actual));

Assert.IsType<NotEqualException>(ex);
Assert.Equal(
"Assert.NotEqual() Failure: Values are equal" + Environment.NewLine +
"Expected: Not [EquatableObject { Char = 'a' }] = 42" + Environment.NewLine +
"Actual: [EquatableObject { Char = 'a' }] = 42",
ex.Message
);
}

[Fact]
public void EquatableKeys_NotEqual()
{
var expected = new KeyValuePair<EquatableObject, int>(new() { Char = 'a' }, 42);
var actual = new KeyValuePair<EquatableObject, int>(new() { Char = 'b' }, 42);

Assert.NotEqual(expected, actual);
}

[Fact]
public void EquatableValues_Equal()
{
Expand Down

0 comments on commit 0cc026b

Please sign in to comment.