Tutorials


Note to self, there are some good tutorials and 101s out there which should help a lot in a few areas. Make time to get through

I'm looking for a good one on Ruby and on Javascript as well. Anyone got anything good? The new Wrox First wiki on Javascript frameworks looks good, but it does cost.

author: Dan Maharry | posted @ Friday, July 25, 2008 9:17 AM | Feedback (1)

Assert.AreValueEqual


One of the interesting aspects of backfilling documentation is uncovering methods few seem to have discovered. Case in point, the Assert.AreValueEqual method in MbUnit v2. Rather than the straightforward AreEqual methods to compare the values of a property in an object or the AreSame methods to compare whether two objects are actually the identical object or of the same type, AreValueEqual verifies that two objects, expected and actual,

  • both have a property described a PropertyInfo object,
  • that the property is not null,
  • and that the value of the property in both objects is equal.

It's a bit of a black box tester then and works across class hierarchies.

AreValueEqual takes three parameters and an optional fourth.

  • The PropertyInfo object indicating the property to be tested
  • The object containing the expected value of the property
  • The object containing the actual value of the property
  • The index of the value to compare in the property if it is an indexed property

Let's take a few examples to demonstrate its various pass and fail scenarios. First, some boilerplate. You'll need to include System.Reflection for the PropertyInfo class and MbUnit.Framework for the Assert class.

using System;
using System.Reflection;
using MbUnit.Framework;

namespace MbUnitAssertDocs
{
   [TestFixture]
   public class AreValueEqualTests
   {

 

The first test passes as it compares the Length property of two string arrays both containing four strings. Only the Lenght property is being tested here, so whether the strings are equal is irrelevant

      //This test passes
      [Test]
      public void AreValueEqual_SameValues()
      {
         // Create two arrays
         String[] a = new String[4] { "this", "is", "a", "test" };
         String[] b = new String[4] { "this", "is", "a", "camel" };
      
         // Generate the PropertyInfo object for an array's length
         PropertyInfo pi = typeof(Array).GetProperty("Length");
         Assert.AreValueEqual(pi, a, b);
      }

 

The next test also passes and demonstrates using the optional fourth parameter to test the value of an indexed property. In this case, we're treating a String object as an array of Char and testing the fourth character.

      //This test passes
      [Test]
      public void AreValueEqual_SameValuesUsingIndices()
      {
         // Create two strings
         String a = "this is a test";
         String b = "this is a camel";

         // Generate the PropertyInfo object for the string as a Char array 
         PropertyInfo pi = typeof(String).GetProperty("Chars");

         // Test the fourth letter
         Assert.AreValueEqual(pi, a, b, new Object[] {4});
      }

 

If one of the objects being tested is null, the test fails with an AssertionException.

      // This test fails with an AssertionException
      [Test]
      public void AreValueEqual_OneValueIsNull()
      {
         // Create two arrays
         String[] a = new String[4] { "this", "is", "a", "test" };
      
         // Generate the PropertyInfo object for an array's length
         PropertyInfo pi = typeof(Array).GetProperty("Length");
      
         Assert.AreValueEqual(pi, a, null);
      }

 

If one of the objects does not have the property specified by the PropertyInfo object, the test also fails with an AssertionException. This next test fails because the String reference class has a Chars property while the string value type does not. (One capitalised letter makes all the difference)

      //This test fails with an AssertionException
      [Test]
      public void AreValueEqual_PropertyNotPresentInOneObject()
      {
         // Create two arrays
         String[] a = new String[4] { "this", "is", "a", "test" };
         string[] b = new string[4] { "this", "is", "a", "camel" };
      
         // Generate the PropertyInfo object for an array's length
         PropertyInfo pi = typeof(Array).GetProperty("Chars");
      
         Assert.AreValueEqual(pi, a, b, new Object[] {4});
      }

 

Finally, if the value of the property shared by the two objects does not have the same value, the test fails with a NotEqualAssertionException.

      //This test fails with a NotEqualAssertionException
      [Test]
      public void AreValueEqual_DifferentValues()
      {
         // Create two strings
         String a = "this is a test";
         String b = "this is a camel";
      
         // Generate the PropertyInfo object for the string as a Char array 
         PropertyInfo pi = typeof(String).GetProperty("Chars");
      
         // Test the tenth letter
         Assert.AreValueEqual(pi, a, b, new Object[] { 10 });
      }
   }
}

 

Hopefully, this gives you a few ideas on how you might use Assert.AreValueEqual. MbUnit itself uses it in our DataAssert class, the source for which you can see here. There's also a discussion on the MbUnit-User forum discussing this method and whether or not it should make it into MbUnit v3. If you'd like to see it stay, or would like to propose an alternative, reply to the thread.

Technorati Tags: ,

author: Dan Maharry | posted @ Monday, July 21, 2008 10:13 PM | Feedback (1)

Learning that WAPs on IIS are for Admins Only The Hard Way


(Or rather "How a fixed bug and a rubbish COMException error dialog ended up making me take four months to learn that Web Application Projects running on IIS rather than Cassini can only be edited in VS when running with Administrative privileges" but that seems slightly long for a blog title post)

