Example #1
0
        public void ServiceFunctions_QueryService_ReturnsServiceStats()
        {
            // Arrange
            var serviceId = AddService("GET", "/api/serviceToBeQueried/1");

            InvokeService("GET", "/api/serviceToBeQueried/1", "Lorem ipsum dolor");
            InvokeService("GET", "/api/serviceToBeQueried/1", "sit amet, consectetur adipiscing");

            var request = new TestHttpRequest()
            {
                Method = "GET",
                Path   = "/__vs/services/" + serviceId
            };
            var response = new TestHttpResponse();
            var context  = new TestHttpContext(request, response);

            Task next() => Task.CompletedTask;

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

            // Assert
            Assert.AreEqual(200, response.StatusCode);
            Assert.AreEqual("text/plain", response.ContentType);
            var expectedResponseBody = new StringBuilder()
                                       .AppendLine($"CallCount: 2")
                                       .AppendLine()
                                       .AppendLine("LastRequestBody:")
                                       .Append("sit amet, consectetur adipiscing")
                                       .ToString();

            Assert.AreEqual(expectedResponseBody, response.ReadBody());
        }
Example #2
0
        public void ServiceFunctions_QueryService_ThrowsOnNullNextFunction()
        {
            // Arrange
            HttpContext context          = new TestHttpContext();
            Func <Task> nullNextFunction = null;

            // Act
            ServiceFunctions.QueryService(context, nullNextFunction).Wait();
        }
Example #3
0
        public void ServiceFunctions_QueryService_ThrowsOnNullContext()
        {
            // Arrange
            HttpContext nullContext = null;

            Task next() => Task.CompletedTask;

            // Act
            ServiceFunctions.QueryService(nullContext, next).Wait();
        }
Example #4
0
        public void ServiceFunctions_QueryService_Returns404WhenServiceDoesNotExist()
        {
            // Arrange
            var request = new TestHttpRequest()
            {
                Method = "GET",
                Path   = "/__vs/services/" + Guid.NewGuid().ToString()
            };
            var response = new TestHttpResponse();
            var context  = new TestHttpContext(request, response);

            Task next() => Task.CompletedTask;

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

            // Assert
            Assert.AreEqual(404, response.StatusCode);
        }