Created
July 12, 2019 09:51
-
-
Save MongkonEiadon/2809a92bad38a978376a8cdf87852ce1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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; | |
} | |
} |
This file contains hidden or 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 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