Transactions and Unit Testing with NUnit

Wednesday, 21 June 2006

Roy Osherove has written a useful library that adds support for wrapping your unit tests inside a transaction (using MSDTC/COM+) which means that you can test your data-layer code and not worry about messing up your database.

The only problem is I can’t get it working for me:-(

  1. Microsoft increased the security around using COM+ in Windows XP Service Pack 2 and Windows Server 2003 Service Pack 1
  2. The database I’m testing against is on a remote server (running 2003 SP1)

So even after reading this KB article, I still can’t get it to work. The unit test just hangs, and I think it’s because MSDTC is having problems of some kind.

Australian Story :: Dzung's Anatomy

Tuesday, 13 June 2006

My wife and her family are friends with the Davis family, and Carl (their son) is married to Thau (Dzung’s daughter).

View Trace.axd

Sunday, 11 June 2006

Roger has written a Firefox Extension that ASP.NET developers will find very useful.

As I always say, “Anything that saves me extra keystrokes is a good thing!”

PageMethod Testamonial

Monday, 5 June 2006

Fabrice has published my testamonial about how we are using the PageMethods component with our development of an Online Assessment Tool.

ObjectDataSource and Sorting (Part 2)

Thursday, 1 June 2006

Sergio asked if I could post how I solved my problem with sorting and the ObjectDataSource control.

Here’s what I did:

First of all, add a parameter to the method that is being called by the ObjectDataSource control that will be used to sort the data.

    <DataObjectMethod(DataObjectMethodType.Select)> \_

    Public Shared Function GetTests(ByVal sortExpression As String) As TestInfoCollection

        If sortExpression Is Nothing Then

            Throw New ArgumentNullException("sortExpression")

        End If

It’s up to you what you do with the value that is passed in. The value comes in looking like the sort bit of SQL. In my case to get things up and running I’m loading my data into a DataTable, then use a DataView to do the sorting for me - not the most efficient way but it works for now. Later on, I might pass the sort criteria down to SQL Server and let it do the sorting for me, but that will require messing with the stored procedures!

It seems like an oversight that there isn’t a special attribute to prepend the sortExpression parameter so that the ObjectDataSource recognises it as special - unfortunately it just thinks it’s a regular parameter and will add it to the SelectParameters part in the aspx file. You just need to remove it from there and instead make sure the SortParameterName attribute is set instead.

<asp:ObjectDataSource id="odsTests"
runat="server"
TypeName="UniSA.UniSAnet.SmartMark.DataAccess.TestComponent"
SelectMethod="GetTestsForCourse"
SortParameterName="sortExpression">
<SelectParameters>
<asp:QueryStringParameter ConvertEmptyStringToNull="False" Name="courseId" QueryStringField="CourseId" Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>