mock

Helper function for creating a Mock object.

mock
(
T
)
()

Examples

interface Foo {
    int foo(int, string) @safe pure;
    void bar() @safe pure;
}

int fun(Foo f) {
    return 2 * f.foo(5, "foobar");
}

auto m = mock!Foo;
m.expect!"foo";
fun(m);
interface Foo {
    int foo(int, string) @safe pure;
    void bar() @safe pure;
}

int fun(Foo f) {
    return 2 * f.foo(5, "foobar");
}

auto m = mock!Foo;
m.expect!"foo"(5, "foobar");
fun(m);
interface Foo {
    int foo(int, string) @safe pure;
    void bar() @safe pure;
}

int fun(Foo f) {
    return 2 * f.foo(5, "foobar");
}

auto m = mock!Foo;
fun(m);
m.expectCalled!"foo"(5, "foobar");
interface Foo {
    int timesN(int i) @safe pure;
}

int fun(Foo f) {
    return f.timesN(3) * 2;
}

auto m = mock!Foo;
m.returnValue!"timesN"(42);
immutable res = fun(m);
assert(res == 84);
interface Foo {
    int timesN(int i) @safe pure;
}

int fun(Foo f) {
    return f.timesN(3) * 2;
}

auto m = mock!Foo;
m.returnValue!"timesN"(42, 12);
assert(fun(m) == 84);
assert(fun(m) == 24);
assert(fun(m) == 0);

Meta