ProcessRequest() public method

Processes an incoming HTTP request.
is null.
public ProcessRequest ( IStumpsHttpContext context ) : Task
context IStumpsHttpContext The representing both the incoming request and the response.
return Task
        public void ProcessRequest_WithNullContext_ThrowsException()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http404NotFound);

            Assert.That(
                async () => await handler.ProcessRequest(null),
                Throws.Exception.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("context"));
        }
Esempio n. 2
0
        public void ProcessRequest_WithNullContext_ThrowsException()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http404NotFound);

            Assert.That(
                async() => await handler.ProcessRequest(null),
                Throws.Exception.TypeOf <ArgumentNullException>().With.Property("ParamName").EqualTo("context"));
        }
Esempio n. 3
0
        public async Task ProcessRequest_With503Fallback_Returns503()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http503ServiceUnavailable);
            var context = new MockHttpContext();
            await handler.ProcessRequest(context);

            Assert.AreEqual(503, context.Response.StatusCode);
            Assert.AreEqual(HttpStatusCodes.GetStatusDescription(503), context.Response.StatusDescription);
        }
Esempio n. 4
0
        public async Task ProcessRequest_With404Fallback_Returns404()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http404NotFound);
            var context = new MockHttpContext();
            await handler.ProcessRequest(context);

            Assert.AreEqual(404, context.Response.StatusCode);
            Assert.AreEqual(HttpStatusCodes.GetStatusDescription(404), context.Response.StatusDescription);
        }
        public void ProcessRequest_With503Fallback_Returns503()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http503ServiceUnavailable);
            var context = new MockHttpContext();
            handler.ProcessRequest(context);

            Assert.AreEqual(503, context.Response.StatusCode);
            Assert.AreEqual(HttpStatusCodes.GetStatusDescription(503), context.Response.StatusDescription);
        }
        public void ProcessRequest_With404Fallback_Returns404()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http404NotFound);
            var context = new MockHttpContext();
            handler.ProcessRequest(context);

            Assert.AreEqual(404, context.Response.StatusCode);
            Assert.AreEqual(HttpStatusCodes.GetStatusDescription(404), context.Response.StatusDescription);
        }
Esempio n. 7
0
        public async Task ProcessRequest_WithStumpsHttpResponse_PopulatesOrigin()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http503ServiceUnavailable);

            var response = new StumpsHttpResponse();
            var context  = new MockHttpContext(null, response);

            await handler.ProcessRequest(context);

            Assert.AreEqual(response.Origin, HttpResponseOrigin.ServiceUnavailable);
        }
        public void ProcessRequest_WithPopulatedResponse_ClearsHeadersAndBody()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http503ServiceUnavailable);
            var context = new MockHttpContext();
            context.Response.AppendToBody(new byte[100]);
            context.Response.Headers["ABCD"] = "123";
            handler.ProcessRequest(context);

            Assert.AreEqual(0, context.Response.Headers.Count);
            Assert.AreEqual(0, context.Response.BodyLength);
        }
Esempio n. 9
0
        public async Task ProcessRequest_WithPopulatedResponse_ClearsHeadersAndBody()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http503ServiceUnavailable);
            var context = new MockHttpContext();

            context.Response.AppendToBody(new byte[100]);
            context.Response.Headers["ABCD"] = "123";
            await handler.ProcessRequest(context);

            Assert.AreEqual(0, context.Response.Headers.Count);
            Assert.AreEqual(0, context.Response.BodyLength);
        }
        public void ProcessRequest_WithStumpsHttpResponse_PopulatesOrigin()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http503ServiceUnavailable);

            var hitCount = 0;
            handler.ContextProcessed += (o, e) => hitCount++;

            var response = new StumpsHttpResponse();
            var context = new MockHttpContext(null, response);

            handler.ProcessRequest(context);
            Assert.AreEqual(response.Origin, HttpResponseOrigin.ServiceUnavailable);
        }
Esempio n. 11
0
        public async Task ProcessRequest_WithValidContext_RaisesContextProcessedEvent()
        {
            var resetEvent = new AutoResetEvent(false);

            var handler = new FallbackResponseHandler(FallbackResponse.Http503ServiceUnavailable);

            handler.ContextProcessed += (o, e) => resetEvent.Set();

            var context = new MockHttpContext();

            await handler.ProcessRequest(context);

            var eventRaised = resetEvent.WaitOne(1000);

            Assert.IsTrue(eventRaised);
        }
        public void ProcessRequest_WithValidContext_RaisesContextProcessedEvent()
        {
            var handler = new FallbackResponseHandler(FallbackResponse.Http503ServiceUnavailable);

            var hitCount = 0;
            handler.ContextProcessed += (o, e) => hitCount++;

            var context = new MockHttpContext();

            handler.ProcessRequest(context);
            Assert.AreEqual(1, hitCount);
        }