This project is read-only.

Probable bug: Listbox.Items.Count does not count duplicates objects

Aug 22, 2011 at 4:09 PM
Edited Aug 22, 2011 at 6:54 PM

I am attempting to count the number of items in a Listbox to verify that objects are properly added when a button is pressed. I've discovered when playing around with the code that it does not count duplicate objects using the White.Core.UIItems.ListBoxItems.ListBox.Items.Count method. Here is an example below:

In xaml I have a System.Windows.Controls.Listbox object. When I hit a click a button I add 3 objects to the listbox:


I then in a White Unit test run the following: 
Assert.AreEqual(3, listbox.Items.Count);
I get a successful result, as it detects 3 items. The unit test then clicks the button again, and it adds runs the code again adding the items. On the screen I can see 6 items in the listbox as follows:


In debug mode, viewing the listbox it contains 6 objects, the objects I'm seeing on the screen. I then do another assert:
Assert.AreEqual(6, listbox.Items.Count);
This time the unit test fails with the number of items expected is 6, but actual is 3.

In running the same test with the 2nd button press changed to different code as follows:


Running Assert.AreEqual(6, listbox.Items.Count); Finds 5 values now instead of 3. Two of the objects are now different, while the myString object is still the same. I've also done this with combinations of other objects.


Has anyone else ran into this issue? I've reported it now as an issue:

Aug 30, 2011 at 4:30 PM

How does your user cope with this problem? Seems like something which shouldn't be done at all in the application.

Aug 31, 2011 at 2:43 PM

The code I'm using isn't in production, and no user is actually using it. I'm currently working on creating a prototype to see how the White UI Framework works and learn how to use it properly with WPF controls. My example is just a dummy case that in adding duplicate items to the listbox, I noticed results different from what I'd expect. In a real application, I would expect the assert to count duplicate items in the listbox.