This package provides some utilities to make it easier to test in C#. For starters it provides a lightweight dependency factory to manage all the tests dependencies. Making it easily and safe to register and replace dependencies within each test. Which provides proper state to test against.
The package is easily installed using nuget.
Install-Package MatrTech.Utilities.Test
using namespace Matr.Test;That's it, now you can use the package.
[TestClass]
public class TestClass : TestBase
{
...
}public class TestClass : TestBase
{
...
}Not yet implemented.
[TestInitialize]
public void TestInitialize()
{
factory.RegisterOrReplace(new Mock<ITestDependency>().Object);
}[SetUp]
public void Init()
{
factory.RegisterOrReplace(new Mock<ITestDependency>().Object);
}Not yet implemented.
[TestMethod]
public void TestMethod()
{
// Setup test specifc dependencies.
var mockedDependency = new Mock<ITestDependency>();
// Mock functionality specific to the test.
mockedDependency.Setup(...).Returns(...);
// Register test specifc dependencies.
factory.RegisterOrReplace(mockedDependency.Object);
// Create your service with the Create method.
// This will resolve all dependencies.
var serviceToTest = factory.Create<ServiceToTest>();
var result = serviceToTest.MethodToTest();
Assert.Equal(result, expectedValue);
}Same goes for NUnit
[Test]
public void TestMethod()
{
// Setup test specifc dependencies.
var mockedDependency = new Mock<ITestDependency>();
// Mock functionality specific to the test.
mockedDependency.Setup(...).Returns(...);
// Register test specifc dependencies.
factory.RegisterOrReplace(mockedDependency.Object);
// Create your service with the Create method.
// This will resolve all dependencies.
var serviceToTest = factory.Create<ServiceToTest>();
var result = serviceToTest.MethodToTest();
Assert.Equal(result, expectedValue);
}Not yet implemented.
- XUnit implementation
- JsonTestSource