Fluent Dates added to NBuilder

Posted on June 6, 2009. Filed under: Uncategorized |

I’ve just published a new release of NBuilder with fluent date support. This means you can specify dates in a nice readable syntax.

The Problem

Say you want to set a date, 21:15 on March 21st 2008

You’d most likely do it something like this:

var date = new DateTime(2009, 03, 21, 21, 15);

This doesn’t read particularly well especially if you have loads of different dates.

The Solution

NBuilder’s fluent dates:

var date = The.Year(2008).On.March.The21st.At(21, 15);

That is the full syntax, there are loads of different variations, for convenience and better readability within different contexts.

No year (defaults to current year):

product.Created = On.March.The21st.At(09, 15);

No time:

product.LastEdited = On.March.The21st;

Using The(x) instead:

product.Created = On.March.The(15)

Using static months instead:

Just having the month without On. might read better in certain situations

myEntity.LastEditedOn = December.The10th

Specifying a time:

TimeSpan time = At.Time(23, 15);

or

TimeSpan time = The.Time(23, 15);

Today at 2pm:

var date = Today.At(14, 00);

You can use seconds as well:

var dateTime = July.The4th.At(07, 00, 05);

Using in the context of NBuilder

You can use the dates anywhere but in the context of NBuilder it would be something like this:

Fluent dates and NBuilder

Of course you can use the fluent dates with the RandomGenerator too:

random_fluent_dates

Hope you find it useful. Any comments / suggestions, please let me know.

Download NBuilder 2.1.7

Download NBuilder 2.1.7 from google code

Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: