Project Description
SimpleMock is a mocking framework that is designed to be lightweight, simplistic, minimalistic, strongly typed and generally very easy to use via a Fluent API.

It is inspired by Moq and was implemented as an academic challenge rather than being an alternative to the more popular and mature mocking frameworks out there.

Method Mocking

var mock = new Mock<IFoo>();

// Define a mock implementation for the Add(int, int) method to return 3 in case arguments 1 and 2 are provided.
mock.HasMethod(foo => foo.Add(1, 2))
    .Returns(3);

// Define a mock implementation for the ToString(int) method to return "1" in case argument 1 is provided.
mock.HasMethod(foo => foo.ToString(1))
    .Returns("1");

// Define a mock implementation for the ParseInt(string) method to throw an ArgumentNullException in case argument null is provided.
mock.HasMethod(foo => foo.ParseInt(null))
    .Throws<ArgumentNullException>();

// It supports a callback handler to be executed any time a mock implementation is ran
mock.HasMethod(foo => foo.SomeMethod("SomeParameter"))
    .Returns("SomeResult")
    .Subscribe(() => Console.WriteLine("SomeMethod() is executed"));

// It also supports providing a custom implementation by means of a delegate. Useful in scenarios where more complex logic is required.
// Note: the arguments are ignored as they are only used for overload resolution
mock.HasMethod(
        foo => foo.MyComplexMethod(1, 2, 3),
        (a, b, c) => 
        {
            return a + b + c;
        });

Last edited Jun 18, 2011 at 6:19 PM by yannickmotton, version 6