Welcome to EasyMock Codeplex Page. This project started as a tutorial series on http://elemarjr.wordpress.com 
Important: This is *NOT* a .net version of Java Mock Framework "EasyMock"

Like Moq, EasyMock is intended to be simple to use, strong typed (no more magic strings!, and therefore full compiler-verified and refactoring-friendly). EasyMock is really Fluent.

Some samples:
var target = new FluentMock<IFoo>()
                .CreateObject();

// Planning to throw an exception
var target = new FluentMock<IFoo>()
                .Setup((foo) => foo.DoSomething())
                .Throws<InvalidOperationException>()
                .CreateObject();

// conditional return
var target = new FluentMock<IFoo>()
                .Setup( (foo) => foo.Process("1"))
                .Returns(1)

                .Setup((foo) => foo.Process("2"))
                .Returns(1500)
                
                .CreateObject();

// support to "flexible" parameters (matching arguments)
var target = new FluentMock<IFoo>()
                .Setup((foo) => foo.Process(It.IsInRange(1, 5)))
                .Returns(1)

                .Setup((foo) => foo.Process(It.IsInRange(6, 10)))
                .Returns(2)
                
                .CreateObject();

// support to lazy-loading return
var target = new FluentMock<IFoo>()
                .Setup((foo) => foo.GetDate(It.IsInRange(1, 5)))
                .Returns(() => DateTime.Now)

// support to callbacks
var target = new FluentMock<IFoo>()

                .Setup((foo) => foo.Process(It.IsAny<int>()))
                .Callback(() => before = true)
                .Returns(1)
                .Callback(() => after = true)

                .CreateObject();

// support to mock multiple interfaces
var target = new FluentMock()
                    .As<IFoo>()
                        .Setup( (foo) => foo.DoSomething() )
                        .Callback( () => ifoo = true )
                    .As<IFoo2>()
                        .Setup((foo) => foo.DoSomething2())
                        .Callback( () => ifoo2 = true )
                    .CreateObject();

// support to "property behavior" to all properties
var target = new FluentMock<IFooGetSetProperty>()
                .SetupAllProperties()
                .CreateObject();

// support to per-property setup (with initial value)
var target = new FluentMock<IFooGetSetProperty>()
                .SetupProperty((foo) => foo.MyIntProperty2, 10)
                .SetupProperty((foo) => foo.MyProperty2, "Elemar")
                .CreateObject();

// support to property set behavior setup
var target = FluentMock.Create<IFooGetSetProperty>()
                .SetupSet((foo) => foo.MyProperty2 = "newValue")
                .Callback(() => callbackWasInvoked = true)
                .CreateObject();

// support to property get behavior setup
var target = FluentMock.Create<IFooGetSetProperty>()

                .SetupGet((foo) => foo.MyProperty2)
                .Callback(() => callbackWasInvoked1 = true)
                .Callback(() => callbackWasInvoked2 = true)

                .SetupGet((foo) => foo.MyIntProperty2)
                .Callback(() => callbackWasInvoked3 = true)

                .CreateObject();

Last edited Aug 29, 2010 at 1:32 PM by elemarjr, version 5