private static Func <MockHttpRequest, HttpResponseMessage> Create(
            string content, string requestId, string s3ExtendedRequestId, bool isOK)
        {
            var status = isOK ? HttpStatusCode.OK : HttpStatusCode.NotFound;

            return((request) =>
            {
                Dictionary <string, string> headers = new Dictionary <string, string>(StringComparer.Ordinal);
                if (!string.IsNullOrEmpty(requestId))
                {
                    headers.Add(HeaderKeys.RequestIdHeader, requestId);
                }

                // https://aws.amazon.com/premiumsupport/knowledge-center/s3-request-id-values/
                if (!string.IsNullOrEmpty(s3ExtendedRequestId))
                {
                    headers.Add(HeaderKeys.XAmzId2Header, s3ExtendedRequestId);
                }

                var response = MockWebResponse.Create(status, headers, content);

                if (isOK)
                {
                    return response;
                }

                throw new HttpErrorResponseException(CustomWebResponse.GenerateWebResponse(response));
            });
        }
Beispiel #2
0
        public Task <IWebResponseData> GetResponseAsync(CancellationToken cancellationToken)
        {
            if (this.GetResponseAction != null)
            {
                this.GetResponseAction();
            }
            var response = ResponseCreator(this);

            return(Task.FromResult <IWebResponseData>(CustomWebResponse.GenerateWebResponse(response)));
        }
Beispiel #3
0
        public IWebResponseData GetResponse()
        {
            if (this.GetResponseAction != null)
            {
                this.GetResponseAction();
            }
            var response = ResponseCreator(this);

            return(CustomWebResponse.GenerateWebResponse(response));
        }
Beispiel #4
0
        private HttpResponseMessage CreateResponse(MockHttpRequest request)
        {
            // Extract the last segment of the URI, this is the custom URI
            // sent by the unit tests.
            var resourceName = request.RequestUri.Host.Split('.').Last();
            var response     = MockWebResponse.CreateFromResource(resourceName);

            if (response.StatusCode >= HttpStatusCode.OK && response.StatusCode <= (HttpStatusCode)299)
            {
                return(response);
            }
            else
            {
                throw new HttpErrorResponseException(CustomWebResponse.GenerateWebResponse(response));
            }
        }
        private static Func <MockHttpRequest, HttpResponseMessage> Create(
            string content, string requestId, bool isOK)
        {
            var status = isOK ? HttpStatusCode.OK : HttpStatusCode.NotFound;

            return((request) =>
            {
                Dictionary <string, string> headers = new Dictionary <string, string>(StringComparer.Ordinal);
                if (!string.IsNullOrEmpty(requestId))
                {
                    headers.Add(HeaderKeys.RequestIdHeader, requestId);
                }
                var response = MockWebResponse.Create(status, headers, content);

                if (isOK)
                {
                    return response;
                }

                throw new HttpErrorResponseException(CustomWebResponse.GenerateWebResponse(response));
            });
        }