public async Task CreatedAtActionResult_ThrowsOnNullUrl()
        {
            // Arrange
            var httpContext   = GetHttpContext();
            var actionContext = GetActionContext(httpContext);
            var urlHelper     = GetMockUrlHelper(returnValue: null);

            var result = new CreatedAtActionResult(
                actionName: null,
                controllerName: null,
                routeValues: null,
                value: null);

            result.UrlHelper = urlHelper;

            // Act & Assert
            await ExceptionAssert.ThrowsAsync <InvalidOperationException>(
                async() => await result.ExecuteResultAsync(actionContext),
                "No route matches the supplied values.");
        }
        public async Task CreatedAtActionResult_ThrowsOnNullUrl()
        {
            // Arrange
            var httpContext = GetHttpContext();
            var actionContext = GetActionContext(httpContext);
            var urlHelper = GetMockUrlHelper(returnValue: null);

            var result = new CreatedAtActionResult(
                actionName: null,
                controllerName: null,
                routeValues: null,
                value: null);

            result.UrlHelper = urlHelper;

            // Act & Assert
            await ExceptionAssert.ThrowsAsync<InvalidOperationException>(
                async () => await result.ExecuteResultAsync(actionContext),
            "No route matches the supplied values.");
        }
        public async Task CreatedAtActionResult_ReturnsStatusCode_SetsLocationHeader()
        {
            // Arrange
            var expectedUrl   = "testAction";
            var httpContext   = GetHttpContext();
            var actionContext = GetActionContext(httpContext);
            var urlHelper     = GetMockUrlHelper(expectedUrl);

            // Act
            var result = new CreatedAtActionResult(
                actionName: expectedUrl,
                controllerName: null,
                routeValues: null,
                value: null);

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

            // Assert
            Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
            Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
        }
        public async Task CreatedAtActionResult_ReturnsStatusCode_SetsLocationHeader()
        {
            // Arrange
            var expectedUrl = "testAction";
            var httpContext = GetHttpContext();
            var actionContext = GetActionContext(httpContext);
            var urlHelper = GetMockUrlHelper(expectedUrl);

            // Act
            var result = new CreatedAtActionResult(
                actionName: expectedUrl,
                controllerName: null,
                routeValues: null,
                value: null);

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

            // Assert
            Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
            Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
        }