Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple base test class
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