My blog has moved!!

Monday, December 24, 2007

I was working with the new MS MVC framework but with express, I used Lazycoders post as a helper to what lead to this template. I have put together a simple C# project template for Visual Web Developer 2008 Express Edition. Just dump it into your

  "(my docs)\Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer"

folder and choose “new website” etc (may need to restart the IDE to pick up the files).

It puts together the basic structure using the "App_Code" restriction in the express edition of the IDE (well, and some others...)

 

There is also a simple “view page” item template, drop this into

  "(my docs)\Visual Studio 2008\Templates\ItemTemplates\Visual Web Developer"

I did not worry about the controller (simgle page + simple change etc)...

Merry Christmas! PK :-)

 

Files:

Monday, December 24, 2007 3:09:14 AM (GMT Standard Time, UTC+00:00) |  | #
Wednesday, October 31, 2007
It's common practice for developers to make small "TODO" notes in code as they work for themselves or others to clarify at some time...

// TODO: confirm this business requirement...
// TODO: make this better!
// TODO: bread, butter, eggs and milk...

Issues can arise when the TODO's are not taken care of for whatever reason or get lost in the mayhem of meeting deadlines. A worst case scenario could arise when there is a production defect for an obscure situation and the maintenance programmer finds something like this:

// TODO: Not sure if there are any more response codes for this one, check before release.

Opps! Now that's expensive.
Now I am not saying this is good or bad (!) practice - but what I have started to do within my team is create either a failing or ignored unit test (depending on the importance) marking what would normally be an innocent "TODO" item. The unit test stays in the build as either a fail or ignore and does not drop off the radar.

[Test]
public void Need_to_confirm_foo()
{
  Assert.Fail();
}

Or...

[Test]
[Ignore("Confirmation required from the business")]
public void A_foo_only_has_a_bla()
{
}

It's much harder to miss a bunch of ignored or failing unit tests before that production release than some well hidden TODO comments!

kick it on DotNetKicks.com

Wednesday, October 31, 2007 9:40:05 AM (GMT Standard Time, UTC+00:00) |  |  |  | #
Thursday, October 04, 2007

Scott Guthrie talks about Microsoft releasing the .Net framework source code later this year.
A very good move by Microsoft I think :-)

http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx

Thursday, October 04, 2007 2:22:05 AM (GMT Standard Time, UTC+00:00) |  |  | #
Monday, August 27, 2007

I have uploaded a small development tool that I put together recently, its called "Behaviour to Unit Test". Basically it converts code functionality from plain sentences (or stories) into unit test stub code. You could also think of it as a cure for TDD writers block!

For an example of the usage, use the Generation -> Fill out example menu option and hit Convert. Basically it takes a set of plain language behaviours for an object such as "person":

  • Check that the default values of all string properties are empty
  • The ToString method renders the first and last names
  • If the date of birth is null, calculate age will return -1
  • If the date of birth is not null, calculate age will return a value

...and converts them into something like:

using System;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace Tests
{
    [TestFixture]
    public class PersonEntityTests
    {
        private PersonEntity person;
        
        [SetUp]
        public void TestSetUp()
        {
            person = new PersonEntity();
        }
        
        [Test]
        [Ignore("Currently only a unit test stub")]
        public void CheckThatTheDefaultValuesOfAllStringPropertiesAreEmpty()
        {
        }
        
        [Test]
        [Ignore("Currently only a unit test stub")]
        public void TheToStringMethodRendersTheFirstAndLastNames()
        {
        }
        
        [Test]
        [Ignore("Currently only a unit test stub")]
        public void IfTheDateOfBirthIsNullCalculateAgeWillReturnMinus1()
        {
        }
        
        [Test]
        [Ignore("Currently only a unit test stub")]
        public void IfTheDateOfBirthIsNotNullCalculateAgeWillReturnAValue()
        {
        }
    }
}

There are C# and VB.NET templates for now. Check it out:

  http://www.pksoftware.net/BehaviourToUnitTest/

My intention is to keep the tool small and simple. The main thing I want to add at the moment is some load/save functionality and drop in the ICSharp.TextEditor for more friendly editing...

kick it on DotNetKicks.com

Monday, August 27, 2007 9:43:04 AM (GMT Standard Time, UTC+00:00) |  |  |  |  |  | #
Thursday, July 19, 2007

This is just a quick heads up to say that I think the Castle Project rocks!

I have been using it allot of late especially Active Record. I'll blog more detail later but it's what I have been looking for all these years! Many time I have implemented simple subsets of the functionality that Castle provides to help get the job done. Castle wraps up all those funky framework fragments and more with a great "action pack" flavour to it in the form of Mono Rail (i.e. 'ruby on rails' for .Net)

Very cool  ;-)

Thursday, July 19, 2007 11:21:35 AM (GMT Standard Time, UTC+00:00) |  |  | #
Thursday, May 17, 2007
This is the line of code that I keep forgetting...

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

Use it in (for example) the Program.Main function when the application starts up and the threads currrent principal is now the windows user. So...

Thread.CurrentPrincipal.Identity.IsAuthenticated

Will now be true and you can make use of the Identity.Name property etc.

Self reminder over...

More Notes...

If for example you need to perform unit tests as a windows user (to access the username or hit a resource) you can make use of the AppDomain.CurrentDomain.SetPrincipalPolicy method in the test fixture setup/teardown methods - see example below. I put the UnauthenticatedPrincipal setting in the teardown so that subsequent tests do not have their principal modified by accident...

