Last active
April 6, 2016 20:18
-
-
Save jrwdexter/cd590b6282fb2512ee7c18067467407e 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 NotBehaviorCoupledTests | |
{ | |
// GOOD | |
Fake<IMyDependency> _myDependency; | |
IMyService _myService; | |
[TestInitialize] | |
public void Initialize() | |
{ | |
_myDependency = A.Fake<IMyDependency>(); | |
_myService = new MyService(_myDependency.FakeObject); | |
} | |
[TestMethod] | |
public void A_call_to_thing_should_return_child_object() | |
{ | |
// Arrange behavior | |
var childObject = new object(); | |
A.CallTo(() => _myDependency.GetChildObject()).Returns(childObject); | |
// Act | |
var result = _myService.GetThing(); | |
// Assert | |
Assert.AreEqual(childObject, result); | |
} | |
} | |
public class BehaviorCoupledTests | |
{ | |
// BAD | |
Fake<IMyDependency> _myDependency; | |
IMyService _myService; | |
[TestInitialize] | |
public void Initialize() | |
{ | |
_myDependency = A.Fake<IMyDependency>(); | |
_myService = new MyService(_myDependency.FakeObject); | |
// Arrange behavior | |
var childObject = new object(); | |
A.CallTo(() => _myDependency.GetChildObject()).Returns(childObject); | |
} | |
[TestMethod] | |
public void A_call_to_thing_should_return_child_object() | |
{ | |
// Act | |
var result = _myService.GetThing(); | |
// Assert | |
Assert.AreEqual(childObject, result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment