示例#1
0
 public void HandleCall(MockingProxy proxy, MockableCall call)
 {
     using (new RecorderManager.Lock()) {
         call.SetResult(InvokeOnServer(proxy, call));
         RecorderManager.RecordCall(call);
     }
 }
示例#2
0
        /// <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());
        }
示例#3
0
 public void Dispose()
 {
     if (validating)
     {
         RecorderManager.ValidatePlayBack();
     }
     RecorderManager.EndPlayBack();
 }
示例#4
0
        /// <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));
            }
        }
示例#5
0
 public void Dispose()
 {
     RecorderManager.EndRecording();
 }
示例#6
0
 public RecordingSession(string recordingName)
 {
     RecorderManager.BeginRecording(recordingName);
 }
示例#7
0
 public PlaybackSession(string recordingName, bool validating)
 {
     this.validating = validating;
     RecorderManager.BeginPlayBack(recordingName);
 }
示例#8
0
 /// <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());
     }
 }