MVC is a software pattern whereby M is the model, i.e. where your data is
stored.  V is the view and C is for controller.  Essentially you make your
views as stupid as possible, and put all the smarts into a controller.

Using the simple example of a login form, you have

        public interface ILoginView


        {
                string Username { get; set; }
                string Password { get; set; }



                event EventHandler<EventArgs> OkClicked;
        }


Your controller looks something like this:

public class LoginController
        {
                private readonly ILoginView _loginView;



                public LoginController(ILoginView loginView)
                {
                        _loginView = loginView;
                        loginView.OkClicked += new 
EventHandler<EventArgs>(loginView_OkClicked);


                }

                void loginView_OkClicked(object sender, EventArgs e)
                {
                        // Do your login checking here, you can access the


                        // details via _loginView.Username and 
_loginView.Password.
                }
        }

Since the smarts of your application are now in the controller, you want to
create some unit tests that create a controller instance, but instead of
passing in a reference to a winforms Form, you pass in another object that
implements ILoginView.

public class FakeLoginView: ILoginView


        {
                public string Username { get; set;}
                public string Password { get; set;}



                public event EventHandler<EventArgs> OkClicked;

                public void RaiseOkClicked()


                {
                        OkClicked(this, new EventArgs());
                }
        }


In your unit test, you can set the view values (Username and Password)
directly, to simulate a user typing in these values.  You can call
RaiseOkClicked to simulate a user clicking the ok button.  (There are
shortcuts to creating fake objects, look up Stub and Mocking frameworks).

Once you're satisfied that the controller is doing what it is supposed to
do, it is simply a case of creating a winforms Form that implements
ILoginView.

Its a big topic, some further reading:
http://en.wikipedia.org/wiki/Model–view–controller<http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller>
http://en.wikipedia.org/wiki/Test-driven_development
http://en.wikipedia.org/wiki/Mock_object

If you want to go down this path, it will force you to change the way that
you structure your application (in a good way, in my opinion).

Cheers
Alan

On 2 July 2010 15:48, Anthony <asale...@tpg.com.au> wrote:

>  The projects are all underdevelopment so i have the source code....have
> an examples or reference..this is all new to me!  What is a model view
> controller?..sorry for my ignorance.
>
>
>
> *From:* ozdotnet-boun...@ozdotnet.com [mailto:
> ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Alan Heywood
> *Sent:* Friday, 2 July 2010 3:46 PM
> *To:* ozDotNet
> *Subject:* Re: UI Automation Testing Software for Win Forms
>
>
>
> This might not be relevant in your case, it depends on whether you are
> testing existing software or developing new software.  I have had good
> results with a Model View Controller approach combined with Test Driven
> Development.  Define an interface for all UI interations, test the
> interaction with Stub views.  By the time you get to implementing your
> actual winforms views they just work.
>
>
>
> The thought of having third party software clicking all over a winforms app
> gives me the creeps.
>
>
>
> Cheers
>
> Alan
>
> On 2 July 2010 15:31, Anthony <asale...@tpg.com.au> wrote:
>
> Anyone recommend or have experience with UI Interface testing software.
> Evaluating TestComplete  7 but anyone have experience with Microsoft
> TestRun..is it a separate product or part of visual studio?
>
>
>
> Thanks in Advance
>
>
>
> Is your website being 
> IntelliXperienced?<http://www.intellixperience.com/signup.aspx>
> regards
> Anthony (*12QWERNB*)
>
> Is your website being IntelliXperienced?
>
>
>
>
>
>
>

Reply via email to