using System;
using System.Security.Principal;
using System.Threading;
using NUnit.Framework;

namespace Tests.SetPrincipalPolicyExample
{
    [TestFixture]
    public class TestSomethingUsingCurrentWindowsPrincipal
    {
        /// <summary>Called once before all tests are run.</summary>
        [TestFixtureSetUp()]
        public void TestFixtureSetUp()
        {
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
        }

        /// <summary>Called once after all tests have run.</summary>
        [TestFixtureTearDown()]
        public void TestFixtureTearDown()
        {
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.UnauthenticatedPrincipal);
        }

        [Test]
        public void VerifySomething()
        {
            string expectedUsername = Thread.CurrentPrincipal.Identity.Name;
            // more testing stuff
        }
    }
}


Thursday, May 17, 2007 1:32:42 PM (GMT Standard Time, UTC+00:00) |  | #
Friday, January 12, 2007

Jeremy Miller has put together a great post on Orthogonal Code - I must admit, I used to code like that! Lucky we can learn and move on... well worth the read.

http://codebetter.com/blogs/jeremy.miller/archive/2007/01/08/Orthogonal-Code.aspx

Friday, January 12, 2007 1:26:48 PM (GMT Standard Time, UTC+00:00) |  |  | #
Tuesday, January 09, 2007

At some point in the unit testing game you will need to tackle the unpleasant task of actually coding and running unit tests on the data access code. This in itself can open a bit of a can of worms - the bigger the database, the more worms you need to deal with. If you want a quick solution to being able to run a bunch of data access tests that insert, update and delete data in tables - try putting a TransactionScope object at the test fixture level. If the scope is not committed the changes are not stored, perfect scenario for a group of unit tests.

Marcus Rosen prompted the idea and I have been using this technique against a local copy of an MSSQL database and have had no issues to date. It has simplified the development process in that data does not keep disappearing due to my unit tests clearing tables and inserting test items.

I have seen "Rollback" attributes around (such as http://weblogs.asp.net/rosherove/archive/2004/10/05/238201.aspx) but the above solution is a one liner and requires no new libraries, and integration etc.

I like a simple solution  ;-)


MSDN TransacrionScope Help:
http://msdn2.microsoft.com/en-us/library/system.transactions.transactionscope.aspx

Tuesday, January 09, 2007 12:50:19 PM (GMT Standard Time, UTC+00:00) |  |  | #
Thursday, November 23, 2006
Using the InternalsVisibleTo attribute to get access to another classes internal methods for testing.
Thursday, November 23, 2006 12:42:08 PM (GMT Standard Time, UTC+00:00) |  |  | #
Thursday, November 16, 2006

When I first started trying out TDD and (more so when I started using the TestDriven.Net), I still spend a good chunk of my test development time stepping through the code line by line, checking the state of variable etc. It took me a while to kick the habit, but when you get stuck into TDD you won't be spending anywhere near as much time stepping through your code trying to work out what’s going wrong as you probably used to.
Why? Because the unit tests you write in an incremental fashion, build slowly on the last and in turn your confidence in the code is greater – you no longer feel the need to step through the code. When I run a test that fails now I can usually spot the issue relatively quickly without having to "step in". Those small TDD steps really pay off.
Don't get me wrong, I still step into my code when I get a curly one, but it's more the odd occasion now than the natural response.
Stay out of that debugger - it will save you a lot of time :-)
Thursday, November 16, 2006 9:46:13 AM (GMT Standard Time, UTC+00:00) |  |  | #
Monday, November 13, 2006
Why would anyone have a problem paying a (small amount) for a great piece of productivity software? Jamie Cansdale has been copping flack about making TestDriven.Net a commercial product...
Monday, November 13, 2006 9:39:55 AM (GMT Standard Time, UTC+00:00) |  |  | #
Friday, November 10, 2006
NCover Explorer is one of my "Must Have Apps"...
Friday, November 10, 2006 9:45:53 AM (GMT Standard Time, UTC+00:00) |  |  | #
Tuesday, April 18, 2006
a "mini" snippit that actually does something cool ;-)
Tuesday, April 18, 2006 11:09:33 PM (GMT Standard Time, UTC+00:00) |  | #
Monday, April 03, 2006
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: DerivedControl --- The base class 'GenericControlBase' could not be loaded. Ensure the assembly has been referenced and that all projects have been built. I can understand – but it’s still a bit annoying! I have some windows forms user controls that inherit from a class that implements generics. Problem is the designer can’t reflect those classes and in turn spits out the wonderful error above.
Monday, April 03, 2006 10:10:43 PM (GMT Standard Time, UTC+00:00) |  |  | #
Sunday, February 26, 2006
A tutorial on using Microsoft .Net's CodeDom technology to generate assemblies on the fly.
Sunday, February 26, 2006 1:21:02 AM (GMT Standard Time, UTC+00:00) |  |  | #
Monday, January 02, 2006
This is where I will post code development related articles.
Monday, January 02, 2006 2:21:16 AM (GMT Standard Time, UTC+00:00) |  | #
Search
Links
Products
Mini SQL Query
Mini SQL Query is a minimalist SQL query tool for multiple providers (MSSQL, Oracle, OLEDB, MS Access files etc.)

Verse Popper
The "Verse Popper" displays bible verses periodically in the lower right hand corner of your screen.

Categories
Blogroll
 PK Software DevBlog
My new blog!