Example #1
0
        public void ServiceFunctions_InvokeService_ThrowsOnNullNextFunction()
        {
            // Arrange
            HttpContext context          = new TestHttpContext();
            Func <Task> nullNextFunction = null;

            // Act
            ServiceFunctions.InvokeService(context, nullNextFunction).Wait();
        }
Example #2
0
        public void ServiceFunctions_InvokeService_ThrowsOnNullContext()
        {
            // Arrange
            HttpContext nullContext = null;

            Task next() => Task.CompletedTask;

            // Act
            ServiceFunctions.InvokeService(nullContext, next).Wait();
        }
Example #3
0
        // Invokes a service and returns the HTTP status code result.
        //
        // Do not use this to test the ServiceFunctions.InvokeService method.
        // This was designed to help other tests and assumes that the
        // ServiceFunctions.InvokeService has already been tested.
        private static int InvokeService(string method, string path, string bodyString = "")
        {
            var request = new TestHttpRequest()
            {
                Method     = method,
                Path       = path,
                BodyString = bodyString
            };
            var response = new TestHttpResponse();
            var context  = new TestHttpContext(request, response);

            Task next() => Task.CompletedTask;

            ServiceFunctions.InvokeService(context, next).Wait();

            return(response.StatusCode);
        }
Example #4
0
        public void ServiceFunctions_InvokeService_ReturnsNotFound()
        {
            // Arrange
            var request = new TestHttpRequest()
            {
                Method     = "PUT",
                Path       = "/api/things/fc845a74-973e-4db9-8951-5c99e7cf009c",
                BodyString = string.Empty
            };
            var response = new TestHttpResponse();
            var context  = new TestHttpContext(request, response);

            Task next() => Task.CompletedTask;

            // Act
            ServiceFunctions.InvokeService(context, next).Wait();

            // Assert
            Assert.AreEqual(404, response.StatusCode);
        }
Example #5
0
        public void ServiceFunctions_InvokeService_InvokesAService()
        {
            // Arrange
            AddService("GET", "/api/things/8bd5c2be-5b8b-4e8d-97bb-cbb9ac8c5066");

            var request = new TestHttpRequest()
            {
                Method     = "GET",
                Path       = "/api/things/8bd5c2be-5b8b-4e8d-97bb-cbb9ac8c5066",
                BodyString = string.Empty
            };
            var response = new TestHttpResponse();
            var context  = new TestHttpContext(request, response);

            Task next() => Task.CompletedTask;

            // Act
            ServiceFunctions.InvokeService(context, next).Wait();

            // Assert
            Assert.AreEqual(200, response.StatusCode);
            Assert.AreEqual("application/json", response.ContentType);
            Assert.AreEqual(@"{""color"":""Red""}", response.ReadBody());
        }