Last active
March 8, 2019 19:24
-
-
Save akatakritos/5a6f44c89dd95d63174388f9f10fc423 to your computer and use it in GitHub Desktop.
C# Fixture Classes
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 FooServiceTests | |
{ | |
private Fixture _fixture = new Fixture(); | |
[Test] | |
public void WhenLoggedIn_TheReportHasTheUsersNameIncluded() | |
{ | |
var subject = _fixture.LogIn("George Washington").CreateService(); | |
var result = subject.GetReportData(); | |
Check.That(result.CurrentUserName).IsEqualTo("George Washington"); | |
} | |
private class Fixture | |
{ | |
public IDependency MockDependency = new Mock<IDependency>(); | |
public Fixture LogIn(string name) | |
{ | |
MockDependency.SetUp(m => m.GetCurrentUser()).Returns(name); | |
return this; | |
} | |
public FooService CreateService() | |
{ | |
return new FooService(MockDependency.Object); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment