[xharness] Fix bug in Simulators.LoadAsync() (#5605)

The "Gizmo" and "Companion" are child elements, not attributes on the SimDevicePair.

Also replaced the custom Distinct() implementation with a comparer which can be used with standard LINQ.
This commit is contained in:
Alexander Köplinger 2019-02-14 13:54:31 +01:00 коммит произвёл Rolf Bjarne Kvinge
Родитель ab2709fb76
Коммит 3974db63c3
2 изменённых файлов: 14 добавлений и 19 удалений

Просмотреть файл

@ -119,23 +119,5 @@ namespace xharness
//
// This makes it abundantly clear that the intention is to not await 'DoSomething', and no warnings will be shown either.
}
public static IEnumerable<T> Distinct<T> (this IEnumerable<T> collection, Func<T, T, bool> comparer)
{
var list = new List<T> ();
foreach (var item in collection) {
bool found = false;
for (var i = 0; i < list.Count; i++) {
if (comparer (list [i], item)) {
found = true;
break;
}
}
if (found)
continue;
list.Add (item);
yield return item;
}
}
}
}

Просмотреть файл

@ -99,7 +99,7 @@ namespace xharness
SelectNodes ("/MTouch/Simulator/AvailableDevicePairs/SimDevicePair").
Cast<XmlNode> ().
// There can be duplicates, so remove those.
Distinct ((a, b) => a.Attributes ["Gizmo"].InnerText == b.Attributes ["Gizmo"].InnerText && a.Attributes ["Companion"].InnerText == b.Attributes ["Companion"].InnerText);
Distinct (new SimulatorXmlNodeComparer ());
foreach (XmlNode sim in sim_device_pairs) {
available_device_pairs.Add (new SimDevicePair ()
{
@ -324,6 +324,19 @@ namespace xharness
};
}
class SimulatorXmlNodeComparer : IEqualityComparer<XmlNode>
{
public bool Equals (XmlNode a, XmlNode b)
{
return a["Gizmo"].InnerText == b["Gizmo"].InnerText && a["Companion"].InnerText == b["Companion"].InnerText;
}
public int GetHashCode (XmlNode node)
{
return node["Gizmo"].InnerText.GetHashCode () ^ node["Companion"].InnerText.GetHashCode ();
}
}
class SimulatorEnumerable : IEnumerable<SimDevice>, IAsyncEnumerable
{
public Simulators Simulators;