[Hmmm, that sort of sounds like a PBS show or something. Hehehe.]

The folks over at Typemock passed a link along to me an interesting new project called Ivonna. It’s an ASP.NET testing framework (currently in beta) that runs on top of Typemock Isolator. It lets you run unit tests against web forms apps without a web server and access the controls and such right from your unit test.

Rather than explain it in long prose, let me just show you an example.

Say you have a web form that takes in two numbers and adds them together. Yes, your typical overused calculator application. The page probably looks like this:

<%@ Page Language="C#" Inherits="System.Web.UI.Page" %>
<html>
  <head runat="server">
    <title>Calculator</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <table>
        <tr>
          <td>First number:</td>
          <td><asp:TextBox ID="FirstNumber" runat="server"/></td>
        </tr>
        <tr>
          <td>Second number:</td>
          <td><asp:TextBox ID="SecondNumber" runat="server"/></td>
        </asp:TableRow>
        <tr>
          <td ColumnSpan="2">
            <asp:Button
             ID="SubmitButton"
             runat="server"
             Text="Calculate"
             OnClick="SubmitButton_Click" />
          </td>
        </tr>
        <tr>
          <td ColumnSpan="2" HorizontalAlign="Right">
            Total: <asp:Label ID="Sum" runat="server"/>
          </td>
        </tr>
      <table>
    </form>
  </body>
</html>
<script runat="server">
void SubmitButton_Click(object sender, EventArgs e)
{
  this.Sum.Text = (
    Double.Parse(this.FirstNumber.Text) +
    Double.Parse(this.SecondNumber.Text)
    ).ToString();
}
</script>

A couple of text boxes, a submit button, and a label to take in the result. You want to test that entering the numbers into the boxes and clicking the button actually puts the right text into the label. Check this out - it doesn’t get much simpler:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ivonna.Core;
using Ivonna.Framework;
using NUnit.Framework;
using TypeMock;

namespace UnitTests
{
  [TestFixture]
  [VerifyMocks]
  [RunOnWeb(@"C:\Path\To\WebApplication", @"/")]
  public class DefaultPageTestFixture : WebFixture
  {
    [Test]
    public void AddTwoNumbers()
    {
      TestSession session = this.InitSession();
      Page page = session.GetPage("Default.aspx");
      TextBox firstNumber = (TextBox)page.FindControl("FirstNumber");
      firstNumber.Text = "15";
      TextBox secondNumber = (TextBox)page.FindControl("SecondNumber");
      secondNumber.Text = "20";

      page = session.ProcessPostback("SubmitButton");
      Label sum = (Label)page.FindControl("Sum");
      Assert.AreEqual("35", sum.Text);
      this.EndSession();
    }
  }
}

That looks a lot like ASP.NET codebehind, doesn’t it? Familiar syntax? And you didn’t have to automate a browser, fire up a web server instance, or anything. Let’s walk through what’s going on in that test:

  1. There are test attributes to indicate this is an NUnit test fixture, I want to verify my Typemock mocks, and this is a web fixture. I specify the physical and virtual paths to the web application so the “navigation” works correctly.
  2. I derive my page test fixture from an Ivonna base test fixture.
  3. In the test…
    1. Initialize my web “session.”
    2. Do the initial page GET. Again, this isn’t actually doing web communication.
    3. Do a standard FindControl call on the page to get references to the textboxes I want to populate in the form.
    4. Set the values in the textboxes.
    5. Tell the page I want to do a postback and provide the ID of the button causing the postback. (I could also have gotten a reference to the button using FindControl and passed in the reference.)
    6. Use FindControl again to get the label that contains the result.
    7. Verify the result is what I expected.
    8. End the web “session.”

This is easier by far than trying to mock out HttpContext and such. Granted, it’s still pretty early and there’s a lot of room for improvement, and I don’t think it’ll entirely replace UI automation testing, but this could help out a lot in catching bugs early and running more UI-based tests without actually automating UI. Go check it out and see what you think.

