Unit testing against Windows Azure Development Storage

1 Comment »

When developing an application targeted for Windows Azure, your application will be executing in an environment to which you have somewhat limited access, making debugging hard. Thus, you will probably want to test your application as much as possible before deploying it. Enter unit testing.

To be able to execute unit tests  against the Azure storage (well, maybe such tests are more like integration tests), you need to have the Azure Development Storage running when the tests are executed. To achieve this, you will need to do two things:

1. Make sure the development storage is available
2. Make sure the development storage is running before testing begins

The first task is taken care of by installing the Windows Azure SDK. If you are developing Windows Azure applications, you will probably already have this installed on your computer. However, if you plan to run your tests on a dedicated build server, you may need to install the SDK on that machine.

For the second task, you need to start the Development Storage prior to executing tests. To start the Development Storage you can use the CSRun utility from the Azure SDK. If you have installed the SDK to the default position, you will find csrun.exe in C:\Program Files\Windows Azure SDK\v1.0\bin:

If you want to integrate this task with your build scripts, you can of course create a NAnt target for it:

<property name="azure.sdk.csrun.exe" value="C:\Program Files\Windows Azure SDK\v1.0\bin\csrun.exe"/>

<target name="azure.devstorage.start" description="Starts the Azure Development Storage">
<exec program="\${azure.sdk.csrun.exe}"
commandline="/devstore:start">
</exec>
<sleep seconds="5"/><!-- Sleep 5 seconds, waiting for the development storage to start -->
</target>

As you can see, I have added a delay in order to allow the storage to fully start before subsequent tasks are executed.

Now just call this target before executing your unit tests. You may also want to shut down the Development Storage upon completion of your tests. Use csrun /devstore:shutdown to do this

Note that if your project is the first project to use Development Storage on the build server, you will want to initialize the database underlying Development Storage before running tests. Initializing the Development Storage will create a database called something like DevelopmentStorageDb20090919 in the local SQL Server (Express) instance.

You just need to do this once. However, if you feel like it, you can force DSInit to recreate the database as part of your test procedure by issuing the command dsinit.exe /forceCreate. DSInit requires administrator privileges, though.

Authoring MathML

I am not entirely satisfied with the result that WP LaTex produces. Obviously, the white background on every little piece of math is a problem. Moreover, it only supports the simplest of layouts – at least I can’t get environments like displaymath, align etc. to work properly. Therefore, I decided to look into MathML. MathML is a W3 Recommendation specification for describing mathematics intended for machine to machine communication. That means in particular that MathML may be used by webservers to send mathematical content to client browsers.

Thus, MathML should be able to achieve the same goal as the WP LaTeX plug-in. However, this alternative comes at a price, since it relies on the browser being able to render MathML. Alas, browser support for MathML is somewhat limited: Firefox supports MathML, but IE needs a plug-in. You would think, Google caring so much about spreading good karma, that Google’s Chrome browser would support MathML, but it doesn’t. Not in any shape or form. Since I like Chrome very much for its speed and ease of use, I find this very disappointing.

However, most of the math I am authoring is just for my personal reference, so I don’t have to adhere to browser support restrictions too much and I decided to move forward and try to find an editor capable of producing MathML (besides Notepad, obviously).

The W3 organisation has a list of MathML editors, of which I have tried a few.

FireMath

This is a Firefox plug-in (much like Firebug etc.) and may be the best free option at the moment. It has a nice preview region, a reasonable layout and the generated XML is easily accesible. I will evaluate this further, before I pass my judgement.

http://www.firemath.info/

MathML Editor for Flash

The MathML Editor for Flash is, as the name suggests, a Flash application for editing and rendering MathML. You can try MathML Editor for Flash out here. It is pretty rudimentary and, unless I am greatly deceived, it is nigh impossible to typeset anything but the most basic expressions. The process of building an expression is very hierarchical, and you have to somewhat plan this hierarchy in advance. If you have got lots of indexes, superscripts, accents etc., you are going to have to start over again and again. Trying to typeset

drove me crazy with frustration. Also, I gave up on this application when it took me more than a few minutes to find the symbol $\mathbb{C}$ (I never found it).

A note on distributive and modular lattices

I’ve been working a little with an old friend, modal logic, this weekend. This digressed into a study of lattices and Boolean algebras, so I thought I would write up some of my observations for archival. Also, I just like to say “lattice”.

If you know anything about lattices, you will probably find this stuff trivial. If you don’t know anything about lattices, a free and much better introduction can be found in A Course in Universal Algebra.

Definition: A distributive lattice is a lattice which satisfies the distributive laws:

$D1: x \land (y \lor z) \simeq (x \land y) \lor (x \land z)$
$D2: x \lor (y \land z) \simeq (x \lor y) \land (x \lor z)$

Actually, it can be shown that a lattice satisfies D1 iff it satisfies D2.

Definition: A lattice L is said to be modular if the modular law holds:

$M : x \leq y \Rightarrow x \lor (y \land z) \simeq y \land (x \lor z)$

Lemma: The modular law for lattices is equivalent to the identity

$(x \land y) \lor (y \land z) \simeq y \land ((x \land y) \lor z)$

Proof
Assume that the modular law holds and consider the expression $y \land ((x \land y) \lor z)$. Since $x \land y \leq y$ we can apply the modular law to infer that $y \land ((x \land y) \lor z) \simeq (x \land y) \lor (y \land z)$.

Now, assume that the identity holds and that $x \leq y$ for some $x, y, z \in L$. Then $x = x \land y$ so

$x \lor (y \land z) \simeq$
$(x \land y) \lor (y \land z) \stackrel{\dagger}{\simeq}$
$y \land ((x \land y) \lor z) \simeq$
$y \land (x \lor z)$,

where the identity was used in $\dagger$. Thus, the modular law holds.$\Box$

Theorem: Every distributive lattice is modular.

Proof
Assume that $x \leq y$ for some $x, y, z \in L$ where $L$ is a distributive lattice. Then $y = x \lor y$ so
$x \lor (y \land z) \simeq (x \lor y) \land (x \lor z) \simeq y \land (x \lor z)$

where we have made use of D2. The desired result now follows from the lemma.