public void MisnamedAttributeMenuItemParseIgnored() { //Arrange string testXml = @" <menu> <item> <displayName>Home</displayName> <path value='/Default.aspx'/> </item> <item> <displayName>Misnamed path</displayName> <path wrongvalue='/Default.aspx'/> </item> </menu>"; XPathDocument testInput = CreateXmLDocument(testXml); //Act MenuParser menu = new MenuParser("/Default.aspx"); bool result = menu.Parse(testInput); //Assert Assert.IsNotNull(menu); Assert.IsTrue(result); Assert.IsTrue(1 == menu.Items.Count); }
public void ParseMenuExample1Success() { //Arrange // This test covers just the basis that parsing happens successfully. string testXml = @"<menu> <item> <displayName>Home</displayName> <path value='/Default.aspx'/> </item> <item> <displayName>Trips</displayName> <path value='/Requests/Quotes/CreateQuote.aspx'/> <subMenu> <item> <displayName>Create Quote</displayName> <path value='/Requests/Quotes/CreateQuote.aspx'/> </item> <item> <displayName>Open Quotes</displayName> <path value='/Requests/OpenQuotes.aspx'/> </item> <item superOverride='true'> <displayName>Scheduled Trips</displayName> <path value='/Requests/Trips/ScheduledTrips.aspx'/> </item> </subMenu> </item> <item> <displayName>Company</displayName> <path value='/mvc/company/view' /> <subMenu> <item> <displayName>Customers</displayName> <path value='/customers/customers.aspx'/> </item> <item> <displayName>Pilots</displayName> <path value='/pilots/pilots.aspx'/> </item> <item> <displayName>Aircraft</displayName> <path value='/aircraft/Aircraft.aspx'/> </item> </subMenu> </item> </menu>"; XPathDocument testInput = CreateXmLDocument(testXml); //Act MenuParser menu = new MenuParser("/Requests/OpenQuotes.aspx"); bool result = menu.Parse(testInput); //Assert Assert.IsNotNull(menu); Assert.IsTrue(result); }
public void Puzzle2() { var exampleInput = new FileReader() .GetResource("AdventOfCode2020.Tests.Day21.PuzzleInput.txt"); var menu = MenuParser.Parse(exampleInput); var foodsWithNoAllergens = menu.GetFoodWithAllergens(); var odered = string.Join(",", foodsWithNoAllergens.OrderBy(x => x.Key).Select(x => x.Value.Name)); Assert.Equal("lkv,lfcppl,jhsrjlj,jrhvk,zkls,qjltjd,xslr,rfpbpn", odered); }
public void Puzzle1() { var exampleInput = new FileReader() .GetResource("AdventOfCode2020.Tests.Day21.PuzzleInput.txt"); var menu = MenuParser.Parse(exampleInput); var foodsWithNoAllergens = menu.GetFoodWithNoAllergens().Select(x => x.Name); var count = menu.GetInstances(foodsWithNoAllergens); Assert.Equal(2779, count); }
static MenuParser ParseXmlMenuFile(string filePath, string activePath) { FileStream file = new FileStream(filePath, FileMode.Open); XPathDocument xpath = new XPathDocument(file); MenuParser menus = new MenuParser(activePath); menus.Parse(xpath); return(menus); }
public void FindAtThreeDeepSuccess() { //Arrange // To test for matching paths in root and submenus string testXml = @" <menu> <item> <displayName>Home</displayName> <path value='/Default.aspx'/> </item> <item> <displayName>Trips</displayName> <path value='/Requests/Quotes/CreateQuote.aspx'/> <subMenu> <item superOverride='true'> <displayName>Scheduled Trips</displayName> <path value='/Requests/Trips/ScheduledTrips.aspx'/> </item> <item> <displayName>Open Quotes</displayName> <path value='/Requests/OpenQuotes.aspx'/> <subMenu> <item superOverride='true'> <displayName>Scheduled Trips</displayName> <path value='/Requests/Trips/ScheduledTrips.aspx'/> </item> <item> <displayName>Open Quotes at leaf</displayName> <path value='/Default.aspx'/> </item> </subMenu> </item> </subMenu> </item> </menu>"; XPathDocument testInput = CreateXmLDocument(testXml); //Act MenuParser menu = new MenuParser("/Requests/Trips/ScheduledTrips.aspx"); bool result = menu.Parse(testInput); List <MenuNode> found = menu.FindAll(x => x.Path.Equals("/Requests/Trips/ScheduledTrips.aspx")); //Assert // The following is not an idea Unit test construction because it assumes knowledge of what is being tested. // That is a fault of the abstraction being incomplete. This is solved by providing an acces abstraction, // such as an iterator so the individual menu items can be retrieved with operations. too complex for this // code exercise but would definatately be needed for production use - just in general. Assert.IsNotNull(menu); Assert.IsTrue(2 == found.Count); Assert.AreSame(menu.Items [1].SubMenu[0], found[0]); Assert.AreSame(menu.Items [1].SubMenu[1].SubMenu[0], found[1]); }
public void Example1() { const string input = @"mxmxvkd kfcds sqjhc nhms (contains dairy, fish) trh fvjkl sbzzf mxmxvkd (contains dairy) sqjhc fvjkl (contains soy) sqjhc mxmxvkd sbzzf (contains fish)"; var menu = MenuParser.Parse(input); var foodsWithNoAllergens = menu.GetFoodWithNoAllergens().Select(x => x.Name); var count = menu.GetInstances(foodsWithNoAllergens); Assert.Equal(5, count); }
public void ActiveMenuThreeDeepSuccess() { //Arrange // To test for active paths in root and submenus string testXml = @" <menu> <item> <displayName>Home</displayName> <path value='/NotDefault.aspx'/> </item> <item> <displayName>Trips</displayName> <path value='/Requests/Quotes/CreateQuote.aspx'/> <subMenu> <item superOverride='true'> <displayName>Scheduled Trips</displayName> <path value='/Requests/Trips/ScheduledTrips.aspx'/> </item> <item> <displayName>Open Quotes</displayName> <path value='/Requests/OpenQuotes.aspx'/> <subMenu> <item superOverride='true'> <displayName>Scheduled Trips</displayName> <path value='/Requests/Trips/ScheduledTrips.aspx'/> </item> <item> <displayName>Open Quotes at leaf</displayName> <path value='/Default.aspx'/> </item> </subMenu> </item> </subMenu> </item> </menu>"; XPathDocument testInput = CreateXmLDocument(testXml); //Act MenuParser menu = new MenuParser("/Default.aspx"); bool result = menu.Parse(testInput); List <MenuNode> found = menu.FindAll(x => true == x.Active); //Assert Assert.IsNotNull(menu); Assert.IsTrue(3 == found.Count); Assert.IsTrue(found[0].Name.Equals("Trips")); Assert.IsTrue(found[1].Name.Equals("Open Quotes")); Assert.IsTrue(found[2].Name.Equals("Open Quotes at leaf")); }
public void Puzzle2Example1() { const string input = @"mxmxvkd kfcds sqjhc nhms (contains dairy, fish) trh fvjkl sbzzf mxmxvkd (contains dairy) sqjhc fvjkl (contains soy) sqjhc mxmxvkd sbzzf (contains fish)"; var menu = MenuParser.Parse(input); var foodsWithNoAllergens = menu.GetFoodWithAllergens(); var odered = string.Join(",", foodsWithNoAllergens.OrderBy(x => x.Key).Select(x => x.Value.Name)); Assert.Equal("mxmxvkd,sqjhc,fvjkl", odered); }
public void EmptyMenuParseSuccessAndReturnsFalse() { //Arrange string testXml = @" <menu> </menu>"; XPathDocument testInput = CreateXmLDocument(testXml); //Act MenuParser menu = new MenuParser("/Default.aspx"); bool result = menu.Parse(testInput); //Assert Assert.IsNotNull(menu); Assert.IsFalse(result); }
public void EmptySingleMenuItemParseFails() { //Arrange string testXml = @" <menu> <item> </item> </menu>"; XPathDocument testInput = CreateXmLDocument(testXml); //Act MenuParser menu = new MenuParser("/Default.aspx"); bool result = menu.Parse(testInput); //Assert Assert.IsNotNull(menu); Assert.IsFalse(result); }
public void SingleMenuParseSuccess() { //Arrange string testXml = @" <menu> <item> <displayName>Home</displayName> <path value='/Default.aspx'/> </item> </menu>"; XPathDocument testInput = CreateXmLDocument(testXml); //Act MenuParser menu = new MenuParser("/Default.aspx"); bool result = menu.Parse(testInput); //Assert Assert.IsNotNull(menu); Assert.IsTrue(result); }