GeekSpeak comments edit

Not quite a month ago, I bought an HP C7280 All-in-One scanner/fax/copier/printer over at the Buy More. I chose an all-in-one because my desk at home was starting to look like a dot-com-startup server room with all of the various pieces of equipment crowding around. The printer died and I sort of wanted to upgrade from my old HP ScanJet 5P (SCSI-based) scanner, so I figured now was the time.

Got it home and it printed beautifully. Like, even on “normal” quality, the print output really was gorgeous. Put a 5” x 7” photo on it and did a photo reprint at 4” x 6” and it not only perfectly scaled the photo down but did a borderless reprint on photo paper that looked as good as the original. Very impressed. To top it off, it was connected entirely via ethernet, so I didn’t have to have a print server or anything sharing the printer so the laptop could access.

It was about a week after I had it before I tried to do a scan - a CD album cover so I could attach the album art in iTunes.

Horrible. Like, really horrible.

Here’s a snippet of the Juno soundtrack cover. When you look at the cover with the naked eye, it looks nice, crisp, smooth. The edges of the orange stripes are sharp. The light gray shading is a solid color. The letters, while done with a hand-drawn style, have hard edges. Not at all how the scan comes out.

Bad scan of the Juno CD
cover.

Look at the scan - the edges of the orange stripes are actually fuzzy. There’s pixelation, almost like a halftone, in the gray shading. The edge of the “J” there looks like it was drawn with a dull colored pencil, which isn’t even close to the way the cover actually looks.

This is how every scan turned out. Colors that appear solid on paper become spotty. I had one weird instance where I scanned a large area of solid blue and the scan came out with Moire patterns in it. To add to the weirdness, this only really happened with printed materials. If I scanned a photo, it would come out decent.

I tried different resolutions, different color depths, different sharpness settings, different color/brightness settings, different OSes (Vista and XP), different scanning programs, different versions of the drivers… no luck.

I spent two weeks going back and forth with HP support on it and they claim (rightly so) that since copies looked good, there was nothing wrong with the hardware. We then spent literally hours uninstalling and reinstalling drivers, adding and removing HP bloatware… all to no avail. I’m about three days away from my 30 day return limit and I’m taking it back tonight.

I’ll be looking at Canon or Epson. Sorry, HP. I’m done.

gaming, playstation, media comments edit

As I’m thinking about getting a PS3 soon, I know I’m going to want to control the Blu-ray portion with my standard universal remote. Unfortunately, PS3 uses Bluetooth for its controllers and doesn’t support standard IR remotes.

IR2BT to the rescue. It converts IR signals to Bluetooth specifically for this purpose. I can get one of those instead of yet-another-proprietary-remote.

A clown and a large fez-shaped Shriner mascot parade around the
arena.Sunday we went to the Shrine Circus and saw Circus Gatti perform. It was very interesting and brought back some childhood memories as I watched some kids getting an elephant ride. (I didn’t think they did that anymore.)

There were some neat acts and I particularly enjoyed the “Extreme Metal Riders,” a group of guys who ride motorcycles around in a metal ball. I’d seen three motorcycles at the same time, but these guys do five and six at once.

The thing I thought was most interesting was truly how small the production was. They had several acts, but there were only like 20 people in the circus. You’d see one of the acrobats was also one of the guys riding motorcycles and he was also the juggler. The lady doing an act with a bunch of hula hoops is also the one who does an act on gymnastics rings and was a “cheerleader” for the motorcycle guys.

I had to show some respect for them, out there making their way doing things I know I can’t do, but at the same time, having just seen Cirque, it felt so small and… well, cheap. I feel bad saying that, because you could tell these folks were doing the best they could with what they had, and if you throw Cirque sort of money at something, of course it’s going to be bigger-better-faster-stronger. Ticket prices reflected that - Shrine Circus ticket: $9; Cirque ticket: $85. You do the math. It was a good time all the same and fun was had by all.

Plus, I had no idea the Shriners had a giant fez mascot. That thing is the bomb.