Getting started

In order to use Ivonna, you have to install the latest version of TypeMock Isolator.

Setting up the Web site.

  1. Create a Web site and add a file Default.aspx if it's not already present.
  2. Add a label to the page and change its ID to "HelloLabel".
  3. Add a textbox to the page and change its ID to "NameTextbox".
  4. Add a button to the page and change its ID to "HelloButton".

Setting up the test project

  1. Add a Class Library project to the solution.
  2. Add references to Ivonna, TypeMock, and your testing framework (e.g., MbUnit or NUnit) to your project.
  3. Change the project's output path to the Web site's bin directory.
    (Note: if you want to use the Microsoft Test Framework, read this).
  4. Add a class to your project. Decorate it with the TestFixtureAttribute and the Ivonna.Framework.RunOnWebAttribute.
  5. Add a method to your class, and decorate it with the TestAttribute.
  6. Each test method should begin with obtaining a reference to a TestSession instance.
  7. Execute a GET request usingt this instance and obtain a reference to the page using the GetPage method.
  8. Find the textbox and set its text to "John".
  9. Execute a postback request using the session's ExecutePostback method and obtain a reference to the page.
  10. Find the HelloLabel label and assert that it's text is equal to "Hello John".

The full code should look like this:

VB.Net:

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports MbUnit.Framework

Imports Ivonna.Framework

 

<TestFixture(), RunOnWeb()> _

Public Class WebTester

 

    <Test()> Public Sub HelloTest()

        Dim session As New TestSession()

        Dim testPage As Page = session.GetPage("Default.aspx") 'Get the page

        Dim NameTextbox As TextBox = testPage.FindControl("NameTextbox") 'Find the textbox

        NameTextbox.Text = "John" 'Enter some data

 

        testPage = session.ProcessPostback("HelloButton") ' That's how we process postbacks

        Dim label As Label = testPage.FindControl("HelloLabel")    'Find the label

        Assert.AreEqual("Hello John", label.Text)

    End Sub

End Class

C#:

using System.Web.UI;

using System.Web.UI.WebControls;

using MbUnit.Framework;

using Ivonna.Framework;

 

    [TestFixture, RunOnWeb]

    public class WebTester

    {

        [Test] public void HelloTest() {

        TestSession session = new TestSession();

        Page testPage = session.GetPage("Default.aspx"); //We first GET our page

        TextBox NameTextbox = (TextBox) testPage.FindControl("NameTextbox"); //Find the textbox

        NameTextbox.Text = "John"//user enters some data

 

        testPage = session.ProcessPostback("HelloButton"); // That's how we process postbacks

        Label label = (Label) testPage.FindControl("HelloLabel");

        Assert.AreEqual("Hello John", label.Text);

        }

    }