public void ConvertToNavigationItems_AutoCreatesSecondLevelMenus()
        {
            var source = NavigationHelper.ByCategory(new[]
            {
                new NavigationLinkAttribute(1, "A/B/C", "http://dummy.com", permission: null)
            });

            var actual = NavigationHelper.ConvertToNavigationItems(source, null);

            Assert.NotNull(actual);
            Assert.StrictEqual(1, actual.Count);
            var a = actual[0];

            Assert.Equal("A", a.Title);
            Assert.Equal("A", a.FullPath);
            Assert.StrictEqual(1, a.Children.Count);
            var b = a.Children[0];

            Assert.Equal("B", b.Title);
            Assert.Equal("A/B", b.FullPath);
            Assert.StrictEqual(1, b.Children.Count);
            var c = b.Children[0];

            Assert.Equal("C", c.Title);
            Assert.Equal("A/B/C", c.FullPath);
            Assert.StrictEqual(0, c.Children.Count);
        }
        public void ConvertToNavigationItems_DoesntTrimItems()
        {
            var source = NavigationHelper.ByCategory(new[]
            {
                new NavigationLinkAttribute(1, "A / B / C", "http://dummy.com", permission: null)
            });

            var actual = NavigationHelper.ConvertToNavigationItems(source, null);

            Assert.NotNull(actual);
            Assert.StrictEqual(1, actual.Count);

            var a1 = actual[0];

            Assert.Equal("A ", a1.Title);
            Assert.Equal("A ", a1.FullPath);
            Assert.StrictEqual(1, a1.Children.Count);

            var a1b = a1.Children[0];

            Assert.Equal(" B ", a1b.Title);
            Assert.Equal("A / B ", a1b.FullPath);
            Assert.StrictEqual(1, a1b.Children.Count);

            var a1bc = a1b.Children[0];

            Assert.Equal(" C", a1bc.Title);
            Assert.Equal("A / B / C", a1bc.FullPath);
            Assert.StrictEqual(0, a1bc.Children.Count);
        }
    private static ILookup <string, NavigationItemAttribute> GetNavigationItemAttributes(
        Func <NavigationItemAttribute, bool> filter)
    {
        var list = new List <NavigationItemAttribute>();

        foreach (var assembly in ExtensibilityHelper.SelfAssemblies)
        {
            foreach (NavigationItemAttribute attr in assembly.GetCustomAttributes <NavigationItemAttribute>())
            {
                if (filter == null || filter(attr))
                {
                    list.Add(attr);
                }
            }
        }

        foreach (var navItemType in ExtensibilityHelper.GetTypesWithInterface(typeof(INavigationItemSource)))
        {
            var navItem = (INavigationItemSource)Activator.CreateInstance(navItemType);
            foreach (var item in navItem.GetItems())
            {
                if (filter == null || filter(item))
                {
                    list.Add(item);
                }
            }
        }

        var user = (UserDefinition)Authorization.UserDefinition;

        var connection     = SqlConnections.NewFor <VisitTypesRow>();
        var visitTypesFlds = VisitTypesRow.Fields;

        var visitTypes = connection.List <VisitTypesRow>(visitTypesFlds.TenantId == user.TenantId && visitTypesFlds.IsActive == 1 && visitTypesFlds.ShowInMenu == 1);

        list.Add(new NavigationMenuAttribute(506, LocalText.Get("Db.PatientManagement.VisitTypes.EntityPlural"), "fa-stethoscope"));

        list.Add(new NavigationLinkAttribute(506,
                                             path: LocalText.Get("Db.PatientManagement.VisitTypes.EntityPlural") + "/" + LocalText.Get("LeftNavigation.AddNewVisitType"),
                                             url: "#",
                                             icon: "fa-plus-square open-new-visit-dialog",
                                             permission: "PatientManagement:VisitTypes:Modify"));
        foreach (var visitType in visitTypes)
        {
            list.Add(new NavigationLinkAttribute(506,
                                                 path: LocalText.Get("Db.PatientManagement.VisitTypes.EntityPlural") + "/" + visitType.Name.Replace("/", "//"),
                                                 url: "/PatientManagement/Visits?visittype=" + visitType.VisitTypeId,
                                                 icon: "fa-circle-o fc-event-droppable " + visitType.BackgroundColor,
                                                 permission: "PatientManagement:VisitTypes:Read"
                                                 ));
        }
        list.Add(new NavigationLinkAttribute(506,
                                             path: LocalText.Get("Db.PatientManagement.VisitTypes.EntityPlural") + "/" + LocalText.Get("LeftNavigation.VisitTypesPage"),
                                             url: "/PatientManagement/VisitTypes",
                                             icon: "fa-bars",
                                             permission: "PatientManagement:VisitTypes:Page"
                                             ));
        return(NavigationHelper.ByCategory(list));
    }
        public void ConvertToNavigationItems_HandlesMultipleDoubleSlashAsSingleSlashWithOneLevel()
        {
            var source = NavigationHelper.ByCategory(new[]
            {
                new NavigationLinkAttribute(1, "X////Y", "http://dummy.com", permission: null)
            });

            var actual = NavigationHelper.ConvertToNavigationItems(source, null);

            Assert.NotNull(actual);
            Assert.StrictEqual(1, actual.Count);

            var xy = actual[0];

            Assert.Equal("X//Y", xy.Title);
            Assert.Equal("X////Y", xy.FullPath);
            Assert.StrictEqual(0, xy.Children.Count);
        }