Sina Weibo client collar 7 Development Notes (1) Establishment of TDD Environment

Source: Internet
Author: User

Since mvvm and TDD are used, the two tools are essential:

1. mvvm light Toolkit

2. Silverlight unit testing framework

The corresponding WP7 version is available. Add the DLL to the project.

 

The following are some important points:

1. Create a new project weibo7
2. Add a test project weibo7.test

1) Add Microsoft. Silverlight. Testing & Microsoft. visualstudio. qualitytools. unittesting. Silverlight to the project reference.
2) Modify mainpage () as follows:

Code

    //  Constructor  
Public Mainpage ()
{
Initializecomponent ();

// Set up Unit Testing
Content = Unittestsystem. createtestpage ();
Imobiletestpage imtp = Content As Imobiletestpage;

If (Imtp ! = Null )
{
Backkeypress + = (X, Xe) => Xe. Cancel = Imtp. navigateback ();
}
}

3) create a new class mainviewmodeltests

Code

  Using System;
Using System. net;
Using Microsoft. Silverlight. testing;
Using Microsoft. visualstudio. testtools. unittesting;
Using Weibo7.viewmodels;


Namespace Weibo7.test
{
[Testclass]
Public Class Mainviewmodeltests: silverlighttest
{

}
}

4) Add a new test method.

Code

  [Testmethod]
Public Void Ishomerefreshing_setvalue_raisespropertychanged ()
{
VaR mainviewmodel = New Mainviewmodel ();

Bool Propchanged = False ;
Mainviewmodel. propertychanged + =
(S, E) =>
{
If (E. propertyname = " Ishomerefreshing " )
{
Propchanged = True ;
}
};

Mainviewmodel. ishomerefreshing = ! Mainviewmodel. ishomerefreshing;
Assert. istrue (propchanged );
}

3. Add a viewmodelbase class from which all viewmodels must inherit

Code

  Using  System. componentmodel;

Namespace Weibo7.viewmodels
{
Public Class Viewmodelbase
{
Protected Void Onpolicypropertychanged ( String P)
{
If (Propertychanged ! = Null )
{
Propertychanged ( This , New Propertychangedeventargs (p ));
}
}
Public Event Propertychangedeventhandler propertychanged;

}
}

4. Add the mainviewmodel class in weibo7 and add an ishomerefreshing attribute. This is used to bind the progressbar. Currently, the UI has not been created, but it can be tested!

Code

    Private     Bool  _ Ishomerefreshing  =     False  ;
/// <Summary>
/// Indicates whether there is an indeterminate operation in progress
/// </Summary>
Public Bool Ishomerefreshing
{
Get { Return _ Ishomerefreshing ;}
Set
{
If (Value ! = _ Ishomerefreshing)
{
_ Ishomerefreshing = Value;
Onpolicypropertychanged ( " Ishomerefreshing " );
}
}
}

If there is no problem, run the test project and you will see the following results:

More detailed results:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.