Beispiel #1
0
 void MockPlug.IMockInvokee.Invoke(Plug plug, string verb, XUri uri, DreamMessage request, Result <DreamMessage> response)
 {
     lock (this) {
         if (_failed)
         {
             _log.DebugFormat("we've already failed, no point checking more expectations");
             response.Return(DreamMessage.InternalError());
             return;
         }
         _log.DebugFormat("{0}={1}", verb, uri);
         XDoc requestDoc = request.HasDocument ? request.ToDocument() : null;
         if (_expectations.Count == _current)
         {
             _log.DebugFormat("excess");
             ExcessInterception excess = new ExcessInterception();
             _excess.Add(excess);
             ;
             response.Return(excess.Call(verb, uri, requestDoc));
             return;
         }
         AutoMockInvokeExpectation expectation = _expectations[_current];
         expectation.Call(verb, uri, request);
         if (!expectation.Verify())
         {
             AddFailure(_expectations[_current].VerificationFailure);
             _log.DebugFormat("got failure, setting reset event ({0})", _current);
             _failed = true;
             _resetEvent.Set();
             response.Return(DreamMessage.BadRequest("expectation failure"));
             return;
         }
         _current++;
         _log.DebugFormat("expected");
         if (_expectations.Count == _current)
         {
             _log.DebugFormat("setting reset event");
             _resetEvent.Set();
         }
         response.Return(expectation.GetResponse());
     }
 }
Beispiel #2
0
 private void Invoke(Dream.Plug plug, string verb, XUri uri, DreamMessage request, Result<DreamMessage> response)
 {
     lock(this) {
         if(_failed) {
             _log.DebugFormat("we've already failed, no point checking more expectations");
             response.Return(DreamMessage.InternalError());
             return;
         }
         _log.DebugFormat("{0}={1}", verb, uri);
         XDoc requestDoc = request.HasDocument ? request.ToDocument() : null;
         if(_expectations.Count == _current) {
             _log.DebugFormat("excess");
             ExcessInterception excess = new ExcessInterception();
             _excess.Add(excess);
             ;
             response.Return(excess.Call(verb, uri, requestDoc));
             return;
         }
         AutoMockInvokeExpectation expectation = _expectations[_current];
         expectation.Call(verb, uri, request);
         if(!expectation.Verify()) {
             AddFailure(_expectations[_current].VerificationFailure);
             _log.DebugFormat("got failure, setting reset event ({0})", _current);
             _failed = true;
             _resetEvent.Set();
             response.Return(DreamMessage.BadRequest("expectation failure"));
             return;
         }
         _current++;
         _log.DebugFormat("expected");
         if(_expectations.Count == _current) {
             _log.DebugFormat("setting reset event");
             _resetEvent.Set();
         }
         response.Return(expectation.GetResponse());
     }
 }