Using Visual Studio 2008/Orcas testing framework with InCisif.net 1.4

6/7/2007 3:11:00 AM

Among the new features of Orcas Beta 1 (Now named VS 2008 based on what I heard from virtual tech ed), there is a testing framework to write unit tests.

As we did for NUnit, we decided to support the Visual Studio 2008 testing framework. Rather than offering an external assembly with source code, this time we ship directly as part of the InCisif.net assembly, the needed class to integrate InCisif.net with Visual Studio 2008 testing framework.

This source code will be available based on simple request.

Here are the first 2 tests I wrote using Visual Studio 2008 testing framework. 
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using InCisif.net.Library;

namespace InCisif.net.VisualStudio.TestTools {

[TestClass]
public class UnitTest1 : InCisif.net.VisualStudio.TestTools.TestClass {

    private TestContext testContextInstance;

    public TestContext TestContext {

        get{ return testContextInstance;  }
        set{ testContextInstance = value; }
    }
            
    [TestInitialize()]
    public void MyTestInitialize() {

        Page.Options.MouseMove         = true;
        Page.Options.DownLoadTimeOut   = 20;
        Page.WebBrowserControl.Top     = 0;
        base.Form.Left                 = 0;
        base.Form.Top                  = 0;
        base.Form.Height               = 550;
    }

    [TestCleanup()]
    public void MyTestCleanup() {

        base.CleanUp(); // Required after each test. Call the InCisif.net.VisualStudio.TestTools.TestClass CleanUp method.
    }

    private static string LastCustomerLastNameCreated;
    private static string LastCustomerIDCreated;

    private const string FIRSTNAME      = "Robert";
    private const string MIDDLENAME     = "A";
    private const string ADDRESS        = "1234 Main st";
    private const bool   TAXEXEMPT      = true;
    private const string COUNTRY        = "US";
    private const string CITY           = "Malden";
    private const string STATE          = "MA";
    private const string ZIP            = "02176";        
    private const string EMAIL          = "rdoe@mail.com";
    private const string CUSTOMERTYPE   = "TypeB";

    [TestMethod]
    public void AddCustomerDialogTest(){

        // Initialize and save in the test's properties the customer lastname used for this test
        LastCustomerLastNameCreated = string.Format("Doe{0}", System.Environment.TickCount);

        Page.URL = DemoURL;
        Page.WaitForPage("/default.asp");

        Page.Control("aDemo1", "menu").Click();
        Page.WaitForPage("demo1_frameset.asp");

        Page.Control("aAddCustomer", "demo1_menu").Click();
        Page.WaitForPage("demo1_addcustomerdialog.asp");

        Page.Control("_LastName", "demo1_main").Text        = LastCustomerLastNameCreated;
        Page.Control("_FirstName", "demo1_main").Text       = FIRSTNAME;
        Page.Control("_MiddleName", "demo1_main").Text      = MIDDLENAME;
        Page.Control("_Address", "demo1_main").Text         = ADDRESS;
        Page.Control("_TaxExempt", "demo1_main").Checked    = TAXEXEMPT;
        Page.Control("_Country", "demo1_main").Value        = COUNTRY;
        Page.Control("_City", "demo1_main").Text            = CITY;
        Page.Control("_Zip", "demo1_main").Text             = ZIP;
        Page.Control("_State", "demo1_main").Text           = STATE;
        Page.Control("_EMail", "demo1_main").Text           = EMAIL;

        // Special syntax for radio button
        Page.Control("_CustomerType", "demo1_main", CUSTOMERTYPE).Checked = true;

        Page.Control("butOK", "demo1_main").Click();
        Page.WaitForPage("MsgBox.asp");

        // Read the customer id from a hidden field and save in the test's properties the customer id just created
        LastCustomerIDCreated = Page.Control("CustomerID", "demo1_main").Value;

        Page.Control("OK", "demo1_main").Click();
        Page.WaitForPage("demo1_home.asp");
    }

    [TestMethod]
    public void LookCustomerDialogTest(){

        Page.URL = DemoURL;
        Page.WaitForPage("/default.asp");

        Page.Control("aDemo1","menu").Click();
        Page.WaitForPage("demo1_frameset.asp");

        Page.Control("aEditCustomer","demo1_menu").Click();
        InCisif.net.Library.HTMLForm NewPage1   = Page.WaitForPopUpWindow("demo1_lookupcustomerdialog.asp","NewPage1");
        NewPage1.Control("_ClientID").Text = LastCustomerIDCreated;

        NewPage1.Control("OKButton").Click();
        Page.WaitForPage(@"/demo1_editcustomerdialog.asp");

        Assert.AreEqual(Page.Control("_FirstName",      "demo1_main").Text,     FIRSTNAME);
        Assert.AreEqual(Page.Control("_LastName",       "demo1_main").Text,     LastCustomerLastNameCreated);
        Assert.AreEqual(Page.Control("_MiddleName",     "demo1_main").Text,     MIDDLENAME);
        Assert.AreEqual(Page.Control("_Address",        "demo1_main").Text,     ADDRESS);
        Assert.AreEqual(Page.Control("_City",           "demo1_main").Text,     CITY);
        Assert.AreEqual(Page.Control("_Zip",            "demo1_main").Text,     ZIP);
        Assert.AreEqual(Page.Control("_State",          "demo1_main").Text,     STATE);
        Assert.AreEqual(Page.Control("_TaxExempt",      "demo1_main").Checked,  TAXEXEMPT);
        Assert.AreEqual(Page.Control("_Country",        "demo1_main").Value,    COUNTRY);
        Assert.AreEqual(Page.Control("_EMail",          "demo1_main").Text,     EMAIL);

        Assert.AreEqual(Page.Control("_CustomerType",   "demo1_main", CUSTOMERTYPE).Checked, true);

        Page.Control("ButOK","demo1_main").Click();
        Page.WaitForPage(@"/demo1_home.asp");
    }
    public string DemoURLPath {

        get { return string.Format("http://www.incisif.net/demo{0}/", InCisif.net.Library.Engine.Version); }
    }
    public string DemoURL{

        get { return DemoURLPath + "default.asp"; }
    }
    public string DemoPostURL{

        get { return DemoURLPath + "PostOutPut.asp"; }
    }
    #region Additional test attributes

    ////You can use the following additional attributes as you write your tests:

    ////Use ClassInitialize to run code before running the first test in the class
    //[ClassInitialize()]
    //public static void MyClassInitialize(TestContext testContext) { }

    ////Use ClassCleanup to run code after all tests in a class have run
    //[ClassCleanup()]
    //public static void MyClassCleanup() { }
    #endregion
}
}