Kris Krause .NET Meister

"If it is fast and ugly, they will use it and curse you; if it is slow, they will not use it."
- David Cheriton, The Art of Computer Systems Performance Analysis

Monday, June 29, 2009

Concrete Example - Mocking .NET Objects w/NUnit

Geoff Lane does a very good job of explaining .NET Mock objects.

People were requesting a "concrete" example so I implemented an example C# console application (although this can easily be made into an ASP.NET web application).

Geoff hints to using Spring .NET to wire things up, but that might be too confusing for some people. And maybe a little over board for a simple example (open closed principle).

So instead I created a PersonServiceManager that creates a "concrete" PersonService via IPersonRepository injection. The GUI communicates to the PersonServiceManager through an IPersonService interface.

Instead of "mocking" an IPersonRepository, we are actually implementing it then injecting it into PersonService (just like our NUnit test). The PersonServiceManager handles passing the appropriate database connection string down to the data layer. In my example, the data layer object PersonDb (which implements IPersonRepository and used for injection) utilizes the DbProviderFactory.

Here is the sample source (C# Console App).

Also remember that the sample source could be broken down into separate assemblies in a real world project.

Labels: ,

Wednesday, June 24, 2009

Side by Side - IE8, IE6, IE5.5, IE5, IE4.01, & IE3

Running IE8 on your computer? The included developer tools are great. Need to switch to IE7 mode? No problem using IE8.

But what about IE6, IE5.5, IE5, IE4.01, and IE3? Here is a free multiple installer you can use. And it works! And I performed a virus scan (before and after the install)... no problems detected.

Unfortunately, a couple of my JQuery sites look weird with IE6. I know I know, its not JQuery... rather its the IE6 CSS quirks (among other things... standards compliance... cough... cough...).

http://tredosoft.com/Multiple_IE

Labels: , , ,

Monday, June 22, 2009

Example mySql IsDate Function

Here is an example mySql IsDate function using a regular expression:

CREATE DEFINER=`root`@`localhost` FUNCTION `IsDate`(var varchar(25)) RETURNS tinyint(4)
DETERMINISTIC
BEGIN
/* 05/17/2009, 5/01/2009, 5/1/2009 */

declare result tinyint;

select  trim(var)

REGEXP '^([1-9]|0[1-9]|1[012])/([1-9]|0[1-9]|[12][0-9]|3[01])/(19|20)[0-9][0-9]'

into @result;

return @result;
END

Labels: