public void HandleCall(MockingProxy proxy, MockableCall call) { using (new RecorderManager.Lock()) { call.SetResult(InvokeOnServer(proxy, call)); RecorderManager.RecordCall(call); } }
/// <summary> /// Creates a mocked instance for the given serverType. /// </summary> /// <param name="serverType">The type for which to create an instance. /// Should be the type decorated by this attribute.</param> protected virtual MarshalByRefObject CreateMockedInstance(Type serverType) { IMocker customMocker; // Retrieve customMockerType from name: if (this.customMockerType == null) { this.customMockerType = Type.GetType(customMockerTypeName); } // Check customMockerType exists: if (this.customMockerType == null) { throw new TypeLoadException(String.Format("The typename \"{0}\" configured as mocker on a CustomMockAttribute could not be resolved.", this.customMockerTypeName)); } // Create custom mocker: customMocker = (IMocker)customMockerType.GetConstructor(new Type[] {}).Invoke(new object[] {}); // Create proxy, return transparent proxy: RealProxy rp; if (RecorderManager.IsRecording) { rp = new MockingProxy(serverType, customMocker, RecorderManager.GetNextInstanceName(serverType)); } else { rp = new MockingProxy(serverType, customMocker, null); } return((MarshalByRefObject)rp.GetTransparentProxy()); }
public void Dispose() { if (validating) { RecorderManager.ValidatePlayBack(); } RecorderManager.EndPlayBack(); }
/// <summary> /// Creates an eventually mocked instance for the given serverType. /// </summary> /// <param name="serverType">The type for which to create an instance. /// Should be the type decorated by this attribute.</param> protected override MarshalByRefObject CreateMockedInstance(Type serverType) { RealProxy rp; switch (RecorderManager.Action) { case RecorderState.Recording: // Create a recording proxy for the object: MarshalByRefObject target = CreateUnmockedInstance(serverType); rp = new MockingProxy(serverType, new RecordingMocker(target), RecorderManager.GetNextInstanceName(serverType)); return((MarshalByRefObject)rp.GetTransparentProxy()); case RecorderState.PlayBack: // Create a playback proxy: rp = new MockingProxy(serverType, new PlayBackMocker(), null); return((MarshalByRefObject)rp.GetTransparentProxy()); default: // Create an instance without proxy: return(CreateUnmockedInstance(serverType)); } }
public void Dispose() { RecorderManager.EndRecording(); }
public RecordingSession(string recordingName) { RecorderManager.BeginRecording(recordingName); }
public PlaybackSession(string recordingName, bool validating) { this.validating = validating; RecorderManager.BeginPlayBack(recordingName); }
/// <summary> /// If the passed value is serializable, returns it as is, otherwise wraps it in a recording proxy. /// </summary> private static object WrapObject(object value, Type expectedType) { if (value == null) { // Leave result as is return(null); } else if (RemotingServices.IsObjectOutOfAppDomain(value)) { // Wrap the result in a RecordingProxy on the method's returntype: return(new MockingProxy(expectedType, new RecordingMocker((MarshalByRefObject)value), RecorderManager.GetNextInstanceName(expectedType)).GetTransparentProxy()); } else if (value.GetType().IsMarshalByRef) { // Wrap the result in a RecordingProxy on the objects real type: return(new MockingProxy(value.GetType(), new RecordingMocker((MarshalByRefObject)value), RecorderManager.GetNextInstanceName(value.GetType())).GetTransparentProxy()); } else if (value.GetType().IsSerializable) { // Leave result as is return(value); } else { // When result is neither serializable, nor MarchalByRef, throw: throw new TypeMockException(value.GetType()); } }