Skip to content

Instantly share code, notes, and snippets.

@akatakritos
Last active March 8, 2019 19:24
Show Gist options
  • Save akatakritos/5a6f44c89dd95d63174388f9f10fc423 to your computer and use it in GitHub Desktop.
Save akatakritos/5a6f44c89dd95d63174388f9f10fc423 to your computer and use it in GitHub Desktop.
C# Fixture Classes
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