May 2009 Entries

A friend of mine, Troy, showed me this a while ago, and I thought this is probably one of the best office tips EVAR.scribble1

Have you ever been designing at the white board and accidentally wrote on it with a permanent marker? We use sharpies all the time for User Stories and it happened to me and I thought I was forced to live with the blue blemish on my whiteboard forever. Not true.

Take a regular white board marker (preferably the same color as the permanent marker) and write right over the top of the permanent mark. Let it dry and then erase as normal. The white board marker’s marks lift off the permanent marks!

This is especially useful for Kanban Boards.

Hope this helps someone as much as it has helped me.

~Lee

Obviously, my Tip of the Day is not meant to be a DAILY thing, so I thought I’d just rename to R# Tip. This is a prettyrsharp_navigate_to_type common one, but it’s possible some people aren’t aware of it.

For simple navigation, using ctrl+t or ctrl+shift+t can be invaluable. If you need to navigate to the file containing the Floogle type ctrl+t can get you there in a hurry. Hit ctrl+t and then type the name of the type you want to navigate to. You can also use capitalizxation to get you there faster. For instance, if you wanted the FloogleDTO to show up at the top, you could type the capitals and get there (e.g. type FDTO and the FloogleDTO type will be the only one matching).

But, if you need to get to a FILE and not a type name, use ctrl+shift+t and type the name of the file, same as you typed the name of the type before.

Try it out!

~Lee

bc_shout_thumb With the flat response from the series so far, I thought I’d stir the pot a little. Again, I am not trying to start a flame war, I just want to share my opinion and start a conversation about it.

I’ll start by saying that I am VERY comfortable using SQL. PL/SQL, T-SQL and even a bit of MySQL (ack). But after using NHibernate for the last year or so, I can honestly say that if I never write another sproc, I’ll be totally OK with that. I don’t think sprocs are evil, or ruin your application, for me it’s about testability. I like the fact that I can write a test that can check my query logic and never have to touch the database. I like the fact that I can test all four basic CRUD operations with one line of code! Most of all, I like doing it in C#.

There are times when there is no good substitute for a good sproc. But for most applications, I don’t see the point. SPECIALLY for CRUD operations.

What do YOU think?

It’s true, I swear. It’s very simple to test if you can (C)reate, (R)ead, (U)pdate and (D)elete objects using NHibernate, and Fluent NHibernate makes it one (fluent) line of code!

Suppose we have an Employee object and we want to check that we can CRUD it AND reference to the Company (object) they work for in the mapping. It might look like this:

   1:  new PersistenceSpecification<Employee>(Session)
   2:      .CheckProperty(x => x.FirstName, "Dave")
   3:      .CheckProperty(x => x.LastName, "Jones")
   4:      .CheckProperty(x => x.MiddleInitial, "L")
   5:      .CheckProperty(x => x.DateOfBirth, new DateTime(2008, 11, 1))
   6:      .CheckProperty(x => x.Sex, _sex)
   7:      .CheckReference(x => x.Company, new Company{ CompanyID = 999, Name = "Wonder Wheels" })
   8:      .VerifyTheMappings(); 

Okay, it may not LOOK like one line of code, but I swear it is. One, long, fluent line of code.

Super sweet. If you’ve found better ways, post a comment, I LOVE to learn better ways.

 

~L

That’s right, I said it, I’ve been doing it, and I abso-effin-lutely love it.

A few months ago my co-worker, Troy, posted a question on Stack Overflow. We were doing integration testing on a project we were working on, and as the object graph grew larger, the code required to test query logic became painful. Since I am a sissy and don’t like pain, Troy asked the question on SO about how we might do it less painfully, and we got this answer, and it totally changed our TDD/BDD lives.

The answer came from Garry Shutler, here and I’ll just sort of re-iterate it.

We created a base Interface for our repositories IRepository<T>, with a method IQueryable<T> All(). like so:

   1:  public interface IRepository<T>
   2:  {
   3:      IQueryable<T> All();
   4:      // whatever else you want
   5:  }

 

Then we implement it like so:
   1:  public IQueryable<T> All()
   2:  {
   3:      return session.Linq<T>();
   4:  }

We can then mock the IRepository<T>:

   1:  _repository = MockRepository.GenerateMock<IRepository<Customer>>();

 

Then Stub it to return a predefined list of objects that we are searching
   1:  _repository.Stub(repo => repo.All()).Return(TestCustomers.All().AsQueryable());

 

Then we can test the login of a Customer search by:
   1:  [Test]
   2:  public void should_return_customers_matching_first_name_last_name_and_dob()
   3:  {
   4:      Assert.That(_returnedMatches.Contains(_firstNameLastNameDOBMatch));
   5:  }

 

 

 

 

 

Many thanks to Garry for all the time he saved us, I immediately subscribed to his blog and have not been disappointed. I hope this helps someone as much as it has helped us.

~L

1) OK, so Coders4Charities went well. The .NET User Group Meeting went well. Now it’s time to take a (small) break. teletype

2) Most who know me probably already know, but I’ve been assigned as regional mentor for INETA membership for Missouri and Kansas. That will be consuming some of my time to get my head around who my UG leaders are and what they need from me, as well as helping fledgling UGs get started.

3) I won Fourth Place in Community Credit for the month of April! I get a sweet pin clock.

4) I will be speaking at the Twin Cities Developer's Guild on May 12th (Yikes next Tuesday) about BDD and I will be helping deliver some Mix 09 content at the Jefferson City .Net User Group on June 9th.

5) Today was my dog, Frieda’s 5th birthday, so we went to the park, got her a hamburger and Stacey made her a carrot cake. I know, we spoil her, don’t look at me like that.

6) I started my foray into Ruby programming tonight. I am mostly interested, because I am a freak for anything BDD, and RSpec is the gold standard to me of Context-Specification style BDD. Haven’t dived into Cucumber yet, but that’s coming soon. I am really liking the syntax of Ruby. It is easy to learn the basics and I am already creating classes and small programs. Now I just need a small project to sink my teeth into and drive the design out with behaviors using RSpec.

That’s about all for now. More information to come an all the new happenings. Stay tuned, dear readers!

~Lee