public void ValueTypeShouldMismatch()
 {
     var item1 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary(new { one = 1 }) };
     var item2 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary(new { one = 1 }) };
     var item3 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary(new { one = "1" }) };
     AssertSameSameDifferent(item1, item2, item3);
 }
 public void TextShouldCauseDifferenceAndNullRouteValuesAreEqual()
 {
     var item1 = new MenuItem { Text = new LocalizedString("hello") };
     var item2 = new MenuItem { Text = new LocalizedString("hello") };
     var item3 = new MenuItem { Text = new LocalizedString("hello3") };
     AssertSameSameDifferent(item1, item2, item3);
 }
 public void PositionAndChildrenDontMatter()
 {
     var item1 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary(new { one = "1", two = "2" }) };
     var item2 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary(new { one = "1", two = "2" }), Position = "4.0" };
     var item3 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary(new { one = "1", two = "2" }), Items = new[] { new MenuItem() } };
     AssertSameSameSame(item1, item2, item3);
 }
 public void AdditionalPropertiesShouldMismatch()
 {
     var item1 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary(new { one = 1 }) };
     var item2 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary(new { one = 1 }) };
     var item3 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary(new { one = 1, two = 2 }) };
     AssertSameSameDifferent(item1, item2, item3);
 }
 public void NullRouteValuesShouldEqualEmptyRouteValues()
 {
     var item1 = new MenuItem { Text = new LocalizedString("hello") };
     var item2 = new MenuItem { Text = new LocalizedString("hello") };
     var item3 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary() };
     var item4 = new MenuItem { Text = new LocalizedString("hello"), RouteValues = new RouteValueDictionary() };
     AssertSameSameSame(item1, item2, item3);
     AssertSameSameSame(item3, item4, item1);
 }
예제 #6
0
 private static bool PositionHasMajorNumber(MenuItem mi, int? position = null)
 {
     int menuPosition;
     var major = mi.Position == null ? null : mi.Position.Split('.')[0];
     if (string.IsNullOrEmpty(major)) {
         return false;
     }
     var parsed = int.TryParse(major, out menuPosition);
     return parsed && (!position.HasValue || position.Value == menuPosition);
 }
        private static void AssertSameSameSame(MenuItem item1, MenuItem item2, MenuItem item3)
        {
            var comparer = new MenuItemComparer();

            Assert.That(comparer.Equals(item1, item2), Is.True);
            Assert.That(comparer.Equals(item1, item3), Is.True);
            Assert.That(comparer.Equals(item2, item3), Is.True);

            Assert.That(comparer.GetHashCode(item1), Is.EqualTo(comparer.GetHashCode(item2)));
            Assert.That(comparer.GetHashCode(item1), Is.EqualTo(comparer.GetHashCode(item3)));
            Assert.That(comparer.GetHashCode(item2), Is.EqualTo(comparer.GetHashCode(item3)));
        }
        private static void AssertSameSameDifferent(MenuItem item1, MenuItem item2, MenuItem item3)
        {
            var comparer = new MenuItemComparer();

            Assert.That(comparer.Equals(item1, item2), Is.True);
            Assert.That(comparer.Equals(item1, item3), Is.False);
            Assert.That(comparer.Equals(item2, item3), Is.False);

            Assert.That(comparer.GetHashCode(item1), Is.EqualTo(comparer.GetHashCode(item2)));
            // - hash inequality isn't really guaranteed, now that you mention it
            //Assert.That(comparer.GetHashCode(item1), Is.Not.EqualTo(comparer.GetHashCode(item3)));
            //Assert.That(comparer.GetHashCode(item2), Is.Not.EqualTo(comparer.GetHashCode(item3)));
        }
        /// <summary>
        /// Builds a local menu item shape.
        /// </summary>
        /// <param name="shapeFactory">The shape factory.</param>
        /// <param name="parentShape">The parent shape.</param>
        /// <param name="menu">The menu shape.</param>
        /// <param name="menuItem">The menu item to build the shape for.</param>
        /// <returns>The menu item shape.</returns>
        public static dynamic BuildLocalMenuItemShape(dynamic shapeFactory, dynamic parentShape, dynamic menu, MenuItem menuItem)
        {
            var menuItemShape = shapeFactory.LocalMenuItem()
                .Text(menuItem.Text)
                .IdHint(menuItem.IdHint)
                .Href(menuItem.Href)
                .LinkToFirstChild(menuItem.LinkToFirstChild)
                .LocalNav(menuItem.LocalNav)
                .Selected(menuItem.Selected)
                .RouteValues(menuItem.RouteValues)
                .Item(menuItem)
                .Menu(menu)
                .Parent(parentShape);

            foreach (var className in menuItem.Classes)
                menuItemShape.Classes.Add(className);

            return menuItemShape;
        }
 public NavigationItemBuilder()
 {
     _item = new MenuItem();
 }
        static MenuItem Join(IEnumerable<MenuItem> items)
        {
            var list = items.ToArray();

            if (list.Count() < 2)
                return list.Single();

            var joined = new MenuItem {
                Text = list.First().Text,
                IdHint = list.Select(x => x.IdHint).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
                Classes = list.Select(x => x.Classes).FirstOrDefault(x => x != null && x.Count > 0),
                Url = list.Select(x => x.Url).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
                Href = list.Select(x => x.Href).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
                LinkToFirstChild = list.First().LinkToFirstChild,
                RouteValues = list.Select(x => x.RouteValues).FirstOrDefault(x => x != null),
                LocalNav = list.Any(x => x.LocalNav),
                Culture = list.First().Culture,
                Items = Merge(list.Select(x => x.Items)).ToArray(),
                Position = SelectBestPositionValue(list.Select(x => x.Position)),
                Permissions = list.SelectMany(x => x.Permissions).Distinct(),
                Content = list.First().Content
            };

            return joined;
        }
        private static RouteData GetRouteData(MenuItem menuItem)
        {
            RouteData routeData = new RouteData();
            routeData.Values["area"] = menuItem.RouteValues["area"];
            routeData.Values["controller"] = menuItem.RouteValues["controller"];
            routeData.Values["action"] = menuItem.RouteValues["action"];

            return routeData;
        }
 public NavigationBuilder Remove(MenuItem item)
 {
     Contained.Remove(item);
     return this;
 }