I've been happily running VS2008 as a standard user since it came out. And with TestDriven.NET and VisualSVN, I'm motoring along quite well. Yesterday, I decided to upgrade VisualSVN to the latest version v1.5.1. And then bang!! I loaded up my current work and got this dialog.

CropperCapture[1]

And my Web Application Projects have failed to load in VS2008. After mild panic has finished setting in, I try regressing to my previous version v1.3.2 and the project loads fine. Which is mildly inconvenient as v1.3.2 doesn't work with TortoiseSVN 1.5 which is something I also updated on my machine.

Looking on the intarwub, it's mildly amusing to see that Google's best match to this situation as I search for it is a forum thread that I started on VisualSVN's forums when I got the same error trying out v1.4. However, one response in there since I last read it suggests removing the <FlavorProperties> element from the wap's .csproj file. Which I do and it works. But having loaded the project back in again and reset it back up to run on IIS, the dialog appears again.

A bit more googling for Web Application Projects and COMExceptions yields this page from Martin Kulov bemoaning the same useless dialog but with the following golden nugget of information.

In order to load the Web Application Project ... if you are running Vista, you should run in elevated privileges as well.

Which is a bit of a shock as I've been happily running Vista and developing this project as a standard user for four months. Furthermore, it turns out that that useless dialog is a VS2008 bug that will be fixed in Service Pack 1.

So apologies to VisualSVN for doubting you. I'm never a fan of running Visual Studio as an admin, but I guess I have no choice. But whatever bug was present in v1.3.2 so I could develop WAPs on IIS as a standard user, maybe you could put it back?  :)

author: Dan Maharry | posted @ Thursday, July 10, 2008 9:50 AM | Feedback (0)

The use of LINQ - in summary


As with all programming tasks, there are many different ways to create a program that solves the problem. The trick is, as ever, to write the program, get it working, and then optimize it. It may be that after you have your program up and running (and profiled), you'll discover that there are some places that you've used LINQ which would be better off using stored procedures running within your database or vice versa or using LINQ to access stored procedures. The trouble is that whether LINQ is the best approach for your apps is something that you'll find out only after you've worked with it for a while. What is sure though is that the advantages of using LINQ are so tremendous that it cries out for a code now, optimize later approach.

author: Dan Maharry | posted @ Sunday, June 15, 2008 7:59 PM | Feedback (0)

Change of Tumblr Address


Just a quick note for all those who have subscribed to my old tumblr feed at http://xibalba.tumblr.com. I no longer use this address and it would appear that someone has already started using it instead of me. Please unsubscribe from there and if you're so inclined subscribe to http://tumblr.hmobius.com/rss. Thanks, Dan

author: Dan Maharry | posted @ Monday, June 09, 2008 9:20 AM | Feedback (0)

EnableStateHash is no more. Long live EnableSecureHistoryState


Just a quick note on the new Browser History feature in .NET 3.5 SP1. I had some time to experiment with beta 1. Because of its long gestation period as part of the ASP Futures package, it has been written about a lot. However, as is the curse of beta software, there is a 'breaking change' between the b1 release and the futures package version that many blog articles write about.

The feature is still enabled using the EnableHistory attribute on your page's ScriptManager object.

<asp:ScriptManager runat="server" id="sm1" EnableHistory="true" /> 

However, the EnableStateHash attribute which you can use to have ASP.NET encrypt or not encrypt the page state in its querystring has been renamed. It is now called EnableSecureHistoryState.

author: Dan Maharry | posted @ Friday, June 06, 2008 10:20 PM | Feedback (0)

Removing The Search Box From IE7


Now as far as I'm concerned, the search box in the menu bar of IE7 is probably the feature I most use - Alt+D, Tab gets me there in half a second - but it takes up some screen realty I'd rather use for other purposes when it comes to taking screenshots for the book, so here's how to remove it and then add it back again should you ever need to do so.

  1. Open RegEdit
  2. Find HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet Explorer\Infodelivery\Restrictions or create it if it isn't there already.
  3. Add a DWORD key called NoSearchBox.
  4. To turn off the search box, set this value to 1
  5. To turn it back on, set this value to 0

That is all.

author: Dan Maharry | posted @ Friday, June 06, 2008 10:10 PM | Feedback (0)

Now Tumbling


Like pretty much anything I get my hands on, I've tweaked, deleted, reinstated, redesigned in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally ignored for three months my tumblr account trying to figure out what to do with it. In the end, it turns out to be just a really good place to stick notes, photos, youtube clips, quick  reviews and quotes just like the tumblr blurb says.

Have a look and see if there's anything you like as well.

author: Dan Maharry | posted @ Friday, June 06, 2008 12:25 PM | Feedback (0)

Gin and The Cognitive Surplus


Update (29/4): If you can't see the video, you can also find it here.

via Warren Ellis.

author: Dan Maharry | posted @ Monday, April 28, 2008 4:27 PM | Feedback (1)

Chinese Book Publisher Steals Illustrations and Plagiarizes


As a writer, this pisses me off. Someone scraped the contents of Darren Di Lieto’s website and published it into a 350-page book being sold online for $100. Publishers have faked their details, resellers refuse to pull the book.

Please spread the word about this and help alert people that they should not buy this book.

author: Dan Maharry | posted @ Monday, April 21, 2008 10:29 AM | Feedback (0)