Skip to content

Instantly share code, notes, and snippets.

@MongkonEiadon
Created July 12, 2019 09:51
Show Gist options
  • Save MongkonEiadon/2809a92bad38a978376a8cdf87852ce1 to your computer and use it in GitHub Desktop.
Save MongkonEiadon/2809a92bad38a978376a8cdf87852ce1 to your computer and use it in GitHub Desktop.
public abstract class Test
{
...
protected IFixture Fixture { get; private set; }
[SetUp]
public void Setup()
{
Fixture = new Fixture().Customize(new AutoMoqCustomization());
}
protected Mock<T> InjectMock<T>(params object[] args)
where T : class
{
var mock = new Mock<T>(args);
Fixture.Inject(mock.Object);
return mock;
}
}
public abstract class TestFor<TSut> : Test
where TSut : class
{
private Lazy<TSut> _lazySut;
/// <summary>
/// The real object that you want to test
/// </summary>
protected TSut Sut => _lazySut.Value;
[SetUp]
public void SetUpTestsFor()
{
_lazySut = new Lazy<TSut>(CreateSut);
}
/// <summary>
/// Create real object
/// </summary>
/// <returns></returns>
protected virtual TSut CreateSut()
{
return Fixture.Create<TSut>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment