public void BreadcrumbTrail_removes_Url_for_current_page()
        {
            var request = new DefaultHttpContext().Request;

            request.Scheme      = "https";
            request.Host        = new HostString("www.example.org");
            request.PathBase    = new PathString(string.Empty);
            request.Path        = new PathString("/example");
            request.QueryString = new QueryString(string.Empty);
            var httpContext = new Mock <HttpContext>();

            httpContext.Setup(x => x.Request).Returns(request);
            var httpContextAccessor = new Mock <IHttpContextAccessor>();

            httpContextAccessor.Setup(x => x.HttpContext).Returns(httpContext.Object);

            var settings = new BreadcrumbSettings {
                { new BreadcrumbLevel {
                      Name = "level1", Url = new Uri("/", UriKind.Relative)
                  } },
                { new BreadcrumbLevel {
                      Name = "level2", Url = new Uri("/example", UriKind.Relative)
                  } }
            };

            var trail = new BreadcrumbTrailFromConfig(Options.Create(settings), httpContextAccessor.Object).BuildTrail();

            Assert.Equal(string.Empty, trail["level2"]);
        }
Beispiel #2
0
        private void Menu()
        {
            // Highlight the current section using the breadcrumb trail. Compare just A-Z characters to avoid any special characters (eg &) breaking the logic.
            string selectedSection;

            if (!String.IsNullOrEmpty(Request.QueryString["section"]))
            {
                selectedSection = Request.QueryString["section"];
            }
            else
            {
                selectedSection = String.Empty;
                var provider = new BreadcrumbTrailFromConfig();
                var trail    = provider.BuildTrail();
                if (trail != null && trail.Count > 1)
                {
                    selectedSection = new List <string>(trail.Keys)[1].ToUpperInvariant();
                }
            }

            HtmlContainerControl[] sections = { this.jobs, this.socialcare, this.business, this.community, this.education, this.environment, this.families, this.leisure, this.libraries, this.transport, this.council };
            var matcher        = new SelectedSectionMatcher();
            var matchedSection = matcher.MatchSection(selectedSection, sections);

            if (matchedSection != null)
            {
                matchedSection.Attributes["class"] = "selected";
            }
        }