public ITestMenuItem GetItem(string name)
        {
            IMenuItemImmutable item = menu.MenuItems.FirstOrDefault(i => i.Name == name);

            Assert.IsNotNull(item, "No menu item with name: " + name);
            return(factory.CreateTestMenuItem(item, owningObject));
        }
Example #2
0
        public static void Compare(IMenuItemImmutable menu1, IMenuItemImmutable menu2)
        {
            if (menu1 == null && menu2 == null)
            {
                return;
            }

            var name = menu1.Name;

            Compare(menu1.Name, menu2.Name, name);
            Compare(menu1.Id, menu2.Id, name);

            switch (menu1)
            {
            case MenuAction m:
                Compare(m, menu2 as MenuAction, name);
                break;

            case MenuImpl m:
                Compare(m, menu2 as MenuImpl, name);
                break;

            default:
                Assert.Fail();
                break;
            }
        }
Example #3
0
        public static string ToOrderString(this IMenuItemImmutable menu, bool print = false)
        {
            if (menu == null)
            {
                return("");
            }
            string id;

            switch (menu)
            {
            case MenuAction m:
                var facet  = m.Action.GetFacet <IActionInvocationFacet>();
                var suffix = "";
                if (facet != null)
                {
                    suffix = facet.OrderString();
                }

                id = $"{m.Name}/{m.Id}/{m.Action.ToIdString()}/{suffix}";
                break;

            default:
                id = $"{menu.Name}/{menu.Id}";
                break;
            }

            if (print)
            {
                Console.WriteLine("menu: " + id);
            }

            return(id);
        }
        private static IMenuItemFacade Wrap(IMenuItemImmutable menu, IFrameworkFacade facade, INakedObjectsFramework framework) {
            var immutable = menu as IMenuActionImmutable;
            if (immutable != null) {
                return new MenuActionFacade(immutable, facade, framework);
            }

            var menuImmutable = menu as IMenuImmutable;
            return menuImmutable != null ? (IMenuItemFacade) new MenuFacade(menuImmutable, facade, framework) : new MenuItemFacade(menu);
        }
        private static bool IsDuplicateAndIsVisibleActions(
            HtmlHelper html, IMenuItemImmutable item,
            IList <IMenuItemImmutable> items, INakedObject nakedObject)
        {
            var itemsOfSameName = items.Where(i => i.Name == item.Name);

            if (itemsOfSameName.Count() == 1)
            {
                return(false);
            }
            return(itemsOfSameName.Count(i => MenuActionAsElementDescriptor(html, i as IMenuActionImmutable, nakedObject, false) != null) > 1);
        }
        private static IMenuItemFacade Wrap(IMenuItemImmutable menu, IFrameworkFacade facade, INakedObjectsFramework framework)
        {
            var immutable = menu as IMenuActionImmutable;

            if (immutable != null)
            {
                return(new MenuActionFacade(immutable, facade, framework));
            }

            var menuImmutable = menu as IMenuImmutable;

            return(menuImmutable != null ? (IMenuItemFacade) new MenuFacade(menuImmutable, facade, framework) : new MenuItemFacade(menu));
        }
 public ITestMenuItem CreateTestMenuItem(IMenuItemImmutable item, ITestHasActions owningObject) => new TestMenuItem(item, this, owningObject);
        private readonly ITestHasActions owningObject; //Non-null if this is on an objectMenu

        public TestMenuItem(IMenuItemImmutable item, ITestObjectFactory factory, ITestHasActions owningObject) {
            this.item = item;
            this.factory = factory;
            this.owningObject = owningObject;
        }
        private static ElementDescriptor MenuItemAsElementDescriptor(this HtmlHelper html, IMenuItemImmutable item, INakedObject nakedObject, bool isEdit)
        {
            ElementDescriptor descriptor = null;

            if (item is IMenuActionImmutable)
            {
                descriptor = MenuActionAsElementDescriptor(html, item as IMenuActionImmutable, nakedObject, isEdit);
            }
            else if (item is IMenu)
            {
                descriptor = SubMenuAsElementDescriptor(html, item as IMenuImmutable, nakedObject, isEdit);
            }
            else if (item is CustomMenuItem)
            {
                descriptor = CustomMenuItemAsDescriptor(html, item as CustomMenuItem);
            }
            return(descriptor);
        }
 public ITestMenuItem CreateTestMenuItem(IMenuItemImmutable item, ITestHasActions owningObject) {
     return new TestMenuItem(item, this, owningObject);
 }
 private void AddMenuItem(IMenuItemImmutable item)
 {
     items = items.Add(item); //Only way to add to an immutable collection
 }
 public MenuItemFacade(IMenuItemImmutable wrapped) {
     Wrapped = wrapped;
     Name = wrapped.Name;
     Id = wrapped.Id;
 }
Example #13
0
        private readonly ITestHasActions owningObject; //Non-null if this is on an objectMenu

        public TestMenuItem(IMenuItemImmutable item, ITestObjectFactory factory, ITestHasActions owningObject)
        {
            this.item         = item;
            this.factory      = factory;
            this.owningObject = owningObject;
        }
 private void AddMenuItem(IMenuItemImmutable item) {
     items = items.Add(item); //Only way to add to an immutable collection
 }
Example #15
0
 public MenuItemFacade(IMenuItemImmutable wrapped)
 {
     Wrapped = wrapped;
     Name    = wrapped.Name;
     Id      = wrapped.Id;
 }
 private static IMenuItemFacade Wrap(IMenuItemImmutable menu, IFrameworkFacade facade, INakedObjectsFramework framework) =>
 menu switch
 {