Skip to content

Instantly share code, notes, and snippets.

@maniserowicz
Created December 13, 2012 06:09
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 maniserowicz/4274462 to your computer and use it in GitHub Desktop.
Save maniserowicz/4274462 to your computer and use it in GitHub Desktop.
public class FeeCalculator
{
public const decimal DailyFee = 50.0m;
public decimal FeeFor(DateTime startTime)
{
DateTime now = ApplicationTime.Current;
if (startTime > now)
{
throw new ArgumentException("Cannot calculate fee for future time");
}
int daysCount = (int)(now - startTime).TotalDays;
return DailyFee * daysCount;
}
}
public class FeeCalculatorTests : IDisposable
{
private FeeCalculator _calculator;
public FeeCalculatorTests()
{
ApplicationTime._replaceCurrentTimeLogic(() => new DateTime(2011, 03, 14, 13, 00, 00));
_calculator = new FeeCalculator();
}
public void Dispose()
{
ApplicationTime._revertToDefaultLogic();
}
[Fact]
public void returns_multiplication_of_days()
{
decimal fee = _calculator.FeeFor(new DateTime(2011, 03, 10));
Assert.Equal(200m, fee);
}
[Fact]
public void returns_0_if_the_same_day()
{
decimal fee = _calculator.FeeFor(new DateTime(2011, 03, 14, 10, 13, 00));
Assert.Equal(0.0m, fee);
}
[Fact]
public void throws_if_future_time()
{
Assert.Throws<ArgumentException>(
() => _calculator.FeeFor(new DateTime(2011, 05, 03))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment