示例#1
0
 public Page(IWebDriver driver)
 {
     this.driver = driver;
     this.driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
     _menu = new NavigationMenu(driver);
     PageFactory.InitElements(driver, this);
 }
        public void TestTargets()
        {
            var menu = new NavigationMenu();

            Assert.That(menu.Targets, Is.Empty);

            bool signaled = false;

            menu.PropertyChanged += (sender, args) => {
                if (args.PropertyName == "Targets")
                {
                    signaled = true;
                }
            };

            var newArray = new[] {
                new ContentPage {
                    Content = new View(), Icon = "img1.jpg"
                },
                new ContentPage {
                    Content = new View(), Icon = "img2.jpg"
                }
            };

            menu.Targets = newArray;

            Assert.AreEqual(newArray, menu.Targets);
            Assert.True(signaled);
        }
        public static NavigationMenu CopyNavigationMenuEntityProperties(this NavigationMenu destEntity, NavigationMenuEntity srcEntity)
        {
            if (destEntity == null)
            {
                return(null);
            }
            if (destEntity == null)
            {
                return(null);
            }

            destEntity.Id                 = srcEntity.Id;
            destEntity.Name               = srcEntity.Name;
            destEntity.DisplayName        = srcEntity.DisplayName;
            destEntity.AreaName           = srcEntity.AreaName;
            destEntity.ControllerName     = srcEntity.ControllerName;
            destEntity.ActionName         = srcEntity.ActionName;
            destEntity.RouteUrl           = srcEntity.RouteUrl;
            destEntity.ParentNavigationId = srcEntity.ParentNavigationId;
            destEntity.NavigationTypeId   = srcEntity.NavigationTypeId;
            destEntity.DisplayOrder       = srcEntity.DisplayOrder;
            destEntity.IsDisabled         = srcEntity.IsDisabled;
            destEntity.LastModifiedUserId = srcEntity.LastModifiedUserId;
            destEntity.InsertedOnUtc      = srcEntity.InsertedOnUtc;
            destEntity.LastModifiedUserId = srcEntity.LastModifiedUserId;

            foreach (var role in srcEntity.Roles)
            {
                destEntity.Roles.Add(role.ToRoleNavigationEntity());
            }
            return(destEntity);
        }
        private IEnumerable <NavigationMenu> SelectNavigation(int?parent, string explicitTenant)
        {
            var items = from n in securityContext.Navigation where n.ParentId == parent orderby n.SortOrder ?? 0 select n;

            foreach (var item in items)
            {
                NavigationMenu ret = new NavigationMenu
                {
                    DisplayName        = item.DisplayName,
                    RequiredPermission = item.EntryPoint?.PermissionName,
                    RequiredFeature    = item.Feature?.FeatureName,
                    SortOrder          = item.SortOrder ?? 0,
                    SpanClass          = item.SpanClass,
                    Url = !string.IsNullOrEmpty(item.Url) ? $"{(!string.IsNullOrEmpty(explicitTenant) ? $"/{explicitTenant}" : "")}{(!item.Url.StartsWith("/") ? "/" : "")}{item.Url}" : ""
                };

                if ((!options.Value.CheckPermissions || string.IsNullOrEmpty(ret.RequiredPermission) || services.VerifyUserPermissions(new[] { ret.RequiredPermission })) &&
                    (!options.Value.CheckFeatures || string.IsNullOrEmpty(ret.RequiredFeature) || services.VerifyActivatedFeatures(new[] { ret.RequiredFeature }, out _)))
                {
                    if (string.IsNullOrEmpty(item.Url))
                    {
                        ret.Children.AddRange(SelectNavigation(item.NavigationMenuId, explicitTenant));
                    }

                    yield return(ret);
                }
            }
        }
        public async Task TestSendTargetSelected()
        {
            var menu    = new NavigationMenu();
            var navForm = new NavigationPage();

            await navForm.PushAsync(new ContentPage {
                Title   = "Menu",
                Content = menu
            });

            bool pushed = false;

            navForm.Pushed += (sender, arg) => pushed = true;

            var child = new ContentPage {
                Icon    = "img.jpg",
                Content = new View()
            };

            menu.Add(child);

            menu.SendTargetSelected(child);

            Assert.True(pushed);
            Assert.AreEqual(child, navForm.CurrentPage);
        }
示例#6
0
        public void Can_Select_Categories()
        {
            Mock <IProductRepository> mock = new Mock <IProductRepository>();

            mock.Setup(m => m.Products).Returns((new Product[]
            {
                new Product {
                    ProductId = 1, Name = "P1", Category = "Jabłka"
                },
                new Product {
                    ProductId = 2, Name = "P2", Category = "Jabłka"
                },
                new Product {
                    ProductId = 3, Name = "P3", Category = "Śliwki"
                },
                new Product {
                    ProductId = 4, Name = "P4", Category = "Pomarańcze"
                }
            }).AsQueryable());

            NavigationMenu target = new NavigationMenu(mock.Object);

            string[] results = ((IEnumerable <string>)(target.Invoke() as ViewViewComponentResult)
                                .ViewData.Model)
                               .ToArray();

            Assert.True(Enumerable.SequenceEqual(new string[] { "Jabłka", "Pomarańcze", "Śliwki" }, results));
        }
        public void TestDoubleRemove()
        {
            var menu = new NavigationMenu();

            var child = new ContentPage {
                Icon    = "jpg.jpg",
                Content = new View()
            };

            menu.Add(child);
            menu.Remove(child);

            bool signaled = false;

            menu.PropertyChanged += (sender, args) => {
                switch (args.PropertyName)
                {
                case "Targets":
                    signaled = true;
                    break;
                }
            };

            menu.Remove(child);

            Assert.False(menu.Targets.Contains(child));
            Assert.False(signaled);
        }
示例#8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((!Roles.IsUserInRole(Context.User.Identity.Name, "Administrators")) && (!Roles.IsUserInRole(Context.User.Identity.Name, "hr_emploee")))
            {
                MenuItem mnuItem = NavigationMenu.FindItem("Manage Users");
                NavigationMenu.Items.Remove(mnuItem);
                mnuItem = NavigationMenu.FindItem("Manage Teams");
                NavigationMenu.Items.Remove(mnuItem);
                mnuItem = NavigationMenu.FindItem("Ustawienia HR");
                NavigationMenu.Items.Remove(mnuItem);
                mnuItem = NavigationMenu.FindItem("HR Manage Holidays");
                NavigationMenu.Items.Remove(mnuItem);
            }

            if ((!Roles.IsUserInRole(Context.User.Identity.Name, "menager")))
            {
                MenuItem mnuItem = NavigationMenu.FindItem("My Team Holidays");
                NavigationMenu.Items.Remove(mnuItem);
            }

            if ((!Roles.IsUserInRole(Context.User.Identity.Name, "emploee")))
            {
                MenuItem mnuItem = NavigationMenu.FindItem("My Holidays");
                NavigationMenu.Items.Remove(mnuItem);
            }
        }
        public async Task CreateNavigationCacheAsync()
        {
            var mItems = new NavigationMenu();
            var roles  = await _identityDbContext.Roles.ToListAsync();

            var itemTypes = await _identityDbContext.NavigationMenus.Where(s => s.Type == MenuType.PCMSWEBRight &&
                                                                           s.ClientName == _settings.Value.ApplicationTitle).Include(s => s.Parent)
                            .Include(s => s.Childeren).Include(s => s.Roles).ToListAsync();

            var itemsDto = new List <NavigationMenuItem>();

            foreach (var item in itemTypes)
            {
                var rIds    = item.Roles.Select(s => s.RoleId);
                var rstring = roles.Where(o => rIds.Contains(o.Id)).Select(o => o.Name).ToList();
                itemsDto.Add(new NavigationMenuItem
                {
                    SelectedRoles = rstring,
                    ClientName    = item.ClientName,
                    DisplayName   = item.DisplayName,
                    Type          = item.Type,
                    IsNested      = item.IsNested,
                    Sequence      = item.Sequence,
                    MaterialIcon  = item.MaterialIcon,
                    Link          = item.Link,
                });
            }
            mItems.MenuItems = itemsDto.ToList();
            var items = JsonConvert.SerializeObject(mItems);
            await _cache.SetStringAsync(NavigationCacheName, items);
        }
示例#10
0
        public RankingState(Game1 game, GraphicsDevice graphicsDevice, ContentManager content) : base(game, graphicsDevice, content)
        {
            var buttonTexture = _content.Load <Texture2D>("Components/Button");

            var buttonFont = _content.Load <SpriteFont>("Components/Font");

            _font = buttonFont;

            var backButton = new Button(buttonTexture, buttonFont)
            {
                Position = new Vector2(550, 570),
                Text     = "Go to main menu"
            };

            backButton.OnClick += backButton_Click;

            navigationMenu = new NavigationMenu(new List <Component>
            {
                backButton,
            });
            _components = new List <Component>()
            {
                navigationMenu,
            };
        }
示例#11
0
        private void SetDefaultMenu()
        {
            MenuItem parent = NavigationMenu.FindItem("3");

            NavigationMenu.Items.Remove(parent);

            MenuItem parent2 = NavigationMenu.FindItem("4");

            NavigationMenu.Items.Remove(parent2);

            MenuItem parent3 = NavigationMenu.FindItem("5");

            NavigationMenu.Items.Remove(parent3);

            MenuItem parent4 = NavigationMenu.FindItem("6");

            NavigationMenu.Items.Remove(parent4);

            MenuItem parent5 = NavigationMenu.FindItem("7");

            NavigationMenu.Items.Remove(parent5);

            MenuItem parent6 = NavigationMenu.FindItem("8");

            NavigationMenu.Items.Remove(parent6);

            MenuItem parent7 = NavigationMenu.FindItem("2");

            NavigationMenu.Items.Remove(parent7);
        }
        public ConfirmExitState(Game1 game, GraphicsDevice graphicsDevice, ContentManager content) : base(game, graphicsDevice, content)
        {
            var buttonTexture = _content.Load <Texture2D>("Components/Button");
            var buttonFont    = _content.Load <SpriteFont>("Components/Font");

            _font = buttonFont;

            var continueButton = new Button(buttonTexture, buttonFont)
            {
                Position = new Vector2(550, 400),
                Text     = "Continue",
            };

            continueButton.OnClick += ContinueButton_Click;

            var exitButton = new Button(buttonTexture, buttonFont)
            {
                Position = new Vector2(550, 460),
                Text     = "Quit",
            };

            exitButton.OnClick += ExitButton_Click;

            navigationMenu = new NavigationMenu(new List <Component>
            {
                continueButton,
                exitButton,
            });
            _components = new List <Component>()
            {
                navigationMenu,
            };
        }
示例#13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserLogin"] != null)
            {
                MAS_COMPANYUSER_DTO retUser = (MAS_COMPANYUSER_DTO)Session["UserLogin"];
                if (retUser.RolesNo == 1)
                {
                    MenuItem parent1 = NavigationMenu.FindItem("2");
                    NavigationMenu.Items.Remove(parent1);

                    MenuItem parent = NavigationMenu.FindItem("8");
                    NavigationMenu.Items.Remove(parent);
                }
                else
                {
                    //(retUser.RolesNo == 2)
                    SetVendorMenu();
                }
            }
            else
            {
                FormsAuthentication.SignOut();
                SetDefaultMenu();
            }
        }
        public async Task CreateNavigationCacheAsync()
        {
            var mItems = new NavigationMenu();
            var roles  = await _identityDbContext.Roles.ToListAsync();

            var itemTypes = await _identityDbContext.NavigationMenus.Where(s => s.Type == MenuType.PCMSWEBLeft &&
                                                                           s.ClientName == _settings.Value.ApplicationTitle).Include(s => s.Parent)
                            .Include(s => s.Childeren).Include(s => s.Roles).ToListAsync();

            if (itemTypes.Any())
            {
                Parallel.ForEach(itemTypes, item =>
                {
                    var rIds           = item.Roles.Select(s => s.RoleId);
                    var rstring        = roles.Where(o => rIds.Contains(o.Id)).Select(o => o.Name).ToList();
                    item.SelectedRoles = rstring;
                });

                var itemsDto = _mapper.Map <IEnumerable <NavigationMenuType>, IEnumerable <NavigationMenuItem> >(itemTypes.Where(s => s.Parent == null));

                mItems.MenuItems = itemsDto.ToList();
                var items = JsonConvert.SerializeObject(mItems);
                await _cache.SetStringAsync(NavigationCacheName, items);
            }
        }
示例#15
0
 public void OpenNavigation()
 {
     //открыть вкладку Ситы
     NavigationMenu.OpenPage("Ситы");
     //проверить часть url
     PageValidation.CheckUrl("/Sits");
 }
        public ActionResult MenuNavigation()
        {
            var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
            var item         = Sitecore.Context.Database.GetItem(dataSourceId);

            var menuIems = item.Children;

            var menus = new List <NavigationMenu>();

            foreach (var menuItem in menuIems)
            {
                var navItem = (Item)menuItem;
                var model   = new NavigationMenu
                {
                    MenuId   = navItem.ID.ToString(),
                    Title    = navItem.Fields["MenuName"].Value,
                    MenuLink = new HtmlString(FieldRenderer.Render(navItem, "MenuLink"))
                };

                if (navItem.Children?.Count > 0)
                {
                    model.SubMenus = GetChildMenus(navItem.Children);
                }

                menus.Add(model);
            }

            return(View("~/Views/Content/NavigationMenu.cshtml", menus));
        }
示例#17
0
        public CreditsState(Game1 game, GraphicsDevice graphicsDevice, ContentManager content) : base(game, graphicsDevice, content)
        {
            _font = _content.Load <SpriteFont>("Components/Font");
            var buttonTexture     = _content.Load <Texture2D>("Components/Button");
            var backgroundTexture = _content.Load <Texture2D>("Components/Background");

            var background = new MenuBackground(backgroundTexture)
            {
                Position = new Vector2(0, 0)
            };


            var backButton = new Button(buttonTexture, _font)
            {
                Position = new Vector2(550, 570),
                Text     = "Go to main menu"
            };

            backButton.OnClick += BackButton_Click;

            navigationMenu = new NavigationMenu(new List <Component>
            {
                backButton,
            });
            _components = new List <Component>()
            {
                background,
                navigationMenu,
            };
            ;
        }
示例#18
0
        public async Task <ApplicationIdentityResult> UpdateAsync(NavigationMenu navigation)
        {
            var entity = await _navigationRepository.GetSingleAsync(navigation.Id);

            var navigationMenuEntity = await _navigationRepository.GetSingleAsync(navigation.Id);

            if (navigationMenuEntity == null)
            {
                return(new ApplicationIdentityResult(new[] { "Invalid Navigation Id" }, false));
            }

            navigationMenuEntity.Name               = navigation.Name;
            navigationMenuEntity.DisplayName        = navigation.DisplayName;
            navigationMenuEntity.AreaName           = navigation.AreaName;
            navigationMenuEntity.ControllerName     = navigation.ControllerName;
            navigationMenuEntity.ActionName         = navigation.ActionName;
            navigationMenuEntity.RouteUrl           = navigation.RouteUrl;
            navigationMenuEntity.IsDisabled         = navigation.IsDisabled;
            navigationMenuEntity.ParentNavigationId = navigation.ParentNavigationId;
            navigationMenuEntity.NavigationTypeId   = navigation.NavigationTypeId;
            navigationMenuEntity.LastModifiedUserId = navigation.LastModifiedUserId;
            navigationMenuEntity.LastModifiedOnUtc  = DateTime.UtcNow;
            navigationMenuEntity.NavigationType     = await _navigationTypeRepository.GetSingleAsync(navigation.NavigationTypeId);

            _navigationRepository.Update(navigationMenuEntity);
            await _unitOfWork.SaveChangesAsync();

            navigation = navigationMenuEntity.ToNavigationMenu();
            return(new ApplicationIdentityResult(new[] { "" }, true));
        }
示例#19
0
        public App()
        {
            InitializeComponent();

            /*DependencyService.Register<MockDataStore>();*/
            MainPage = new NavigationMenu();
        }
示例#20
0
        public void Indicates_Selected_Category()
        {
            string categoryToSelect        = "Jabłka";
            Mock <IProductRepository> mock = new Mock <IProductRepository>();

            mock.Setup(m => m.Products).Returns((new Product[]
            {
                new Product {
                    ProductId = 1, Name = "P1", Category = "Jabłka"
                },
                new Product {
                    ProductId = 4, Name = "P2", Category = "Pomarańcze"
                }
            }).AsQueryable());

            NavigationMenu target = new NavigationMenu(mock.Object);

            target.ViewComponentContext = new ViewComponentContext
            {
                ViewContext = new ViewContext
                {
                    RouteData = new RouteData()
                }
            };

            target.RouteData.Values["category"] = categoryToSelect;

            string result = (string)(target.Invoke()
                                     as ViewViewComponentResult).ViewData["SelectedCategory"];

            Assert.Equal(categoryToSelect, result);
        }
示例#21
0
        public App()
        {
            // http://www.materialpalette.com/teal/amber
            //sets enosix items color scheme in app
            EnosixStyles.Theme.DarkPrimaryColor   = Color.FromHex("C2185B");
            EnosixStyles.Theme.PrimaryColor       = Color.FromHex("CC2F86");
            EnosixStyles.Theme.LightPrimaryColor  = Color.FromHex("F8BBD0");
            EnosixStyles.Theme.AccentColor        = Color.FromHex("C2185B");
            EnosixStyles.Theme.AltTextColor       = Color.White;
            EnosixStyles.Theme.SecondaryTextColor = Color.FromHex("808285");
            //clears navigation screen
            NavigationItems.Clear();
            //adds settings and messages item too navigation menu
            NavigationItems.Add(new SettingsNavigationItem());
            NavigationItems.Add(messagesNavigationItem = new SAPMessageNavigationItem(this)
            {
                Title = "Messages",
            });

            //sets the navigation menu page as the startup page
            var menu = new NavigationMenu();

            MainPage = menu;

            // service order page logic
            menu.sOrder = new ServiceOrderTimeEntryListPage()
            {
                BindingContext      = (_serviceOrderList = new ServiceOrderListViewModel(this)),
                ItemSelectedCommand = new Command <ServiceOrderListViewModel.ServiceOrderListItemViewModel>(ShowDetailPage, item => null != item),
            };
        }
