Esempio n. 1
0
		public void GetsRoutesFromRouteFetcher()
		{
			var routes = new[]
			{
				new RouteInfo
				{
					Constraints = new Dictionary<string, object> {{"constr", "aint"}},
					Defaults = new Dictionary<string, object>
					{
						{"controller", "Foo"},
						{"action", "Bar"}
					},
					Optional = new[] {"id"},
					Url = "foo/bar",
				},
			};
			var routeFetcher = new Mock<IRouteFetcher>();
			routeFetcher.Setup(x => x.GetRoutes(It.IsAny<RouteData>())).Returns(routes);

			var request = new Mock<HttpRequest>();
			request.Setup(x => x.PathBase).Returns(new PathString("/base"));
			var httpContext = new Mock<HttpContext>();
			httpContext.Setup(x => x.Request).Returns(request.Object);
			var actionContext = new Mock<IActionContextAccessor>();
			actionContext.Setup(x => x.ActionContext).Returns(new ActionContext
			{
				HttpContext = httpContext.Object
			});
			var config = new Mock<IRouteJsConfiguration>();

			var routeJs = new RouteJs(new[] { routeFetcher.Object }, actionContext.Object, Enumerable.Empty<IRouteFilter>(), config.Object);
			var result = routeJs.GetJsonData();
			const string expected = @"{""routes"":[{""url"":""foo/bar"",""defaults"":{""controller"":""Foo"",""action"":""Bar""},""constraints"":{""constr"":""aint""},""optional"":[""id""]}],""baseUrl"":""/base"",""lowerCaseUrls"":false}";
			Assert.Equal(expected, result);
		}
Esempio n. 2
0
        public void InsertsSlashAtTheBeginningOfBaseUrl()
        {
            var routes = new[]
            {
                new RouteInfo
                {
                    Constraints = new Dictionary <string, object> {
                        { "constr", "aint" }
                    },
                    Defaults = new Dictionary <string, object>
                    {
                        { "controller", "Foo" },
                        { "action", "Bar" }
                    },
                    Optional = new[] { "id" },
                    Url      = "foo/bar",
                },
            };
            var routeFetcher = new Mock <IRouteFetcher>();

            routeFetcher.Setup(x => x.GetRoutes(It.IsAny <RouteData>())).Returns(routes);

            var request = new Mock <HttpRequest>();

            request.Setup(x => x.PathBase).Returns(new PathString(""));
            var httpContext = new Mock <HttpContext>();

            httpContext.Setup(x => x.Request).Returns(request.Object);
            var actionContext = new Mock <IActionContextAccessor>();

            actionContext.Setup(x => x.ActionContext).Returns(new ActionContext
            {
                HttpContext = httpContext.Object
            });
            var config = new Mock <IRouteJsConfiguration>();

            var          routeJs  = new RouteJs(new[] { routeFetcher.Object }, actionContext.Object, Enumerable.Empty <IRouteFilter>(), config.Object);
            var          result   = routeJs.GetJsonData();
            dynamic      json     = JsonConvert.DeserializeObject <ExpandoObject>(result, new ExpandoObjectConverter());
            const string expected = @"/";

            Assert.Equal(expected, json.baseUrl);
        }
Esempio n. 3
0
        public void GetsRoutesFromRouteFetcher()
        {
            var routes = new[]
            {
                new RouteInfo
                {
                    Constraints = new Dictionary <string, object> {
                        { "constr", "aint" }
                    },
                    Defaults = new Dictionary <string, object>
                    {
                        { "controller", "Foo" },
                        { "action", "Bar" }
                    },
                    Optional = new[] { "id" },
                    Url      = "foo/bar",
                },
            };
            var routeFetcher = new Mock <IRouteFetcher>();

            routeFetcher.Setup(x => x.GetRoutes(It.IsAny <RouteData>())).Returns(routes);

            var request = new Mock <HttpRequest>();

            request.Setup(x => x.PathBase).Returns(new PathString("/base"));
            var httpContext = new Mock <HttpContext>();

            httpContext.Setup(x => x.Request).Returns(request.Object);
            var actionContext = new Mock <IActionContextAccessor>();

            actionContext.Setup(x => x.ActionContext).Returns(new ActionContext
            {
                HttpContext = httpContext.Object
            });
            var config = new Mock <IRouteJsConfiguration>();

            var          routeJs  = new RouteJs(new[] { routeFetcher.Object }, actionContext.Object, Enumerable.Empty <IRouteFilter>(), config.Object);
            var          result   = routeJs.GetJsonData();
            const string expected = @"{""routes"":[{""url"":""foo/bar"",""defaults"":{""controller"":""Foo"",""action"":""Bar""},""constraints"":{""constr"":""aint""},""optional"":[""id""]}],""baseUrl"":""/base/"",""lowerCaseUrls"":false}";

            Assert.Equal(expected, result);
        }
Esempio n. 4
0
		public void InsertsSlashAtTheBeginningOfBaseUrl()
		{
			var routes = new[]
				{
				new RouteInfo
				{
					Constraints = new Dictionary<string, object> {{"constr", "aint"}},
					Defaults = new Dictionary<string, object>
					{
						{"controller", "Foo"},
						{"action", "Bar"}
					},
					Optional = new[] {"id"},
					Url = "foo/bar",
				},
			};
			var routeFetcher = new Mock<IRouteFetcher>();
			routeFetcher.Setup(x => x.GetRoutes(It.IsAny<RouteData>())).Returns(routes);

			var request = new Mock<HttpRequest>();
			request.Setup(x => x.PathBase).Returns(new PathString(""));
			var httpContext = new Mock<HttpContext>();
			httpContext.Setup(x => x.Request).Returns(request.Object);
			var actionContext = new Mock<IActionContextAccessor>();
			actionContext.Setup(x => x.ActionContext).Returns(new ActionContext
			{
				HttpContext = httpContext.Object
			});
			var config = new Mock<IRouteJsConfiguration>();

			var routeJs = new RouteJs(new[] { routeFetcher.Object }, actionContext.Object, Enumerable.Empty<IRouteFilter>(), config.Object);
			var result = routeJs.GetJsonData();
			dynamic json = JsonConvert.DeserializeObject<ExpandoObject>(result, new ExpandoObjectConverter());
			const string expected = @"/";
			Assert.Equal(expected, json.baseUrl);
		}