public void InRangeNoIComparableTest(object testObj, object from, object to, ObjectToStringComparer comparer) { Assert.That(testObj, Is.InRange(from, to).Using(comparer)); Assert.AreEqual(comparer.WasCalled, true); }
private void UpdateSelectedItemsFromTextTimer_Tick(object sender, EventArgs e) { _updateSelectedItemsFromTextTimer.Stop(); bool foundItem; // We clear the selection if there is no text available. if (string.IsNullOrEmpty(Text)) { switch (SelectionMode) { case SelectionMode.Single: SelectedItem = null; break; case SelectionMode.Multiple: case SelectionMode.Extended: SelectedItems.Clear(); break; default: throw new NotSupportedException("Unknown SelectionMode"); } return; } switch (SelectionMode) { case SelectionMode.Single: foundItem = false; SelectedItem = null; for (int i = 0; i < Items.Count; i++) { if (ObjectToStringComparer.CheckIfStringMatchesObject(Text, Items[i], EditableTextStringComparision, SelectedItemStringFormat)) { SetCurrentValue(SelectedItemProperty, Items[i]); foundItem = true; break; } } if (!foundItem) { var result = TryAddObjectFromString(Text); if (!(result is null)) { SelectedItem = result; } } break; case SelectionMode.Multiple: case SelectionMode.Extended: var strings = Text.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries); SelectedItems.Clear(); for (int i = 0; i < strings.Length; i++) { foundItem = false; for (int j = 0; j < Items.Count; j++) { if (ObjectToStringComparer.CheckIfStringMatchesObject(strings[i], Items[j], EditableTextStringComparision, SelectedItemStringFormat)) { SelectedItems.Add(Items[j]); foundItem = true; } } if (!foundItem) { var result = TryAddObjectFromString(strings[i]); if (!(result is null)) { SelectedItems.Add(result); } } } break; default: throw new NotSupportedException("Unknown SelectionMode"); } // First we need to check if the string matches completely to the selected items. Therefore we need to display the items in the selected order first UpdateDisplaySelectedItems(OrderSelectedItemsBy.SelectedOrder); UpdateHasCustomText(null); // If the items should be ordered differntly than above we need to reoder them accordingly. if (OrderSelectedItemsBy != OrderSelectedItemsBy.SelectedOrder) { UpdateDisplaySelectedItems(); } var oldCaretPos = PART_EditableTextBox.CaretIndex; UpdateEditableText(); PART_EditableTextBox.CaretIndex = oldCaretPos; isUserdefinedTextInputPending = false; }