Skip to content

Commit

Permalink
Unit tests for #2850 (v3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Dec 20, 2023
1 parent 460901f commit 5b64d0e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
36 changes: 20 additions & 16 deletions src/xunit.v3.assert.tests/Asserts/CollectionAssertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,15 +1303,16 @@ public static void SomeKeysDiffer()
[Fact]
public static void WithCollectionValues_Equal()
{
var expected = new Dictionary<string, List<string>>
// Different concrete collection types in the value slot, per https://github.com/xunit/xunit/issues/2850
var expected = new Dictionary<string, IEnumerable<string>>
{
["toAddresses"] = new List<string> { "test1@example.com" },
["ccAddresses"] = new List<string> { "test2@example.com" },
};
var actual = new Dictionary<string, List<string>>
var actual = new Dictionary<string, IEnumerable<string>>
{
["toAddresses"] = new List<string> { "test1@example.com" },
["ccAddresses"] = new List<string> { "test2@example.com" },
["toAddresses"] = new string[] { "test1@example.com" },
["ccAddresses"] = new string[] { "test2@example.com" },
};

Assert.Equal(expected, actual);
Expand All @@ -1320,15 +1321,16 @@ public static void WithCollectionValues_Equal()
[Fact]
public static void WithCollectionValues_NotEqual()
{
var expected = new Dictionary<string, List<string>>
// Different concrete collection types in the value slot, per https://github.com/xunit/xunit/issues/2850
var expected = new Dictionary<string, IEnumerable<string>>
{
["toAddresses"] = new List<string> { "test1@example.com" },
["ccAddresses"] = new List<string> { "test2@example.com" },
};
var actual = new Dictionary<string, List<string>>
var actual = new Dictionary<string, IEnumerable<string>>
{
["toAddresses"] = new List<string> { "test1@example.com" },
["ccAddresses"] = new List<string> { "test3@example.com" },
["toAddresses"] = new string[] { "test1@example.com" },
["ccAddresses"] = new string[] { "test3@example.com" },
};

var ex = Record.Exception(() => Assert.Equal(expected, actual));
Expand Down Expand Up @@ -1952,15 +1954,16 @@ public static void SomeKeysDiffer()
[Fact]
public static void WithCollectionValues_Equal()
{
var expected = new Dictionary<string, List<string>>
// Different concrete collection types in the value slot, per https://github.com/xunit/xunit/issues/2850
var expected = new Dictionary<string, IEnumerable<string>>
{
["toAddresses"] = new List<string> { "test1@example.com" },
["ccAddresses"] = new List<string> { "test2@example.com" },
};
var actual = new Dictionary<string, List<string>>
var actual = new Dictionary<string, IEnumerable<string>>
{
["toAddresses"] = new List<string> { "test1@example.com" },
["ccAddresses"] = new List<string> { "test2@example.com" },
["toAddresses"] = new string[] { "test1@example.com" },
["ccAddresses"] = new string[] { "test2@example.com" },
};

var ex = Record.Exception(() => Assert.NotEqual(expected, actual));
Expand All @@ -1977,15 +1980,16 @@ public static void WithCollectionValues_Equal()
[Fact]
public static void WithCollectionValues_NotEqual()
{
var expected = new Dictionary<string, List<string>>
// Different concrete collection types in the value slot, per https://github.com/xunit/xunit/issues/2850
var expected = new Dictionary<string, IEnumerable<string>>
{
["toAddresses"] = new List<string> { "test1@example.com" },
["ccAddresses"] = new List<string> { "test2@example.com" },
};
var actual = new Dictionary<string, List<string>>
var actual = new Dictionary<string, IEnumerable<string>>
{
["toAddresses"] = new List<string> { "test1@example.com" },
["ccAddresses"] = new List<string> { "test3@example.com" },
["toAddresses"] = new string[] { "test1@example.com" },
["ccAddresses"] = new string[] { "test3@example.com" },
};

Assert.NotEqual(expected, actual);
Expand Down
32 changes: 20 additions & 12 deletions src/xunit.v3.assert.tests/Asserts/EqualityAssertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,17 +1512,19 @@ public class KeyValuePair
[Fact]
public void CollectionKeys_Equal()
{
// Different concrete collection types in the key slot, per https://github.com/xunit/xunit/issues/2850
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 actual = new KeyValuePair<IEnumerable<string>, int>(new string[] { "Key1", "Key2" }, 42);

Assert.Equal(expected, actual);
}

[Fact]
public void CollectionKeys_NotEqual()
{
// Different concrete collection types in the key slot, per https://github.com/xunit/xunit/issues/2850
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 actual = new KeyValuePair<IEnumerable<string>, int>(new string[] { "Key1", "Key3" }, 42);

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

Expand All @@ -1538,17 +1540,19 @@ public void CollectionKeys_NotEqual()
[Fact]
public void CollectionValues_Equal()
{
var expected = new KeyValuePair<string, List<string>>("Key1", new() { "Value1a", "Value1b" });
var actual = new KeyValuePair<string, List<string>>("Key1", new() { "Value1a", "Value1b" });
// Different concrete collection types in the value slot, per https://github.com/xunit/xunit/issues/2850
var expected = new KeyValuePair<string, IEnumerable<string>>("Key1", new List<string> { "Value1a", "Value1b" });
var actual = new KeyValuePair<string, IEnumerable<string>>("Key1", new string[] { "Value1a", "Value1b" });

Assert.Equal(expected, actual);
}

[Fact]
public void CollectionValues_NotEqual()
{
var expected = new KeyValuePair<string, List<string>>("Key1", new() { "Value1a", "Value1b" });
var actual = new KeyValuePair<string, List<string>>("Key1", new() { "Value1a", "Value2a" });
// Different concrete collection types in the value slot, per https://github.com/xunit/xunit/issues/2850
var expected = new KeyValuePair<string, IEnumerable<string>>("Key1", new List<string> { "Value1a", "Value1b" });
var actual = new KeyValuePair<string, IEnumerable<string>>("Key1", new string[] { "Value1a", "Value2a" });

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

Expand Down Expand Up @@ -3600,8 +3604,9 @@ public class KeyValuePair
[Fact]
public void CollectionKeys_Equal()
{
// Different concrete collection types in the key slot, per https://github.com/xunit/xunit/issues/2850
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 actual = new KeyValuePair<IEnumerable<string>, int>(new string[] { "Key1", "Key2" }, 42);

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

Expand All @@ -3617,17 +3622,19 @@ public void CollectionKeys_Equal()
[Fact]
public void CollectionKeys_NotEqual()
{
// Different concrete collection types in the key slot, per https://github.com/xunit/xunit/issues/2850
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 actual = new KeyValuePair<IEnumerable<string>, int>(new string[] { "Key1", "Key3" }, 42);

Assert.NotEqual(expected, actual);
}

[Fact]
public void CollectionValues_Equal()
{
var expected = new KeyValuePair<string, List<string>>("Key1", new() { "Value1a", "Value1b" });
var actual = new KeyValuePair<string, List<string>>("Key1", new() { "Value1a", "Value1b" });
// Different concrete collection types in the key slot, per https://github.com/xunit/xunit/issues/2850
var expected = new KeyValuePair<string, IEnumerable<string>>("Key1", new List<string> { "Value1a", "Value1b" });
var actual = new KeyValuePair<string, IEnumerable<string>>("Key1", new string[] { "Value1a", "Value1b" });

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

Expand All @@ -3643,8 +3650,9 @@ public void CollectionValues_Equal()
[Fact]
public void CollectionValues_NotEqual()
{
var expected = new KeyValuePair<string, List<string>>("Key1", new() { "Value1a", "Value1b" });
var actual = new KeyValuePair<string, List<string>>("Key1", new() { "Value1a", "Value2a" });
// Different concrete collection types in the key slot, per https://github.com/xunit/xunit/issues/2850
var expected = new KeyValuePair<string, IEnumerable<string>>("Key1", new List<string> { "Value1a", "Value1b" });
var actual = new KeyValuePair<string, IEnumerable<string>>("Key1", new string[] { "Value1a", "Value2a" });

Assert.NotEqual(expected, actual);
}
Expand Down
2 changes: 1 addition & 1 deletion src/xunit.v3.assert/Asserts

0 comments on commit 5b64d0e

Please sign in to comment.