Beispiel #1
0
        public async Task CreatedAtRouteResult_ReturnsStatusCode_SetsLocationHeader(object values)
        {
            // Arrange
            var expectedUrl   = "testAction";
            var httpContext   = GetHttpContext();
            var actionContext = GetActionContext(httpContext);
            var urlHelper     = GetMockUrlHelper(expectedUrl);

            // Act
            var result = new CreatedAtRouteResult(routeName: null, routeValues: values, value: null);

            result.UrlHelper = urlHelper;
            await result.ExecuteResultAsync(actionContext);

            // Assert
            Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
            Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
        }
Beispiel #2
0
        public async Task CreatedAtRouteResult_ThrowsOnNullUrl()
        {
            // Arrange
            var httpContext   = GetHttpContext();
            var actionContext = GetActionContext(httpContext);
            var urlHelper     = GetMockUrlHelper(returnValue: null);

            var result = new CreatedAtRouteResult(
                routeName: null,
                routeValues: new Dictionary <string, object>(),
                value: null);

            result.UrlHelper = urlHelper;

            // Act & Assert
            await ExceptionAssert.ThrowsAsync <InvalidOperationException>(
                async() => await result.ExecuteResultAsync(actionContext),
                "No route matches the supplied values.");
        }