Mockable.Mock

Injected by the Mockable mixin template this class contains all mocking behaviour.

This Mock class extends any class it's injected into and provides methods to interact with the mocked instance. An instance of this class can dynamically replace any of its methods at runtime using the 'mockMethod' method. All mocked methods can optionally have their call counts asserted to be within set limits.

Members

Functions

assertMethodCalls
void assertMethodCalls(string message = "Failed asserting call count", string file = __FILE__, size_t line = __LINE__)

Assert all replaced methods are called the defined amount of times.

disableParentMethods
void disableParentMethods(string file = __FILE__, size_t line = __LINE__)

Disable parent methods being called if mock replacements are not implemented. If parent methods have been disabled a helpful assert error will be raised on any attempt to call methods that haven't been replaced. This is helpful if it's necessary to disable all behaviour of the mocked class.

mockMethod
void mockMethod(string name, T delegate_, ulong minimumCount = 0, ulong maximumCount = ulong.max, string file = __FILE__, size_t line = __LINE__)

Replace a method in the mock object by adding a mock method to be called in its place. By default parent methods are called in lieu of any replacements unless parent methods are disabled.

Meta