public Spec AnyCachedRequestThatHasNotGotAResponseInTheCacheHandledBeforeTheFirstExceptionCallsTheHandleMethod(IList<Tuple<Request, DescribedAction>> input, Response[] output) { return new Spec( () => { var nonFailedRequests = input .Select(tuple => tuple.First) .Take(GetIndexOfFirstExceptionThrown() + 1) .Where(request => request.GetType().HasAttribute<EnableServiceResponseCachingAttribute>()); var requestTypes = nonFailedRequests .Select(request => request.GetType()) .Distinct(); var requestsThatReturnedACachedResponse = nonFailedRequests .Where(request => State.CacheManager.ReturnedCachedResponseFor(request)); requestTypes.ForEach( type => Ensure.Equal( nonFailedRequests.Count(request => request.GetType() == type) - requestsThatReturnedACachedResponse.Count(request => request.GetType() == type), State.GetHandler(type).HandledRequest)); }) .IfAfter(ExceptionWasThrownAfterTheFirstRequest); }
protected override void When() { using (var requestProcessor = IoC.Container.Resolve<IRequestProcessor>()) { response = requestProcessor.Process(request).SingleOrDefault(); } }
public Type GetRequestTypeFor(Response response) { if (response == null) throw new ArgumentNullException("response"); var responseType = response.GetType(); if (!responseRequestMappings.ContainsKey(responseType)) throw new Exception("No request type found by convention for response type " + responseType); return responseRequestMappings[responseType]; }
/// <summary> /// Called when [process requests completed]. /// </summary> /// <param name="processRequestsAsyncCompletedArgs">The process requests async completed args.</param> /// <param name="responseReciever">The response reciever.</param> /// <param name="tempResponseArray">The temp response array.</param> /// <param name="requestsToSendAsArray">The requests to send as array.</param> public override void OnProcessRequestsCompleted( ProcessRequestsAsyncCompletedArgs processRequestsAsyncCompletedArgs, ResponseReceiver responseReciever, Response[] tempResponseArray, Request[] requestsToSendAsArray ) { base.OnProcessRequestsCompleted ( processRequestsAsyncCompletedArgs, responseReciever, tempResponseArray, requestsToSendAsArray ); var requestEndTime = DateTime.Now; var timespan = requestEndTime - _requestStartTime; var requestString = GetRequestString ( requestsToSendAsArray ); Logger.Debug ( "Response received for the following agatha batch: [{0}]. Elapsed milliseconds ({1})", requestString, timespan.TotalMilliseconds ); }
public Spec AnyNonCachedRequestHandledAfterAndIncludingTheFirstExceptionCallsTheCreateDefaultResponseMethod(IList<Tuple<Request, DescribedAction>> input, Response[] output) { return new Spec( () => { var requestsAfterTheFirstException = input .Select(tuple => tuple.First) .Skip(GetIndexOfFirstExceptionThrown()); var requestTypes = requestsAfterTheFirstException .Select(request => request.GetType()) .Distinct() .Where(type => !type.HasAttribute<EnableServiceResponseCachingAttribute>()); requestTypes.ForEach( type => Ensure.Equal( requestsAfterTheFirstException.Count(request => request.GetType() == type), State.GetHandler(type).DefaultResponseReturned)); }) .IfAfter(ExceptionWasThrownBeforeLastRequest); }
private void SetExceptionType(Response response, Exception exception) { var exceptionType = exception.GetType(); if (exceptionType.Equals(serviceLayerConfiguration.BusinessExceptionType)) { response.ExceptionType = ExceptionType.Business; SetExceptionFaultCode(exception, response.Exception); return; } if (exceptionType.Equals(serviceLayerConfiguration.SecurityExceptionType)) { response.ExceptionType = ExceptionType.Security; SetExceptionFaultCode(exception, response.Exception); return; } response.ExceptionType = ExceptionType.Unknown; }
protected Request GetRequestFor(Response response) { return input.Select(i => i.Item1).ElementAt(output.ToList().IndexOf(response)); }
private Response SetStandardExceptionInfoWhenEarlierRequestsFailed(Response response) { response.ExceptionType = ExceptionType.EarlierRequestAlreadyFailed; response.Exception = new ExceptionInfo(new Exception(ExceptionType.EarlierRequestAlreadyFailed.ToString())); return response; }
protected virtual void AfterHandle(Request request, Response response) { }
public void MarkAsProcessed(Response response) { if (response == null) throw new ArgumentNullException("response"); Response = response; IsProcessed = true; }
/// <summary> /// Stores the specified request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> /// <param name="expiration">The expiration.</param> public void Store(Request request, Response response, TimeSpan expiration) { Cache.Put(BuildKey(request), response, expiration); }
public CacheEntry(Request request, Response response, TimeSpan expiration, string region) { Request = request; Response = response; Expiration = expiration; Region = region; }
protected override void StoreInCache(Request request, Response response, TimeSpan expiration, string region) { cacheEntries.Add(new CacheEntry(request, response, expiration, region)); base.StoreInCache(request, response, expiration, region); }
public Spec CachableRequestsNeverCallTheCreateDefaultResponseMethodImplicitely(IList<Tuple<Request, DescribedAction>> input, Response[] output) { return new Spec( () => input .Where(request => request.GetType().HasAttribute<EnableServiceResponseCachingAttribute>()) .Select(request => request.GetType()) .Distinct() .ForEach(type => Ensure.Equal(0, State.GetHandler(type).DefaultResponseReturned))); }
public override void StoreInCache(Request request, Response response) { if (((RequestBase)request).BypassCache) return; base.StoreInCache(request, response); }