Created
August 19, 2014 07:57
-
-
Save MattKeen/361124ab4a2c101edcd1 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
[TestClass] | |
public class GravityTest | |
{ | |
private const decimal EarthFactor = 9.8M; | |
private IPlanet Planet { get; set; } | |
private Gravity Target { get; set; } | |
[TestInitialize] | |
public void BeforeEachTest() | |
{ | |
Planet = Mock.Create<IPlanet>(); | |
Target = new Gravity(Planet); | |
} | |
[TestClass] | |
public class GetVelocityAfter : GravityTest | |
{ | |
[TestMethod] | |
public void Returns_Zero_When_Passed_Zero() | |
{ | |
AssertVelocityAfterNumberOfSeconds(numberOfSeconds: 0, expectedVelocity: 0); | |
} | |
[TestMethod] | |
public void Returns_Nine_Point_Eight_After_1_Second_On_Earth() | |
{ | |
Planet.Arrange(p => p.GetGravitationalFactor()).Returns(EarthFactor); | |
AssertVelocityAfterNumberOfSeconds(numberOfSeconds: 1, expectedVelocity: 9.8); | |
} | |
[TestMethod] | |
public void Returns_NinetyEight_After_10_Seconds_On_Earth() | |
{ | |
Planet.Arrange(p => p.GetGravitationalFactor()).Returns(EarthFactor); | |
AssertVelocityAfterNumberOfSeconds(numberOfSeconds: 10, expectedVelocity: 98); | |
} | |
private void AssertVelocityAfterNumberOfSeconds(int numberOfSeconds, decimal expectedVelocity) | |
{ | |
var velocityAfterGivenSeconds = Target.GetVelocityAfter(numberOfSeconds); | |
Assert.AreEqual<decimal>(expectedVelocity, velocityAfterGivenSeconds); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think an assertion library like Should or Fluent Assertions can help to achieve the readability you are trying to get to without over-refactoring it: