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); }
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); } }
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); }