c# - Testing Custom Control derived from ComboBox -


I have created a control from the combo box, and want to test the unit's behavior.

However, it seems to behave differently in my unit testing how it behaves in the actual application.

In the actual application, Combobox.DataSource property and. In other words, when I change Combobox.DataSource.The .ms list updates to automatically show an item for each element of the datasource and automatically updates the list.

In my testing, I create a combo box, assign a data source for it, but Do not get updated on all, remaining in 0 items. Thus, when I try to update. To select the first object, to select the IMEX selected from 0 in the test, I get an ArgumentOutRangeException.

This is because I do not have any applications. An event loop or is it a bit of a red herring?

Edit: More details on the first test:

  [Setup] Public zero setup () {MECB = new advanced combobox (); Mecb formatting enabled = true; MECB.Location = New system. Drawing Point (45, 4); MECB.Name = "cboFind"; MECB Size = new system Drawing. Size (121, 21); MECB TabIndex = 3; MECB.AddObserver (this); MTestItems = new list & lt; TestItem & gt; (); MTestItems.Add (New TestItem () {value = "Billy"}); MTestItems.Add (New TestItem () {value = "Bob"}); MTestItems.Add (New TestItem () {value = "blues"}); MECB.DataSource = mTestItems; MECB.Reset (); MObservedValue = Faucet; } [Test] Public Zero Test01_UpdateObserver () {mECB.SelectedIndex = 0; Decide. Erequal ("Billy", MOSBeed Value Value); }  

The test in the first line fails when the selected index is trying to set to 0. On debugging, it appears that when DataSource changes, then The archive collection is not updated to reflect this, however, when the original app is debug, the amazes collection is always updated when the data changes.

Of course I do not really need to provide a combo box in the test, I have no one set to present the drawing surfaces! It is possible that only one answer is needed "How do I make a combo box update, as it is drawn in a unit test scenario, where I do not really need to attract the box?"

Since you are just calling the constructor, not all Cambodia's functionality will work. For example, the item will be filled on a form, when a combo box is prepared on the screen. This does not happen when constructing it in a unit test.

Why do you want to write a unit test on that combo box?

Can not you separate the logic that is now in the Custom Control? For example, insert it into the controller, and test it?

Why do not you test the datasource property instead of the item collection?


Comments