1 module dmocks.factory; 2 3 import dmocks.object_mock; 4 import dmocks.repository; 5 import std.typecons; 6 7 package: 8 9 /** Get a mock object of the given type. */ 10 T mock (T, CONSTRUCTOR_ARGS...) (MockRepository rep, CONSTRUCTOR_ARGS cargs) 11 { 12 Mocked!(T) ret = new Mocked!(T)(cargs); 13 ret._owner = rep; 14 return cast(T)ret; 15 } 16 17 MockedFinal!(T) mockFinal (T, CONSTRUCTOR_ARGS...) (MockRepository rep, CONSTRUCTOR_ARGS t) 18 { 19 static if (__traits(isFinalClass, T)) 20 T obj = new T(t); 21 else 22 T obj = new WhiteHole!T(t); 23 MockedFinal!(T) ret = new MockedFinal!(T)(obj); 24 ret._owner = rep; 25 return ret; 26 } 27 28 MockedFinal!(T) mockFinalPassTo (T, CONSTRUCTOR_ARGS...) (MockRepository rep, T obj) 29 { 30 MockedFinal!(T) ret = new MockedFinal!(T)(obj); 31 ret._owner = rep; 32 return ret; 33 } 34 35 MockedStruct!(T) mockStruct (T, CONSTRUCTOR_ARGS...) (MockRepository rep, CONSTRUCTOR_ARGS t) 36 { 37 MockedStruct!(T) ret = MockedStruct!(T)(T(t)); 38 ret._owner = rep; 39 return ret; 40 } 41 42 MockedStruct!(T) mockStructPassTo (T, CONSTRUCTOR_ARGS...) (MockRepository rep, T obj) 43 { 44 MockedStruct!(T) ret = MockedStruct!(T)(obj); 45 ret._owner = rep; 46 return ret; 47 }