Skip to content

Commit 0453f34

Browse files
authored
get the Suggestion count of the AutoSuggestBox via RemoteExecute
1 parent dee5301 commit 0453f34

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

tests/MaterialDesignThemes.UITests/WPF/AutoSuggestBoxes/AutoSuggestTextBoxTests.cs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections;
1+
using System.Collections;
22
using System.ComponentModel;
33
using MaterialDesignThemes.UITests.Samples.AutoSuggestBoxes;
44
using MaterialDesignThemes.UITests.Samples.AutoSuggestTextBoxes;
@@ -178,12 +178,13 @@ public async Task AutoSuggestBox_KeysUpAndDown_WrapAround()
178178
await suggestBox.SendInput(new KeyboardInput("e"));
179179
await Task.Delay(delay);
180180

181-
//var itemSource = (await suggestBox.GetSuggestions()).Cast<object>().ToList();
182-
183-
//var suggestions = await suggestionListBox.GetProperty<IEnumerable>(nameof(ListBox.ItemsSource));
184-
//int itemCount = suggestions.Cast<object>().Count();
181+
static int? GetSuggestionCount(AutoSuggestBox autoSuggestBox)
182+
{
183+
int? count = autoSuggestBox.Suggestions?.OfType<object>().Count();
184+
return count;
185+
}
185186

186-
int itemCount = CountNonGenericEnumerable(await suggestBox.GetSuggestions());
187+
int itemCount = await suggestBox.RemoteExecute(GetSuggestionCount) ?? 0;
187188

188189
//Assert that initially the first item is selected
189190
int selectedIndex = await suggestionListBox.GetSelectedIndex();
@@ -198,27 +199,6 @@ public async Task AutoSuggestBox_KeysUpAndDown_WrapAround()
198199
//Assert that the first item is selected after pressing ArrowDown
199200
await suggestBox.SendInput(new KeyboardInput(Key.Down));
200201
Assert.Equal(0, await suggestionListBox.GetSelectedIndex());
201-
202-
203-
}
204-
205-
internal static int CountNonGenericEnumerable(IEnumerable? source)
206-
{
207-
ArgumentNullException.ThrowIfNull(source);
208-
209-
if (source is ICollection collection)
210-
{
211-
return collection.Count;
212-
}
213-
214-
int count = 0;
215-
IEnumerator e = source.GetEnumerator();
216-
while (e.MoveNext())
217-
{
218-
count++;
219-
}
220-
221-
return count;
222202
}
223203

224204
private static async Task AssertExists(IVisualElement<ListBox> suggestionListBox, string text, bool existsOrNotCheck = true)

0 commit comments

Comments
 (0)