Created
December 13, 2012 06:09
-
-
Save maniserowicz/4274462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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