Timely greeting

Expanding on the classic Hello World example, what if you wanted to change your greeting based on the time of day? An example is as follows:

As a visitor to the site 
I want to receive a time-appropriate greeting
So that I may plan the submission of my talks

Given it is before noon
When greeting is requested
Then morning message is returned

Given it is afternoon
When greeting is requested
Then afternoon message is returned

You might think to yourself, this is simple; I can just write a quick method to return the proper message. Of course, you would be right. This is a pretty easy task. You might come up with something like this:

public string GetGreeting()
{
if (DateTime.Now.Hour < 12)
return "Good morning";

return "Good afternoon";
}

Remember, back in Chapter 5Why TDD is Important, we discussed the Three laws of TDD. The all-important first law states that you aren't allowed to write a single line of production code without a failing test.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.10.201