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: 18 additions & 10 deletions src/TestFramework/TestFramework/Assertions/CollectionAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,31 +1625,37 @@ private static bool AreCollectionsEqual(ICollection? expected, ICollection? actu
return true;
}

return CompareIEnumerable(expected, actual, comparer, ref reason);
string fullExpectedStr = expected == null ? "null" : string.Join(", ", expected.Cast<object>().Select(x => Convert.ToString(Assert.ReplaceNulls(x), CultureInfo.InvariantCulture)));
string fullActualStr = actual == null ? "null" : string.Join(", ", actual.Cast<object>().Select(x => Convert.ToString(Assert.ReplaceNulls(x), CultureInfo.InvariantCulture)));

return CompareIEnumerable(expected, actual, comparer, ref reason, fullExpectedStr, fullActualStr);
}

private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actual, IComparer comparer, ref string reason)
private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actual, IComparer comparer, ref string reason, string fullExpected, string fullActual)
{
if ((expected == null) || (actual == null))
{
reason = string.Format(CultureInfo.CurrentCulture, "Collections differ in nullability.\nExpected: {0}\nActual: {1}", fullExpected, fullActual);
return false;
}

var stack = new Stack<Tuple<IEnumerator, IEnumerator, int>>();
stack.Push(new(expected.GetEnumerator(), actual.GetEnumerator(), 0));
var stack = new Stack<Tuple<IEnumerator, IEnumerator, int, string, string>>();
stack.Push(new(expected.GetEnumerator(), actual.GetEnumerator(), 0, fullExpected, fullActual));

while (stack.Count > 0)
{
Tuple<IEnumerator, IEnumerator, int> cur = stack.Pop();
Tuple<IEnumerator, IEnumerator, int, string, string> cur = stack.Pop();
IEnumerator expectedEnum = cur.Item1;
IEnumerator actualEnum = cur.Item2;
int position = cur.Item3;
string fullExp = cur.Item4;
string fullAct = cur.Item5;

while (expectedEnum.MoveNext())
{
if (!actualEnum.MoveNext())
{
reason = FrameworkMessages.NumberOfElementsDiff;
reason = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.NumberOfElementsDiff, fullExp, fullAct);
return false;
}

Expand All @@ -1661,8 +1667,8 @@ private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actua
}
else if (curExpected is IEnumerable curExpectedEnum && curActual is IEnumerable curActualEnum)
{
stack.Push(new(expectedEnum, actualEnum, position + 1));
stack.Push(new(curExpectedEnum.GetEnumerator(), curActualEnum.GetEnumerator(), 0));
stack.Push(new(expectedEnum, actualEnum, position + 1, fullExp, fullAct));
stack.Push(new(curExpectedEnum.GetEnumerator(), curActualEnum.GetEnumerator(), 0, fullExp, fullAct));
}
else if (comparer.Compare(curExpected, curActual) != 0)
{
Expand All @@ -1671,14 +1677,16 @@ private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actua
FrameworkMessages.ElementsAtIndexDontMatch,
position,
Assert.ReplaceNulls(curExpected),
Assert.ReplaceNulls(curActual));
Assert.ReplaceNulls(curActual),
fullExp,
fullAct);
return false;
}
}

if (actualEnum.MoveNext() && !expectedEnum.MoveNext())
{
reason = FrameworkMessages.NumberOfElementsDiff;
reason = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.NumberOfElementsDiff, fullExp, fullAct);
return false;
}
}
Expand Down
62 changes: 33 additions & 29 deletions src/TestFramework/TestFramework/Resources/FrameworkMessages.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema

Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple

