Example #1
0
        public void BuildRoutes_CreatesEightRoutes()
        {
            var routeCollection = new RouteCollection();

            SimplyRestfulRouteHandler.BuildRoutes(routeCollection);
            Assert.That(routeCollection.Count, Is.EqualTo(7));
        }
Example #2
0
        public void BuildRoutes_WhenNullArea_CreatesDefaultRoutes()
        {
            var routeCollection = new RouteCollection();

            SimplyRestfulRouteHandler.BuildRoutes(routeCollection, null);
            foreach (Route route in routeCollection)
            {
                Assert.That(route.Url, Is.StringStarting("{controller}"));
            }
        }
Example #3
0
        public void BuildRoutes_WhenAreaHasLeadingSlash_StripsTheSlash()
        {
            var routeCollection = new RouteCollection();

            SimplyRestfulRouteHandler.BuildRoutes(routeCollection, "/admin");
            foreach (Route route in routeCollection)
            {
                Assert.That(route.Url, Is.StringStarting("admin"));
            }
        }
            public virtual void GetRouteData_WithAControllerAndIdUsingHttpGetWithStringIdValidatorAndANumericId_DoesNotMatch()
            {
                routeCollection = new RouteCollection();
                SimplyRestfulRouteHandler.BuildRoutes(routeCollection, ControllerPath, "[a-zA-Z]+", ControllerName);

                using (mocks.Record())
                {
                    SetupContext("/123", "POST", "DELETE");
                }
                using (mocks.Playback())
                {
                    RouteData routeData = routeCollection.GetRouteData(httpContext);
                    Assert.That(routeData, Is.Null);
                }
            }
Example #5
0
        public void EnsureActionResolver_WhenResolverIsNullAndCannotGetOneFromTheContainer_UsesRestfulActionResolver()
        {
            var           mocks          = new MockRepository();
            var           httpContext    = mocks.DynamicMock <HttpContextBase>();
            IRouteHandler handler        = new SimplyRestfulRouteHandler();
            var           requestContext = new RequestContext(httpContext, new RouteData());

            using (mocks.Record())
            {
                SetupResult.For(httpContext.Request).Return(mocks.DynamicMock <HttpRequestBase>());
            }
            using (mocks.Playback())
            {
                handler.GetHttpHandler(requestContext);
            }
        }
            public virtual void GetRouteData_WithAControllerAndIdUsingHttpGetWithAnyIdValidator_SetsTheShowAction()
            {
                routeCollection = new RouteCollection();
                SimplyRestfulRouteHandler.BuildRoutes(routeCollection, ControllerPath, SimplyRestfulRouteHandler.MatchAny, ControllerName);

                using (mocks.Record())
                {
                    SetupContext("/123", "POST", "DELETE");
                }
                using (mocks.Playback())
                {
                    RouteData routeData = routeCollection.GetRouteData(httpContext);
                    Assert.That(routeData.RouteHandler, Is.TypeOf(typeof(SimplyRestfulRouteHandler)));
                    AssertController(routeData);
                }
            }
Example #7
0
        public void EnsureActionResolver_WhenResolverIsUsedInTheConstructor_UsesRestfulActionResolver()
        {
            var           mocks          = new MockRepository();
            var           httpContext    = mocks.DynamicMock <HttpContextBase>();
            var           resolver       = mocks.StrictMock <IRestfulActionResolver>();
            IRouteHandler handler        = new SimplyRestfulRouteHandler(resolver);
            var           requestContext = new RequestContext(httpContext, new RouteData());

            using (mocks.Record())
            {
                Expect.Call(resolver.ResolveAction(requestContext)).Return(RestfulAction.None);
            }
            using (mocks.Playback())
            {
                handler.GetHttpHandler(requestContext);
            }
        }
Example #8
0
        public void GetHttpHandler_WithARestfulAction_SetsRouteDataAction()
        {
            var           mocks          = new MockRepository();
            var           httpContext    = mocks.DynamicMock <HttpContextBase>();
            var           resolver       = mocks.DynamicMock <IRestfulActionResolver>();
            IRouteHandler handler        = new SimplyRestfulRouteHandler(resolver);
            var           requestContext = new RequestContext(httpContext, new RouteData());

            using (mocks.Record())
            {
                SetupResult.For(resolver.ResolveAction(requestContext)).Return(RestfulAction.Update);
            }
            using (mocks.Playback())
            {
                handler.GetHttpHandler(requestContext);
                Assert.That(requestContext.RouteData.Values["action"], Is.EqualTo("Update").IgnoreCase);
            }
        }
Example #9
0
        public void GetHttpHandler_WithoutARestfulAction_DoesNotSetRouteDataAction()
        {
            var mocks       = new MockRepository();
            var httpContext = mocks.DynamicMock <HttpContextBase>();
            var resolver    = mocks.DynamicMock <IRestfulActionResolver>();

            IRouteHandler handler   = new SimplyRestfulRouteHandler(resolver);
            var           routeData = new RouteData();

            routeData.Values.Add("action", "goose");
            var requestContext = new RequestContext(httpContext, routeData);

            using (mocks.Record())
            {
                SetupResult.For(resolver.ResolveAction(requestContext)).Return(RestfulAction.None);
            }
            using (mocks.Playback())
            {
                handler.GetHttpHandler(requestContext);
                Assert.That(requestContext.RouteData.Values["action"], Is.EqualTo("goose"));
            }
        }
Example #10
0
        public void EnsureActionResolver_WhenResolverIsNull_ResolvesAndUsesOneFromTheContainer()
        {
            var mocks       = new MockRepository();
            var httpContext = mocks.StrictMock <HttpContextBase>();
            var resolver    = mocks.StrictMock <IRestfulActionResolver>();
            var httpRequest = mocks.DynamicMock <HttpRequestBase>();

            IRouteHandler handler        = new SimplyRestfulRouteHandler();
            var           requestContext = new RequestContext(httpContext, new RouteData());

            using (mocks.Record())
            {
                /// Context has to be a mock b/c we want to assert that GetService is called.
                httpContext.Expect(c => c.Request).Repeat.Any().Return(httpRequest);
                httpContext.Expect(c => c.GetService(typeof(IRestfulActionResolver))).Return(resolver).Repeat.Once();

                /// Resolver has to be a mock b/c we want to assert that it was gotten from the container and actually used.
                resolver.Expect(r => r.ResolveAction(requestContext)).Return(RestfulAction.None);
            }
            using (mocks.Playback())
            {
                handler.GetHttpHandler(requestContext);
            }
        }
 protected virtual void BuildRoutes(RouteCollection routes)
 {
     SimplyRestfulRouteHandler.BuildRoutes(routes, ControllerPath, SimplyRestfulRouteHandler.MatchPositiveInteger, ControllerName);
 }