From 90bed2917514403e4b2f88c4277bbb535caddf20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Thu, 14 Feb 2019 03:51:20 +0100 Subject: [PATCH] [xharness] Fix bug in Simulators.LoadAsync() 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. --- tests/xharness/Extensions.cs | 18 ------------------ tests/xharness/Simulators.cs | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tests/xharness/Extensions.cs b/tests/xharness/Extensions.cs index 0fa00b7210..6a86822630 100644 --- a/tests/xharness/Extensions.cs +++ b/tests/xharness/Extensions.cs @@ -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 Distinct (this IEnumerable collection, Func comparer) - { - var list = new List (); - 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; - } - } } } diff --git a/tests/xharness/Simulators.cs b/tests/xharness/Simulators.cs index 1876327246..3a3021127b 100644 --- a/tests/xharness/Simulators.cs +++ b/tests/xharness/Simulators.cs @@ -99,7 +99,7 @@ namespace xharness SelectNodes ("/MTouch/Simulator/AvailableDevicePairs/SimDevicePair"). Cast (). // 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 + { + 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, IAsyncEnumerable { public Simulators Simulators;