CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Ranjan Sakalley

April 2006 - Posts

  • Writing unit tests for Windows Forms to test DataBinding

    Me and my pair were creating a form for the application, and basically testing out the data binding on the controls in the form.  Having  been bound to a domain object, the controls were tested as -

    1. Create a domain object, and set the properties to be bound with random values.

    2. Bind this/empty domain object to the windows form controls.

    3. Set/Change the values in the controls(like Text property of a TextBox, depending on this being a create or edit form.

    4. Assert the values of the current domain object state, with the values set/edited for equality.

    Our library, to perform step 3, consists of methods like the following -

      void SetControlValue(string name, string controlProperty, object value);

    which find out the control, then find out the mentioned property using reflection, and then set that property to the "value".

    As we started writing the first test to check up the state of the first control, we found a major issue. Even after the 4 steps, the asserts were failing. We spent around 2-3 hours trying to find out if the data binding was done correctly or not, or if the repository methods that were setting the control values using reflection were doing it correctly. Just as we got up to ask for help, one of our collegues mentioned that -- A control's DataBinding does not update the values in the object bound to it until the focus on the control changes.

    Why did I not notice it before writing my first test case? Having never written a unit test on any Windows Form, I was used to test my control bindings by checking the saved values etc. And that happened on the click of the "Save" button, which means the focus changed from the control to the button, and the data was saved to the object, and I could never notice this.

    Man its fun to write tests.

    Technorati :
    Technorati Profile
    Posted Apr 16 2006, 04:23 PM by rsakalley with 3 comment(s)
    Filed under:
  • Dialog Units

    Microsoft recommends a left margin of 7 Dialog Units (DLUs) (here) between controls in forms. So what is this DLU?
    The definition follows -
     A vertical dialog unit equals 1/8 the font height, and a horizontal dialog unit equals 1/4 the font width.

    The actual problem is,  when we talk about the system font above, how do we design a form, for a variety of possible font sizes and system resolutions, on the dev machine? Should we keep the measurements dynamic or is there a way to mandate the sizes in DLUs, rather than pixels?



    Posted Apr 11 2006, 05:35 AM by rsakalley with 4 comment(s)
    Filed under:
  • New job

    I joined ThoughtWorks as an application developer. It was a wonderful day, had a real nice time talking to some of the people there. Incidentally, Martin Fowler is in the India office these day, so maybe I will get to meet him sometime.

    BTW, moving from Outlook 2003 to Lotus Notes is a hell of an experience. Embarrassing at times.
    Posted Apr 10 2006, 03:13 PM by rsakalley with 1 comment(s)
    Filed under:
More Posts

Our Sponsors