Ejemplo n.º 1
0
        public void CreateControllerWithFactoryThatThrowsDoesNothingSpecial()
        {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();

            cb.SetControllerFactory(typeof(ControllerFactoryThrows));

            // Act
            Assert.Throws <Exception>(
                delegate
            {
                RequestContext reqContext = new RequestContext(
                    new Mock <HttpContextBase>().Object,
                    new RouteData()
                    );
                reqContext.RouteData.Values["controller"] = "foo";
                MvcHandlerWithNoVersionHeader handler     = new MvcHandlerWithNoVersionHeader(
                    reqContext
                    )
                {
                    ControllerBuilder = cb
                };
                handler.ProcessRequest(reqContext.HttpContext);
            },
                "ControllerFactoryThrows"
                );
        }
Ejemplo n.º 2
0
        public void CreateControllerWithFactoryThatReturnsNullThrows()
        {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();

            cb.SetControllerFactory(typeof(ControllerFactoryReturnsNull));

            // Act
            Assert.Throws <InvalidOperationException>(
                delegate
            {
                RequestContext reqContext = new RequestContext(
                    new Mock <HttpContextBase>().Object,
                    new RouteData()
                    );
                reqContext.RouteData.Values["controller"] = "boo";
                MvcHandlerWithNoVersionHeader handler     = new MvcHandlerWithNoVersionHeader(
                    reqContext
                    )
                {
                    ControllerBuilder = cb
                };
                handler.ProcessRequest(reqContext.HttpContext);
            },
                "The IControllerFactory 'System.Web.Mvc.Test.ControllerBuilderTest+ControllerFactoryReturnsNull' did not return a controller for the name 'boo'."
                );
        }
Ejemplo n.º 3
0
        public void CreateControllerWithFactoryThatCannotBeCreatedThrows()
        {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();

            cb.SetControllerFactory(typeof(ControllerFactoryThrowsFromConstructor));

            // Act
            Assert.Throws <InvalidOperationException>(
                delegate
            {
                RequestContext reqContext = new RequestContext(
                    new Mock <HttpContextBase>().Object,
                    new RouteData()
                    );
                reqContext.RouteData.Values["controller"] = "foo";
                MvcHandlerWithNoVersionHeader handler     = new MvcHandlerWithNoVersionHeader(
                    reqContext
                    )
                {
                    ControllerBuilder = cb
                };
                handler.ProcessRequest(reqContext.HttpContext);
            },
                "An error occurred when trying to create the IControllerFactory 'System.Web.Mvc.Test.ControllerBuilderTest+ControllerFactoryThrowsFromConstructor'. Make sure that the controller factory has a public parameterless constructor."
                );
        }
Ejemplo n.º 4
0
        public void CreateControllerWithFactoryThatThrowsDoesNothingSpecial() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();
            cb.SetControllerFactory(typeof(ControllerFactoryThrows));

            // Act
            ExceptionHelper.ExpectException<Exception>(
                delegate {
                    RequestContext reqContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
                    reqContext.RouteData.Values["controller"] = "foo";
                    MvcHandlerWithNoVersionHeader handler = new MvcHandlerWithNoVersionHeader(reqContext) {
                        ControllerBuilder = cb
                    };
                    handler.ProcessRequest(reqContext.HttpContext);
                },
                "ControllerFactoryThrows");
        }
Ejemplo n.º 5
0
        public void CreateControllerWithFactoryThatReturnsNullThrows() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();
            cb.SetControllerFactory(typeof(ControllerFactoryReturnsNull));

            // Act
            ExceptionHelper.ExpectException<InvalidOperationException>(
                delegate {
                    RequestContext reqContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
                    reqContext.RouteData.Values["controller"] = "boo";
                    MvcHandlerWithNoVersionHeader handler = new MvcHandlerWithNoVersionHeader(reqContext) {
                        ControllerBuilder = cb
                    };
                    handler.ProcessRequest(reqContext.HttpContext);
                },
                "The IControllerFactory 'System.Web.Mvc.Test.ControllerBuilderTest+ControllerFactoryReturnsNull' did not return a controller for the name 'boo'.");
        }
Ejemplo n.º 6
0
        public void CreateControllerWithFactoryThatCannotBeCreatedThrows() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();
            cb.SetControllerFactory(typeof(ControllerFactoryThrowsFromConstructor));

            // Act
            ExceptionHelper.ExpectException<InvalidOperationException>(
                delegate {
                    RequestContext reqContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
                    reqContext.RouteData.Values["controller"] = "foo";
                    MvcHandlerWithNoVersionHeader handler = new MvcHandlerWithNoVersionHeader(reqContext) {
                        ControllerBuilder = cb
                    };
                    handler.ProcessRequest(reqContext.HttpContext);
                },
                "An error occurred when trying to create the IControllerFactory 'System.Web.Mvc.Test.ControllerBuilderTest+ControllerFactoryThrowsFromConstructor'. Make sure that the controller factory has a public parameterless constructor.");
        }