Category Archives: Uncategorized

Simplify your test assertions

Came across this failing test, immediately felt a bit verbose… with testing in general the simpler and cleaner your tests can stay the better, otherwise test rot starts to creep up, developers procrastinate
about fixing them etc….

The test assertion was:


It Should_be_add_a_message_to_the_contractor_conversation = () =>
{
Assert.That(_contractor.Messages, Has.Some.InstanceOf().And.All.With.Property("Content").EqualTo(messageContent));
};

Changed to:


It Should_be_add_a_message_to_the_contractor_conversation = () =>
{
_contractor.Messages.ShouldContainAny(m => m.Content == messageContent);
};

The extension method:


public static void ShouldContainAny(this IEnumerable list, Func comparer, params T[] items)
{
if (items.Any(comparer))
{
throw new SpecificationException(string.Format(@"Should contain any matching item but contains none"));
}
}

Win place at the TDD Masterclass!!

Roy Osherove is giving an hands-on TDD Masterclass in the UK, September 21-25. Roy is author of “The Art of Unit Testing” (http://www.artofunittesting.com/), a leading tdd & unit testing book; he maintains a blog at http://iserializable.com (which amoung other things has critiqued tests written by Microsoft for asp.net MVC – check out the testreviews category) and has recently been on the Scott Hanselman podcast (http://bit.ly/psgYO) where he educated Scott on best practices in Unit Testing techniques. For a further insight into Roy’s style, be sure to also check out Roy’s talk at the recent Norwegian Developer’s Conference (http://bit.ly/NuJVa).

Full Details here: http://bbits.co.uk/tddmasterclass

bbits are holding a raffle for a free ticket for the event. To be eligible to win the ticket (worth £2395!) you MUST paste this text, including all links, into your blog and email Ian@bbits.co.uk with the url to the blog entry.  The draw will be made on September 1st and the winner informed by email and on bbits.co.uk/blog

asp.net mvc – The virtual path maps to another application, which is not allowed

what a waste of time… i was getting this error:

Error 1
The virtual path ‘/Views/Shared/Site.Master’ maps to another application, which is not allowed. C:\temp\Views\Cart\New.aspx

this didn’t really help me, some searching said stuff about IIS mappings etc… anyways it turns out to be very simple… one of my views had a missing tilde ~

“/Views/Shared/Site.Master” i changed it to   “~/Views/Shared/Site.Master” and the problem was gone…

as i said what a waste of time !!!!


ApplicationPoolIdentity IIS 7, Asp.net Gotcha!!!!

 

What a waste of an hour…   I was running an asp.net mvc app  on my VMWare Fusion VM, with Windows 7 RC & IIS 7. When i kept getting this error:

System.Security.SecurityException: Request for the permission of type ‘System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.

The thing that threw me off was that it only seemed to happen doing certain stuff, like the mvc future strongly typed links and html helper submits..

<% Html.SubmitImage(…..

Also if you search for posts/forums on it you;’ll bump into the UNC path issue, which again threw me a little.. “was it because of my VM, was iis seeing my C drive as a share?” crazy talk but still that’s the kind of shit that goes through your head when debugging these kinds of issues…

 

Anyways in the end it was the identity that the Application pool for my site was running under, funnily enough  called “ApplicationPoolIdentity”.

I changed it to network service and all is fine..

check out this post which covers the issue…

Visual Studio CSS Formatting… nice!!

 

Now that I’m back doing alot of CSS i came across a post describing the CSS formatting feature in visual studio…

My preference is for single line css. I dont like to expand to one line per rule, thats just my personal preference. But it can be a pain to maintain.

Enter visual studio:

here’s some code i had….

 

body
  {
      background: #123;
      border-top: 5px solid #000;
      color: #333;
      font-size: 11px;
      padding: 20px 0 40px;
  }
  a
  {
      color: #fff;
      text-decoration: none;
  }
  a:hover
  {
      text-decoration: underline;
  }
  h1
  {
      font-family: Georgia, serif;
      font-weight: normal;
      text-align: center;
  }

and with a quick Format!!!

body { background: #123; border-top: 5px solid #000; color: #333; font-size: 11px; padding: 20px 0 40px; }
a { color: #fff; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-family: Georgia, serif; font-weight: normal; text-align: center; }

nice….

 

now if only the formatter would make the rules alphabetical !!!!

Visual Studio CSS Formatting… nice!!

 

Now that I’m back doing alot of CSS i came across a post describing the CSS formatting feature in visual studio…

My preference is for single line css. I dont like to expand to one line per rule, thats just my personal preference. But it can be a pain to maintain.

Enter visual studio:

here’s some code i had….

 

body
  {
      background: #123;
      border-top: 5px solid #000;
      color: #333;
      font-size: 11px;
      padding: 20px 0 40px;
  }
  a
  {
      color: #fff;
      text-decoration: none;
  }
  a:hover
  {
      text-decoration: underline;
  }
  h1
  {
      font-family: Georgia, serif;
      font-weight: normal;
      text-align: center;
  }

and with a quick Format!!!

body { background: #123; border-top: 5px solid #000; color: #333; font-size: 11px; padding: 20px 0 40px; }
a { color: #fff; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-family: Georgia, serif; font-weight: normal; text-align: center; }

nice….

 

now if only the formatter would make the rules alphabetical !!!!

Will IronRuby take off???

Hi,

I’ve been working with ruby for about 6 months now on and off but the majority of my development is still in C#. So i’ve been keen to try out the possibility of using IronRuby with C#. I think the mixture of both langauges is compelling as there’s cases where a dynamic language is a better choice, more flexible and faster (development time).

Also with ruby there’s a really good opportunity to build internal DSL’s fast, and with an elegant end product. You only have to look at ActiveRecord in rails:

class Post < ActiveRecord::Base
  has_many :comments
  validates_presence_of :text

  ...
end

class Comment < ActiveRecord::Base
  belongs_to :post
  ...
end

and RSpec:

describe "(empty)" do
    it { @stack.should be_empty }
    it_should_behave_like "non-full Stack"
    it "should complain when sent #peek" do
      lambda { @stack.peek }.should raise_error(StackUnderflowError)
    end
    it "should complain when sent #pop" do
      lambda { @stack.pop }.should raise_error(StackUnderflowError)
    end
end

to be fair with the increasing number of fluent interface API’s in the .net world the drive towards more understandable code is not the preserve of the dynamic people.  With tools like StructureMap,

registry.AddInstanceOf<IWidget>()
 .WithName("DarkGreen")
 .UsingConcreteType<ColorWidget>()
 .WithProperty("Color").EqualTo("DarkGreen");

we get a very intuitive, understandable API which is also a DSL as far as i’m concerned. But i still believe that ruby’s looser syntax allows us to build nicer looking DSL’s :-)

I guess ultimately it’ll come down to how easy it is to use IronRuby with C#, how good the tooling is, for example RubyMine is a ruby IDE from Jetbrains (resharper) which provides refactoring support and with these guys on the case i feel confident that the ruby refactoring story will only get better.

I did a talk on Ruby/IronRuby for skillmatter a while back and speaking to everyone at the talk there was a consistent message, we like/love ruby, love the tools available, rspec, cucumber, rake etc but we really need stability & ide support.

Its arguable whether you need an ide, i used textmate for the majority of my rails dev, however i did find it alot easier once i started to use it in combination with rubymine. Textmate for cranking out the code (its gr8, no clunky huge ide in the way), but when things got messy (i.e. i couldnt figure out a problem) i was able to boot up rubymine and get the full visual studio like experience with debugging, break points, watches, hover over variables etc, all that good stuff.

So if we get this for IronRuby i.e. a texteditor (which there are already loads of, e.g. e-editior, notepad++ etc) and full visual studio support I think people would jump all over Ruby/IronRuby.

visual studio team system very slow right click…

if your having performance problems in VS2008 with Team Explorer on with large projects where you right click on the solution explorer and it takes a long fixed amount of time to load up each context menu then this could be for you.

it drove me crazy for a while until i found this patch that sorted it out..

http://code.msdn.microsoft.com/KB947751/Release/ProjectReleases.aspx?ReleaseId=1022

starting a new website – use a css framework

i’ve been doing web development for a number of years, although most of those were asp.net, i did some jsp and have also recently built a site using ruby on rails, it was during the development of that site that i came across the blueprint css framework.

my conclusion, unless your a real css freak/hacker then save yourself alot of time and either use this or something similar such as yahoo grids – developer.yahoo.com/yui/grids ,   or 960 grids – http://960.gs

you’ll find a good example here:

http://wiki.github.com/joshuaclayton/blueprint-css/quick-start-tutorial

meet macruby

peepcode’s latest screencast is on macruby…http://peepcode.com/products/meet-macruby

i have to say i give the thumbs up to peepcode.. Geoffrey Grosenbach has done a gr8 job with the content here…

even if your not into rails or ruby or objective c etc, it worth grabbing the unlimited subscription and watching this stuff  as it should open up your horizons to new ways of doing things and looking over at how other communities are getting they’re work done… obviously if your a developer using this stuff then all the better…

i’m looking forward to building a native twitter client for the mac in ruby, as even though i’ve looked into objective-c i cant see myself getting into it as easy as i would ruby…