(Not so much) fun with Rhino Mocks

After creating some unit tests, I ran into a problem where the TestInitialization method was failing with either one of two errors.

The test initialization was performing something similar to:

[TestInitialize]
public void Initialize()
{
	myMock = MockRepository.GenerateMock<IMyInterface>();
	myMock.Stub(m => m.NextValue()).Return(6).Repeat.Once();
	myMock.Stub(m => m.NextValue()).Return(7).Repeat.Once();
	myMock.Stub(m => m.NextValue()).Return(9);
}

The first error I might get on the GenerateMock would be:
    System.NullReferenceException occurred
      Message=Object reference not set to an instance of an object.
      Source=mscorlib

Or, on one of the Stub calls I might get:
  System.InvalidOperationException occurred
  Message=Previous method ‘IMyInterface.MyMethod();’ requires a return value or an exception to throw.
  Source=Rhino.Mocks

This was a really frustrating problem and it took getting several people reviewing the problem with me before one individual spotted that two unit tests were running at once.  The problem ended up being that using the parallelTestCount=”2″ attribute in the testrunconfig file and the total problem that using this creates.  Trying to execute multiple tests at once would be great except for the fact that MSTest executes multiple parallel tests within the same test class.  Rhino Mocks is also NOT multi thread safe.

So the next time you see these types of errors, check to see if you’re using a parallelTestCount greater than 1.  It might save you a lot of time.

Happy Coding

Advertisements
Posted in Uncategorized | Leave a comment

Visual Studio 11 Beta–Holy Smokes Batman!!

Visual Studio 11 Beta and .Net 4.5 Beta became available on February 29th.  Some where expecting the normal incremental updates and improvements but the VS and .Net team appear set to knock this one totally out of the ball park!  Everyone knew that the UI was going to get a facelift for Win8 but that’s just the tip of the iceberg.  You can debug those Win8 apps locally or in the simulator.  You can upload directly to the Windows Store.  The tab bars have been simplified.  The JavaScript tooling support has been greatly improved.  And that’s just some of the stuff in the IDE.

The languages got some major upgrades as well, C++ in particular.  The list for C++ is far to long to go into.  The F# asynchronous abilities show their influence in the async syntax in C# and VB.

The .Net framework is now even faster and even more support for building parallel and concurrent applications.

I mean the list is huge!  Jason Zander did a great summary write up.  It’s well worth your time and will give you some of the highlights.

Happy Coding!!

Posted in Uncategorized | Leave a comment

Decompiling .Net

As many of you know, our beloved tool .Net Reflector was bought by RedGate and is no longer free.  The last free version is showing it’s age.  Enter Telerik to the rescue.  They are providing a FREE .Net Decompiler!  And this is not some dumbed down version.  It supports side-by-side assembly loading, .Net versions 1.1 through 4.0, Silverlight and Compact Framework, lambda expressions, generics, yield statements and auto generated properties.  Telerik apparently didn’t think that was enough.  They added the ability to create a full Visual Studio project from a decompiled assembly!  And if that wasn’t enough, they do three major updates a year!  Way to go Telerik!!!

Happy Coding!  And decompiling!

Posted in Uncategorized | Leave a comment

Building services in Visual Studio

When we’re building WCF services, we often want to debug our code.  Creating a harness to host our service is easy enough but I’ve seen people open two instances of Visual Studio to do this.  One to host and one to debug.  However, that’s not necessary.  The trick is to go to the Solution properties and set the “Multiple start up projects” and select which ones you wish to start.  In my example, I have created a simple WCF service project, a project to contain my service contract, a console app to host the service in for testing and finally a project to actually make the call to my service.  I can tell VS to start both my hosting program and my caller program by making the changes shown below.

 

Another way you could accomplish the same is to right click on the project you want to start, select debug and then select start new instance.

 

Happy Coding!!

Posted in Uncategorized | Leave a comment

Audio and Video in HTML5

Script Junkie delivers another good post about using the <audio/> tag in HTML5.  I really liked the table showing what codecs are supported in each browser.  Thanks Emily!

Happy Coding!

Posted in Uncategorized | Leave a comment

Interesting SQL ISNULL behavior

Found an interesting post about the SQL ISNULL function.  Apparently, it behaves differently if you’re using it to test strings.  For example:

DECLARE @a VARCHAR(100)
DECLARE @b VARCHAR(10)

SET @a=’This is much longer than 10 characters
SET @b=NULL

— This will display
—        This is mu

SELECT ISNULL(@b,@a)

— This will display
—        This is much longer than 10 characters

SELECT ISNULL(CONVERT(NVARCHAR(MAX), @b), @a)

Knowing this could keep you from pulling your hair out trying to investigate a bug when the truncated data gets down the pipeline.  Hope that helps someone out there.

Happy Coding!

Posted in Uncategorized | Leave a comment

Twitter

I haven’t been as active on my Blog but I have been active on Twitter.  I’ll work on the blog but in the meantime you can follow me at #JohnMarkHowell on Twitter!

Posted in Uncategorized | Leave a comment