There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -192,7 +192,9 @@
<data name="ElementsAtIndexDontMatch" xml:space="preserve">
<value>Element at index {0} do not match.
Expected: {1}
Actual: {2}</value>
Actual: {2}
Full Expected: {3}
Full Actual: {4}</value>
</data>
<data name="ElementTypesAtIndexDontMatch" xml:space="preserve">
<value>Element at index {1} is not of expected type. Expected type:&lt;{2}&gt;. Actual type:&lt;{3}&gt;.{0}</value>
Expand Down Expand Up @@ -233,7 +235,9 @@ Actual: {2}</value>
<value>The parameter '{0}' is invalid. The value cannot be null. {1}.</value>
</data>
<data name="NumberOfElementsDiff" xml:space="preserve">
<value>Different number of elements.</value>
<value>Different number of elements.
Expected: {0}
Actual: {1}</value>
</data>
<data name="StartsWithFail" xml:space="preserve">
<value>String '{0}' does not start with string '{1}'. {2}</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@
<trans-unit id="ElementsAtIndexDontMatch">
<source>Element at index {0} do not match.
Expected: {1}
Actual: {2}</source>
<target state="translated">Element v indexu {0} nesouhlasí.
Očekáváno: {1}
Skutečnost: {2}</target>
Actual: {2}
Full Expected: {3}
Full Actual: {4}</source>
<target state="new">Element at index {0} do not match.
Expected: {1}
Actual: {2}
Full Expected: {3}
Full Actual: {4}</target>
<note />
</trans-unit>
<trans-unit id="ElementTypesAtIndexDontMatch">
Expand Down Expand Up @@ -279,9 +283,13 @@ Skutečnost: {2}</target>
<note></note>
</trans-unit>
<trans-unit id="NumberOfElementsDiff">
<source>Different number of elements.</source>
<target state="translated">Rozdílný počet elementů.</target>
<note></note>
<source>Different number of elements.
Expected: {0}
Actual: {1}</source>
<target state="new">Different number of elements.
Expected: {0}
Actual: {1}</target>
<note />
</trans-unit>
<trans-unit id="ReturnedSubsetValueMessage">
<source>Element(s) &lt;{0}&gt; is/are not present in the collection.</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@
<trans-unit id="ElementsAtIndexDontMatch">
<source>Element at index {0} do not match.
Expected: {1}
Actual: {2}</source>
<target state="translated">Das Element bei Index {0} stimmt nicht überein.
Erwartet: {1}
Tatsächlich: {2}</target>
Actual: {2}
Full Expected: {3}
Full Actual: {4}</source>
<target state="new">Element at index {0} do not match.
Expected: {1}
Actual: {2}
Full Expected: {3}
Full Actual: {4}</target>
<note />
</trans-unit>
<trans-unit id="ElementTypesAtIndexDontMatch">
Expand Down Expand Up @@ -279,9 +283,13 @@ Tatsächlich: {2}</target>
<note></note>
</trans-unit>
<trans-unit id="NumberOfElementsDiff">
<source>Different number of elements.</source>
<target state="translated">Unterschiedliche Anzahl von Elementen.</target>
<note></note>
<source>Different number of elements.
Expected: {0}
Actual: {1}</source>
<target state="new">Different number of elements.
Expected: {0}
Actual: {1}</target>
<note />
</trans-unit>
<trans-unit id="ReturnedSubsetValueMessage">
<source>Element(s) &lt;{0}&gt; is/are not present in the collection.</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@
<trans-unit id="ElementsAtIndexDontMatch">
<source>Element at index {0} do not match.
Expected: {1}
Actual: {2}</source>
<target state="translated">El elemento del índice {0} no coincide.
Esperado: {1}
Real: {2}</target>
Actual: {2}
Full Expected: {3}
Full Actual: {4}</source>
<target state="new">Element at index {0} do not match.
Expected: {1}
Actual: {2}
Full Expected: {3}
Full Actual: {4}</target>
<note />
</trans-unit>
<trans-unit id="ElementTypesAtIndexDontMatch">
Expand Down Expand Up @@ -279,9 +283,13 @@ Real: {2}</target>
<note></note>
</trans-unit>
<trans-unit id="NumberOfElementsDiff">
<source>Different number of elements.</source>
<target state="translated">Número diferente de elementos.</target>
<note></note>
<source>Different number of elements.
Expected: {0}
Actual: {1}</source>
<target state="new">Different number of elements.
Expected: {0}
Actual: {1}</target>
<note />
</trans-unit>
<trans-unit id="ReturnedSubsetValueMessage">
<source>Element(s) &lt;{0}&gt; is/are not present in the collection.</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@
<trans-unit id="ElementsAtIndexDontMatch">
<source>Element at index {0} do not match.
Expected: {1}
Actual: {2}</source>
<target state="translated">L’élément au {0} d’index ne correspond pas.
Attendu : {1}
Réel : {2}</target>
Actual: {2}
Full Expected: {3}
Full Actual: {4}</source>
<target state="new">Element at index {0} do not match.
Expected: {1}
Actual: {2}
Full Expected: {3}
Full Actual: {4}</target>
<note />
</trans-unit>
<trans-unit id="ElementTypesAtIndexDontMatch">
Expand Down Expand Up @@ -279,9 +283,13 @@ Réel : {2}</target>
<note></note>
</trans-unit>
<trans-unit id="NumberOfElementsDiff">
<source>Different number of elements.</source>
<target state="translated">Nombre d'éléments différent.</target>
<note></note>
<source>Different number of elements.
Expected: {0}
Actual: {1}</source>
<target state="new">Different number of elements.
Expected: {0}
Actual: {1}</target>
<note />
</trans-unit>
<trans-unit id="ReturnedSubsetValueMessage">
<source>Element(s) &lt;{0}&gt; is/are not present in the collection.</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@
<trans-unit id="ElementsAtIndexDontMatch">
<source>Element at index {0} do not match.
Expected: {1}
Actual: {2}</source>
<target state="translated">L'elemento nell'indice {0} non corrisponde.
Previsto: {1}
Effettivo: {2}</target>
Actual: {2}
Full Expected: {3}
Full Actual: {4}</source>
<target state="new">Element at index {0} do not match.
Expected: {1}
Actual: {2}
Full Expected: {3}
Full Actual: {4}</target>
<note />
</trans-unit>
<trans-unit id="ElementTypesAtIndexDontMatch">
Expand Down Expand Up @@ -279,9 +283,13 @@ Effettivo: {2}</target>
<note></note>
</trans-unit>
<trans-unit id="NumberOfElementsDiff">
<source>Different number of elements.</source>
<target state="translated">Il numero di elementi è diverso.</target>
<note></note>
<source>Different number of elements.
Expected: {0}
Actual: {1}</source>
<target state="new">Different number of elements.
Expected: {0}
Actual: {1}</target>
<note />
</trans-unit>
<trans-unit id="ReturnedSubsetValueMessage">
<source>Element(s) &lt;{0}&gt; is/are not present in the collection.</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@
<trans-unit id="ElementsAtIndexDontMatch">
<source>Element at index {0} do not match.
Expected: {1}
Actual: {2}</source>
<target state="translated">インデックス {0} の要素が一致しません。
予想: {1}
実際: {2}</target>
Actual: {2}
Full Expected: {3}
Full Actual: {4}</source>
<target state="new">Element at index {0} do not match.
Expected: {1}
Actual: {2}
Full Expected: {3}
Full Actual: {4}</target>
<note />
</trans-unit>
<trans-unit id="ElementTypesAtIndexDontMatch">
Expand Down Expand Up @@ -279,9 +283,13 @@ Actual: {2}</source>
<note></note>
</trans-unit>
<trans-unit id="NumberOfElementsDiff">
<source>Different number of elements.</source>
<target state="translated">要素数が異なります。</target>
<note></note>
<source>Different number of elements.
Expected: {0}
Actual: {1}</source>
<target state="new">Different number of elements.
Expected: {0}
Actual: {1}</target>
<note />
</trans-unit>
<trans-unit id="ReturnedSubsetValueMessage">
<source>Element(s) &lt;{0}&gt; is/are not present in the collection.</source>
Expand Down
Loading
Loading