Skip to content

Instantly share code, notes, and snippets.

@iskernel
Last active December 19, 2015 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iskernel/5992786 to your computer and use it in GitHub Desktop.
Save iskernel/5992786 to your computer and use it in GitHub Desktop.
A simple method for always obtaining a future date.
//The RIGHT way
[Test]
public void GetConversionRate_DateFutureParameter_ThrowsException()
{
//This will always return a date that will be in the future
DateTime future = DateTime.Now.AddYears(1);
Assert.Throws( typeof(CurrencyConversionException),
() => GrandTrunkCurrencyConversionService.Instance
.GetConversionRate(TEST_CURRENCY_NAME_US_DOLLAR,
TEST_CURRENCY_NAME_AU_DOLLAR,
future) );
}
//The NOT SO RIGHT way
[Test]
public void GetConversionRate_DateFutureParameter_ThrowsException()
{
//Perhaps no one will run this unit test in 10 years. But what if
//someone will?
DateTime notReallyFuture = new DateTime(2023,1,1);
Assert.Throws( typeof(CurrencyConversionException),
() => GrandTrunkCurrencyConversionService.Instance
.GetConversionRate(TEST_CURRENCY_NAME_US_DOLLAR,
TEST_CURRENCY_NAME_AU_DOLLAR,
notReallyFuture) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment