Magically fast mocking

What is DynMock?

DynMock is a high-performance .NET mocking framework that support dynamic objects.

Why use DynMock?

DynMock significantly cuts down on unit test waiting time without the need for new hardware and without rewriting existing unit tests as DynMock closely emulatates Moq, NSubstitute, and FakeItEasy syntaxes— DynMock also extends these with dynamic object mocking functionality.

Who is DynMock for?

DynMock is for large projects where the team members spend significant time waiting for unit tests, and teams looking to mock dynamic classes like ExpandoObject and DynamicObject.

Emulates the most popular syntaxes

DynMock has no syntax of its own and emulates the Moq, NSubstitute, and FakeitEasy syntax:

using NUnit.Framework;
using SysSurge.DynMock.Syntax.Moq;

namespace SysSurge.DynMock.Tests.Moq
{
    [TestFixture]
    public class GenericTests
    {
        [Test]
        public void MockActionReturnInt()
        {
            var mock = new Mock<IMotorist>();
            mock.Setup(foo => foo.GetAge()).Returns(1);
            var age = mock.Object.GetAge();
            Assert.AreEqual(1, age);
        }

}
using NUnit.Framework;
using SysSurge.DynMock.Syntax.NSubstitute;

namespace SysSurge.DynMock.Tests.NSubstitute
{
    [TestFixture]
    public class GenericTests
    {
        [Test]
        public void MockActionReturnInt()
        {
            var driver = Substitute.For<IMotorist>();
            driver.GetAge().Returns(1);
            var age = driver.GetAge();
            Assert.AreEqual(1, age);
        }

}
using NUnit.Framework;
using SysSurge.DynMock.Syntax.FakeItEasy;

namespace SysSurge.DynMock.Tests.FakeItEasy
{
    [TestFixture]
    public class GenericTests
    {
        [Test]
        public void Mock_Method_Return_Int()
        {
            var driver = A.Fake<IMotorist>();
            A.CallTo(() => driver.GetAge()).Returns(1);
            var age = driver.GetAge();
            Assert.AreEqual(1, age);
        }

}

Mock dynamic objects

DynMock extends Moq, NSubstitute, and FakeItEasy with support for mocking of dynamically objects.

using System;
using System.Dynamic;
using NUnit.Framework;
using SysSurge.DynMock.Syntax.FakeItEasy;

namespace SysSurge.DynMock.Tests.FakeItEasy
{
    [TestFixture]
    public class Wrapping_Tests
    {
        [Test]
        public void Dynamic_Mock_Return_String()
        {
            dynamic wrappedDynamic = new ExpandoObject();
            wrappedDynamic.First = "Jane";
            wrappedDynamic.Last = "Doe";
            wrappedDynamic.StringFunction = new Func<string>(() => wrappedDynamic.First + " " + wrappedDynamic.Last);
            var name = wrappedDynamic.StringFunction();
            Assert.AreEqual("Jane Doe", name);

            var person = A.Fake<IMisc>(x => x.Wrapping(new[] { wrappedDynamic }));
            A.CallTo(() => person.StringFunction()).Returns("Mocked name");
            name = person.StringFunction();
            Assert.AreEqual("Mocked name", name);
        }
}