public void ApiControllerRedirectToRoute_WithStringAndObject_CreatesCorrectResult()
        {
            // Arrange
            string        expectedRouteName = CreateRouteName();
            object        routeValues       = new { id = 1 };
            ApiController controller        = CreateController();

            // Act
            RedirectToRouteResult result = controller.RedirectToRoute(expectedRouteName, routeValues);

            // Assert
            Assert.NotNull(result);
            Assert.Same(expectedRouteName, result.RouteName);
            Assert.IsType <HttpRouteValueDictionary>(result.RouteValues);
            Assert.True(result.RouteValues.ContainsKey("id"));
            Assert.Equal(1, result.RouteValues["id"]);

            using (HttpRequestMessage expectedRequest = CreateRequest())
            {
                controller.Request = expectedRequest;
                Assert.Same(expectedRequest, result.Request);
            }
        }
        public void RouteName_Returns_InstanceProvided()
        {
            // Arrange
            string expectedRouteName = CreateRouteName();
            IDictionary <string, object> routeValues = CreateRouteValues();
            UrlHelper urlFactory = CreateDummyUrlFactory();

            using (HttpRequestMessage request = CreateRequest())
            {
                RedirectToRouteResult result = CreateProductUnderTest(
                    expectedRouteName,
                    routeValues,
                    urlFactory,
                    request
                    );

                // Act
                string routeName = result.RouteName;

                // Assert
                Assert.Same(expectedRouteName, routeName);
            }
        }
        public void Request_ForApiController_EvaluatesLazily()
        {
            // Arrange
            string routeName = CreateRouteName();
            IDictionary <string, object> routeValues = CreateRouteValues();
            ApiController         controller         = CreateController();
            RedirectToRouteResult result             = CreateProductUnderTest(
                routeName,
                routeValues,
                controller
                );

            using (HttpRequestMessage expectedRequest = CreateRequest())
            {
                controller.Request = expectedRequest;

                // Act
                HttpRequestMessage request = result.Request;

                // Assert
                Assert.Same(expectedRequest, request);
            }
        }
        public void UrlFactory_ForApiController_EvaluatesLazily()
        {
            // Arrange
            string routeName = CreateRouteName();
            IDictionary <string, object> routeValues = CreateRouteValues();
            ApiController controller = CreateController();

            using (HttpRequestMessage request = CreateRequest())
            {
                controller.Request = request;
                controller.Url     = CreateDummyUrlFactory();

                RedirectToRouteResult result = CreateProductUnderTest(routeName, routeValues, controller);

                UrlHelper expectedUrlFactory = CreateDummyUrlFactory();
                controller.Url = expectedUrlFactory;

                // Act
                UrlHelper urlFactory = result.UrlFactory;

                // Assert
                Assert.Same(expectedUrlFactory, urlFactory);
            }
        }
        public void ApiControllerRedirectToRoute_WithStringAndDictionary_CreatesCorrectResult()
        {
            // Arrange
            string expectedRouteName = CreateRouteName();
            IDictionary <string, object> expectedRouteValues = CreateRouteValues();
            ApiController controller = CreateController();

            // Act
            RedirectToRouteResult result = controller.RedirectToRoute(
                expectedRouteName,
                expectedRouteValues
                );

            // Assert
            Assert.NotNull(result);
            Assert.Same(expectedRouteName, result.RouteName);
            Assert.Same(expectedRouteValues, result.RouteValues);

            using (HttpRequestMessage expectedRequest = CreateRequest())
            {
                controller.Request = expectedRequest;
                Assert.Same(expectedRequest, result.Request);
            }
        }
        public void Request_ForApiController_Throws_WhenControllerRequestIsNull()
        {
            // Arrange
            string routeName = CreateRouteName();
            IDictionary <string, object> routeValues = CreateRouteValues();
            ApiController controller = CreateController();

            Assert.Null(controller.Request);

            RedirectToRouteResult result = CreateProductUnderTest(
                routeName,
                routeValues,
                controller
                );

            // Act & Assert
            InvalidOperationException exception = Assert.Throws <InvalidOperationException>(
                () =>
            {
                HttpRequestMessage ignore = result.Request;
            },
                "ApiController.Request must not be null."
                );
        }