示例#22
0
        static void Main(string[] args)
        {
            var mainMenu = new NavigationMenu()
            {
                Header    = "Main Menu",
                MenuItems = new List <MenuItem>()
                {
                    new MenuItem()
                    {
                        Command      = "A",
                        MenuItemLine = "First Command",
                        MethodToCall = DoAnAction
                    },
                    new MenuItem()
                    {
                        Command      = "B",
                        MenuItemLine = "Second Command",
                        MethodToCall = DoAnAction,
                        SubMenu      = null
                    }
                }
            };

            mainMenu.DoMenu();
        }
    // Start is called before the first frame update
    void Start()
    {
        instance = this;
        gameObject.SetActive(false);
        worldNodes = new List <WorldNode>();

        WorldNode temp;


        /*
         * temp = Instantiate<WorldNode>(prefab, worldContainer.transform);
         * temp.SetUp(WorldType.Tundra);
         * worldNodes.Add(temp);
         *
         * temp = Instantiate<WorldNode>(prefab, worldContainer.transform);
         * temp.SetUp(WorldType.Lava);
         * worldNodes.Add(temp);
         *
         * temp = Instantiate<WorldNode>(prefab, worldContainer.transform);
         * temp.SetUp(WorldType.Purple);
         * worldNodes.Add(temp);
         *
         * temp = Instantiate<WorldNode>(prefab, worldContainer.transform);
         * temp.SetUp(WorldType.Yellow);
         * worldNodes.Add(temp);
         */


        //SetMaps();
        //RollMaps();


        //LevelManager.instance.completedWorlds = new bool[worldNodes.Count];
        defaultObject = backButton.gameObject;
    }
示例#24
0
        public ExploderViewModel(CalendarGraph CalendarGraph) ///, IEnumerable<Element> Path
        {
            if (CalendarGraph == null)
            {
                return;
            }
            this.CalendarGraph = CalendarGraph;

            int i = CalendarGraph.ActiveElement.Depth;

            NavigationMenu.Add(CalendarGraph.ActiveElement);
            var cursor = CalendarGraph.ActiveElement.Parent;

            if (cursor != null)
            {
                while (cursor.Id != -1)
                {
                    NavigationMenu.Add(cursor);

                    cursor = cursor.Parent;
                    if (cursor == null)
                    {
                        break;
                    }
                }
            }



            SelectedElement = CalendarGraph.ActiveElement;
        }
示例#25
0
        public NewRecordState(Game1 game, GraphicsDevice graphicsDevice, ContentManager content) : base(game, graphicsDevice, content)
        {
            champ = Champion.GetInstance();
            var buttonTexture = _content.Load <Texture2D>("Components/Button");

            _font = _content.Load <SpriteFont>("Components/Font");

            var submitButton = new Button(buttonTexture, _font)
            {
                Position = new Vector2(550, 570),
                Text     = "Submit your score"
            };

            var backButton = new Button(buttonTexture, _font)
            {
                Position = new Vector2(550, 570),
                Text     = "Go to main menu"
            };

            _components           = new List <Component>();
            backButton.OnClick   += BackButton_Click;
            submitButton.OnClick += SubmitButton_Click;
            navigationMenu        = new NavigationMenu(new List <Component>
            {
                backButton,
                submitButton
            });
            _components = new List <Component>()
            {
                navigationMenu
            };

            var list = RankingFile.getPlacements();

            if (list.Count < 10 || list[list.Count - 1].score < champ.points)
            {
                navigationMenu = new NavigationMenu(new List <Component>
                {
                    submitButton
                });
                _components = new List <Component>()
                {
                    navigationMenu
                };
                isNewRecord = true;
            }
            else
            {
                navigationMenu = new NavigationMenu(new List <Component>
                {
                    backButton
                });
                _components = new List <Component>()
                {
                    navigationMenu
                };
                isNewRecord = false;
            }
        }
        public List <NavigationMenu> LoadControlData(int selectedMenu)
        {
            var results = NavigationMenu.SelectMenuItem(selectedMenu, this.Page);

            this.DataListNavigationMenu.DataSource = results;
            this.DataListNavigationMenu.DataBind();
            return(results);
        }
示例#27
0
        public void ReturnsAModel()
        {
            IItem item = new TestItem("test");
            NavigationModelBuilder navModelBuilder = new NavigationModelBuilder();
            NavigationMenu         model           = navModelBuilder.CreateNavigationMenu(item, item);

            Assert.AreNotEqual(model, null);
        }
示例#28
0
        protected void SetNavigtionMenu()
        {
            var results = this.NavigationPanelNonRev.LoadControlData((int)MenuType.MenuMultiViewA);
            int index   = NavigationMenu.GetMinimumIndex(results);

            this.MultiViewNonRev.ActiveViewIndex = index;
            this.NavigationPanelNonRev.SetMenuStyle(this.MultiViewNonRev.ActiveViewIndex);
        }
示例#29
0
        public void OpenNavigation3()
        {
            //TODO: ожидается другой Exception
            Assert.Throws(typeof(Exception), () => { NavigationMenu.OpenPage("Бюджетные планы"); },
                          "Ожидалось, что пользователю будет не доступна вкладка \"Бюджетные планы\"");

            PageValidation.CheckUrl("/Home");
        }
示例#30
0
        public async Task AddNavigationMenuAsync(NavigationMenu menu)
        {
            ValidationTool.Validate(typeof(NavigateMenuValidator), menu);

            await _uow.NavigationMenuRepo.InsertAsync(menu);

            await _uow.SaveChangesAsync();
        }
示例#31
0
        public void ValidateItemByUserRoles_item_is_null_should_return_false()
        {
            // Arrange
            var myNavigationMenu = new NavigationMenu();
            XElement item = null;
            bool expected = false;

            // Act
            bool result = myNavigationMenu.ValidateItemByUserRoles(item);

            // Assert
            Assert.AreEqual(expected, result, "NavigationMenu.ValidateItemByUserRoles did not return the expected value of {0}", expected);
        }
示例#32
0
        public void ValidateItemByUserRoles_itemAttributeRoles_is_stringEmpty_should_return_false()
        {
            // Arrange
            var myNavigationMenu = new NavigationMenu();
            var item = new XElement("ElementName", new XAttribute("roles", string.Empty));
            bool expected = false;

            // Act
            bool result = myNavigationMenu.ValidateItemByUserRoles(item);

            // Assert
            Assert.AreEqual(expected, result, "NavigationMenu.ValidateItemByUserRoles did not return the expected value of {0}", expected);
        }
示例#33
0
        public void ValidateItemByUserRoles_LoggedOut_AboutHelp_ReportAProblem_Should_Be_Visible()
        {
            using(ShimsContext.Create())
            {
                // Arrange
                var myNavigationMenu = new NavigationMenu();
                XElement root = XElement.Load(ProductionCodeXMLFileLocation);
                IEnumerable<XElement> mainMenuItemAboutHelp =
                    from el in root.Elements("menuitem")
                    where (string)el.Attribute("value") == "AboutHelp"
                    select el;

                if (!mainMenuItemAboutHelp.Any())
                {
                    Assert.Fail("Unable to find the About/Help main menu item");
                }

                IEnumerable<XElement> itemsNode =
                    from el in mainMenuItemAboutHelp.First().Elements("items")
                    select el;

                if (!itemsNode.Any())
                {
                    Assert.Fail("Unable to find the items nodes inside the About/Help main menu item");
                }

                IEnumerable<XElement> reportProblemNode =
                    from el in itemsNode.First().Elements("menuitem")
                    where (string)el.Attribute("value") == "ReportProblem"
                    select el;

                if (!reportProblemNode.Any())
                {
                    Assert.Fail("Unable to find the ReportProblem value inside the About/Help main menu item");
                }

                bool expected = true;

                var fakeCurrentUser = new ShimCurrentUser();
                fakeCurrentUser.IsAuthenticatedGet = () => false;

                // Fake call to CurrentUser.GetInstance()
                ShimCurrentUser.GetInstance = () => fakeCurrentUser;

                // Act
                bool result = myNavigationMenu.ValidateItemByUserRoles(reportProblemNode.First());

                // Assert
                Assert.AreEqual(expected, result, "NavigationMenu.ValidateItemByUserRoles did not return the expected value of {0}", expected);
            }
        }