Skip to content

Commit

Permalink
Add tests for KeyValuePair<>/Dictionary ArgumentFormatter update
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Jul 6, 2022
1 parent 1109d48 commit 32d21fb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/xunit.assert/Asserts
Submodule Asserts updated 1 files
+12 −15 Sdk/ArgumentFormatter.cs
24 changes: 12 additions & 12 deletions test/test.xunit.assert/Asserts/EquivalenceAssertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,8 @@ public void Failure()
Assert.IsType<EquivalentException>(ex);
Assert.Equal(
"Assert.Equivalent() Failure: Collection value not found" + Environment.NewLine +
"Expected: [Foo, 16]" + Environment.NewLine +
"In: [[Foo, 42], [Bar, 2112]]",
"Expected: [\"Foo\"] = 16" + Environment.NewLine +
"In: [[\"Foo\"] = 42, [\"Bar\"] = 2112]",
ex.Message
);
}
Expand All @@ -938,8 +938,8 @@ public void Failure_EmbeddedDictionary()
Assert.IsType<EquivalentException>(ex);
Assert.Equal(
"Assert.Equivalent() Failure: Collection value not found in member 'x'" + Environment.NewLine +
"Expected: [Foo, 16]" + Environment.NewLine +
"In: [[Foo, 42], [Bar, 2112]]",
"Expected: [\"Foo\"] = 16" + Environment.NewLine +
"In: [[\"Foo\"] = 42, [\"Bar\"] = 2112]",
ex.Message
);
}
Expand Down Expand Up @@ -976,8 +976,8 @@ public void Failure_ValueNotFoundInActual()
Assert.IsType<EquivalentException>(ex);
Assert.Equal(
"Assert.Equivalent() Failure: Collection value not found" + Environment.NewLine +
"Expected: [Foo, 16]" + Environment.NewLine +
"In: [[Foo, 42], [Bar, 2112]]",
"Expected: [\"Foo\"] = 16" + Environment.NewLine +
"In: [[\"Foo\"] = 42, [\"Bar\"] = 2112]",
ex.Message
);
}
Expand All @@ -993,8 +993,8 @@ public void Failure_ExtraValueInActual()
Assert.IsType<EquivalentException>(ex);
Assert.Equal(
"Assert.Equivalent() Failure: Extra values found" + Environment.NewLine +
"Expected: [[Bar, 2112], [Foo, 42]]" + Environment.NewLine +
"Actual: [[Biff, 2600]] left over from [[Foo, 42], [Biff, 2600], [Bar, 2112]]",
"Expected: [[\"Bar\"] = 2112, [\"Foo\"] = 42]" + Environment.NewLine +
"Actual: [[\"Biff\"] = 2600] left over from [[\"Foo\"] = 42, [\"Biff\"] = 2600, [\"Bar\"] = 2112]",
ex.Message
);
}
Expand All @@ -1010,8 +1010,8 @@ public void Failure_EmbeddedDictionary_ValueNotFoundInActual()
Assert.IsType<EquivalentException>(ex);
Assert.Equal(
"Assert.Equivalent() Failure: Collection value not found in member 'x'" + Environment.NewLine +
"Expected: [Foo, 16]" + Environment.NewLine +
"In: [[Foo, 42], [Bar, 2112]]",
"Expected: [\"Foo\"] = 16" + Environment.NewLine +
"In: [[\"Foo\"] = 42, [\"Bar\"] = 2112]",
ex.Message
);
}
Expand All @@ -1027,8 +1027,8 @@ public void Failure_EmbeddedDictionary_ExtraValueInActual()
Assert.IsType<EquivalentException>(ex);
Assert.Equal(
"Assert.Equivalent() Failure: Extra values found in member 'x'" + Environment.NewLine +
"Expected: [[Bar, 2112], [Foo, 42]]" + Environment.NewLine +
"Actual: [[Biff, 2600]] left over from [[Foo, 42], [Biff, 2600], [Bar, 2112]]",
"Expected: [[\"Bar\"] = 2112, [\"Foo\"] = 42]" + Environment.NewLine +
"Actual: [[\"Biff\"] = 2600] left over from [[\"Foo\"] = 42, [\"Biff\"] = 2600, [\"Bar\"] = 2112]",
ex.Message
);
}
Expand Down
25 changes: 25 additions & 0 deletions test/test.xunit.assert/Asserts/Sdk/ArgumentFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ public static void Flags(FlagsEnum enumValue, string expected)
}
}

public class KeyValuePair
{
[CulturedFact]
public static void KeyValuePairValue()
{
var kvp = new KeyValuePair<object, List<object>>(42, new() { 21.12M, "2600" });
var expected = $"[42] = [{21.12M}, \"2600\"]";

Assert.Equal(expected, ArgumentFormatter.Format(kvp));
}
}

public class Enumerables
{
[CulturedFact]
Expand All @@ -247,6 +259,19 @@ public static void EnumerableValue()
Assert.Equal(expected, ArgumentFormatter.Format(new object[] { 1, 2.3M, "Hello, world!" }));
}

[CulturedFact]
public static void DictionaryValue()
{
var value = new Dictionary<object, List<object>>
{
{ 42, new() { 21.12M, "2600" } },
{ "123", new() { } },
};
var expected = $"[[42] = [{21.12M}, \"2600\"], [\"123\"] = []]";

Assert.Equal(expected, ArgumentFormatter.Format(value));
}

[CulturedFact]
public static void OnlyFirstFewValuesOfEnumerableAreRendered()
{
Expand Down

0 comments on commit 32d21fb

Please sign in to comment.