-
-
Save CopperStarSystems/9a5b5c12b079d000b14ffc2912830e28 to your computer and use it in GitHub Desktop.
A simple base test class
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
using Moq; | |
using NUnit.Framework; | |
[TestFixture] | |
public abstract class TestBase<T> where T : class | |
{ | |
MockRepository mockRepository; | |
[Test] | |
public void Constructor_Always_PerformsExpectedWork() | |
{ | |
VerifyAllMocks(); | |
} | |
[SetUp] | |
public void SetUp() | |
{ | |
CreateMockRepository(); | |
CreateMocks(); | |
ConfigureConstructorMocks(); | |
SystemUnderTest = CreateSystemUnderTest(); | |
} | |
protected T SystemUnderTest { get; private set; } | |
protected abstract void ConfigureConstructorMocks(); | |
protected Mock<TMock> CreateMock<TMock>() where TMock : class | |
{ | |
return mockRepository.Create<TMock>(); | |
} | |
protected abstract void CreateMocks(); | |
protected abstract T CreateSystemUnderTest(); | |
protected void VerifyAllMocks() | |
{ | |
mockRepository.VerifyAll(); | |
} | |
void CreateMockRepository() | |
{ | |
mockRepository = new MockRepository(MockBehavior.Strict); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment