コード例 #1
0
        public void GetSiteMap_NonMenuChildrenNodeIsActive_SetsActiveMenu()
        {
            route["action"]     = "Edit";
            route["controller"] = "Accounts";
            route["area"]       = "Administration";

            siteMap = new MvcSiteMapProvider(config, parser, null);

            MvcSiteMapNode[] actual = siteMap.GetSiteMap(context).ToArray();

            Assert.Equal(1, actual.Length);
            Assert.False(actual[0].IsActive);

            actual = actual[0].Children.ToArray();

            Assert.Equal(2, actual.Length);
            Assert.True(actual[0].IsActive);
            Assert.False(actual[1].IsActive);
            Assert.Empty(actual[0].Children);

            actual = actual[1].Children.ToArray();

            Assert.Equal(1, actual.Length);
            Assert.False(actual[0].IsActive);
            Assert.Empty(actual[0].Children);
        }
コード例 #2
0
        public void GetSiteMap_ActiveMenuParents_SetsHasActiveChildren()
        {
            route["action"]     = "Create";
            route["controller"] = "Roles";
            route["area"]       = "Administration";

            siteMap = new MvcSiteMapProvider(config, parser, null);

            MvcSiteMapNode[] actual = siteMap.GetSiteMap(context).ToArray();

            Assert.Equal(1, actual.Length);
            Assert.True(actual[0].HasActiveChildren);

            actual = actual[0].Children.ToArray();

            Assert.Equal(2, actual.Length);
            Assert.Empty(actual[0].Children);
            Assert.True(actual[1].HasActiveChildren);
            Assert.False(actual[0].HasActiveChildren);

            actual = actual[1].Children.ToArray();

            Assert.Equal(1, actual.Length);
            Assert.Empty(actual[0].Children);
            Assert.False(actual[0].HasActiveChildren);
        }
コード例 #3
0
        public void SetUp()
        {
            HttpContext.Current = HttpContextFactory.CreateHttpContext();

            routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values;
            provider    = new MvcSiteMapProvider(siteMapPath, parser);
        }
コード例 #4
0
        public void GetSiteMap_SetsActiveMenu()
        {
            routeValues["action"]     = "Create";
            routeValues["controller"] = "Roles";
            routeValues["area"]       = "Administration";

            provider = new MvcSiteMapProvider(siteMapPath, parser, null);

            MvcSiteMapNode[] actual = provider.GetSiteMap(viewContext).ToArray();

            Assert.Equal(1, actual.Length);
            Assert.False(actual[0].IsActive);

            actual = actual[0].Children.ToArray();

            Assert.Equal(2, actual.Length);
            Assert.False(actual[0].IsActive);
            Assert.False(actual[1].IsActive);
            Assert.Empty(actual[0].Children);

            actual = actual[1].Children.ToArray();

            Assert.Empty(actual[0].Children);
            Assert.True(actual[0].IsActive);
            Assert.Equal(1, actual.Length);
        }
コード例 #5
0
        public MvcSiteMapProviderTests()
        {
            authorizationProvider = Substitute.For <IAuthorizationProvider>();
            viewContext           = HtmlHelperFactory.CreateHtmlHelper().ViewContext;

            provider    = new MvcSiteMapProvider(siteMapPath, parser, authorizationProvider);
            routeValues = viewContext.RouteData.Values;
        }
コード例 #6
0
        public MvcSiteMapProviderTests()
        {
            parser  = new MvcSiteMapParser();
            config  = ConfigurationFactory.Create();
            context = HtmlHelperFactory.CreateHtmlHelper().ViewContext;
            authorizationProvider = Substitute.For <IAuthorizationProvider>();
            siteMap = new MvcSiteMapProvider(config, parser, authorizationProvider);

            route = context.RouteData.Values;
        }
コード例 #7
0
        /// <summary>
        /// Determines whether node is accessible to user.
        /// </summary>
        /// <param name="siteMap">The site map.</param>
        /// <param name="node">The node.</param>
        /// <returns>
        /// <c>true</c> if accessible to user; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="System.NotImplementedException">沒有實作</exception>
        public bool IsAccessibleToUser(MvcSiteMapProvider.ISiteMap siteMap,
            MvcSiteMapProvider.ISiteMapNode node)
        {
            bool result = true;
            if (ResourceOperationCollection.IsResourceOperationPopulated)
            {
                var resourceOperation = ResourceOperationCollection.GetResourceOperation(node.Area, node.Controller, node.Action);

                result = ResourceOperationAuthorisation.CheckAccess(ClaimsPrincipal.Current, resourceOperation);
            }
            return result;
        }
コード例 #8
0
        public void GetSiteMap_NullAuthorization_ReturnsAllMenus()
        {
            siteMap = new MvcSiteMapProvider(config, parser, null);

            MvcSiteMapNode[] actual = siteMap.GetSiteMap(context).ToArray();

            Assert.Equal(1, actual.Length);

            Assert.Null(actual[0].Action);
            Assert.Null(actual[0].Controller);
            Assert.Equal("Administration", actual[0].Area);
            Assert.Equal("fa fa-gears", actual[0].IconClass);

            actual = actual[0].Children.ToArray();

            Assert.Equal(2, actual.Length);

            Assert.Empty(actual[0].Children);

            Assert.Equal("Index", actual[0].Action);
            Assert.Equal("Accounts", actual[0].Controller);
            Assert.Equal("Administration", actual[0].Area);
            Assert.Equal("fa fa-user", actual[0].IconClass);

            Assert.Null(actual[1].Action);
            Assert.Equal("Roles", actual[1].Controller);
            Assert.Equal("Administration", actual[1].Area);
            Assert.Equal("fa fa-users", actual[1].IconClass);

            actual = actual[1].Children.ToArray();

            Assert.Equal(1, actual.Length);
            Assert.Empty(actual[0].Children);

            Assert.Equal("Create", actual[0].Action);
            Assert.Equal("Roles", actual[0].Controller);
            Assert.Equal("Administration", actual[0].Area);
            Assert.Equal("fa fa-file-o", actual[0].IconClass);
        }
コード例 #9
0
 public MvcSiteMapProviderTests()
 {
     siteMap = new MvcSiteMapProvider("Mvc.sitemap", new MvcSiteMapParser());
     context = HtmlHelperFactory.CreateHtmlHelper().ViewContext;
     route   = context.RouteData.Values;
 }
コード例 #10
0
 public MvcSiteMapProviderTests()
 {
     requestContext = HttpContextFactory.CreateHttpContext().Request.RequestContext;
     provider       = new MvcSiteMapProvider(siteMapPath, parser);
     routeValues    = requestContext.RouteData.Values;
 }
コード例 #11
0
 public void SetUp()
 {
     HttpContext.Current = new HttpMock().HttpContext;
     provider            = new MvcSiteMapProvider(siteMapPath, parser);
     routeValues         = HttpContext.Current.Request.RequestContext.RouteData.Values;
 }
コード例 #12
0
 public MvcSiteMapProviderTests()
 {
     viewContext = HtmlHelperFactory.CreateHtmlHelper().ViewContext;
     provider    = new MvcSiteMapProvider(siteMapPath, parser);
     routeValues = viewContext.RouteData.Values;
 }
コード例 #13
0
 public MvcSiteMapProviderTests()
 {
     viewContext = HtmlHelperFactory.CreateHtmlHelper().ViewContext;
     provider = new MvcSiteMapProvider(siteMapPath, parser);
     routeValues = viewContext.RouteData.Values;
 }