public void BuildModel_Case3_CurrentNodeNotVisible_StartingNodeInChildLevel_NotShowStartingNode_visibilityAffectsDescendants_ShouldReturn0Nodes() { // Html.MvcSiteMap().Menu(null, Html.MvcSiteMap().SiteMap.CurrentNode, true, false, int32.MaxValue, false, true, new SourceMetadataDictionary()) // Arrange var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase3(); ((FakeSiteMap)siteMap).SetCurrentNode(siteMap.FindSiteMapNode("/Root/AB")); var startingNode = siteMap.CurrentNode; HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object); MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false); // Act var result = MenuHelper.BuildModel( helper: helperExtension, sourceMetadata: new SourceMetadataDictionary(), startingNode: startingNode, startingNodeInChildLevel: true, showStartingNode: false, maxDepth: Int32.MaxValue, drillDownToCurrent: false, visibilityAffectsDescendants: true); // Check counts Assert.AreEqual(0, result.Nodes.Count); }
public void BuildModel_Case1_StartingNodeNotInChildLevel_ShouldReturnHierarchicalNodes() { // @Html.MvcSiteMap().Menu(true, false, true) // Arrange var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase1(); var startingNode = siteMap.RootNode; HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object); MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false); // Act var result = MenuHelper.BuildModel( helper: helperExtension, sourceMetadata: new SourceMetadataDictionary(), startingNode: startingNode, startingNodeInChildLevel: false, showStartingNode: true, maxDepth: Int32.MaxValue, drillDownToCurrent: false, visibilityAffectsDescendants: true); // Assert // Tree structure - 3 nodes Assert.AreEqual("Home", result.Nodes[0].Title); Assert.AreEqual("About", result.Nodes[0].Children[0].Title); Assert.AreEqual("Contact", result.Nodes[0].Children[1].Title); // Check Counts Assert.AreEqual(1, result.Nodes.Count); Assert.AreEqual(2, result.Nodes[0].Children.Count); Assert.AreEqual(0, result.Nodes[0].Children[0].Children.Count); Assert.AreEqual(0, result.Nodes[0].Children[1].Children.Count); }
public void BuildModel_Case3_CurrentNodeNotVisible_StartingNodeInChildLevel_NotShowStartingNode_MaxDepth2_visibilityNotAffectsDescendants_ShouldReturn2Nodes() { // Start at /Root/AD // Expect a list of all visible children and visible grandchildren of invisible children but not any great grandchildren of /Root/AD (2 nodes) // Html.MvcSiteMap().Menu(null, Html.MvcSiteMap().SiteMap.CurrentNode, true, false, 2, false, false, new SourceMetadataDictionary()) // Arrange var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase3(); ((FakeSiteMap)siteMap).SetCurrentNode(siteMap.FindSiteMapNode("/Root/AD")); var startingNode = siteMap.CurrentNode; HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object); MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false); // Act var result = MenuHelper.BuildModel( helper: helperExtension, sourceMetadata: new SourceMetadataDictionary(), startingNode: startingNode, startingNodeInChildLevel: true, showStartingNode: false, maxDepth: 2, drillDownToCurrent: false, visibilityAffectsDescendants: false); // Assert Assert.AreEqual("ADB", result.Nodes[0].Title); Assert.AreEqual("ADC", result.Nodes[1].Title); // Check counts Assert.AreEqual(2, result.Nodes.Count); Assert.AreEqual(0, result.Nodes[0].Children.Count); Assert.AreEqual(0, result.Nodes[1].Children.Count); }
public void BuildModel_Case2_StartingNodeNotInChildLevel_MaxDepth1_ShouldReturnHierarchialNodesTo1Levels() { // @Html.MvcSiteMap().Menu(0, false, true, 2) // Arrange var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase2(); var startingNode = siteMap.RootNode; HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object); MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false); // Act var result = MenuHelper.BuildModel( helper: helperExtension, sourceMetadata: new SourceMetadataDictionary(), startingNode: startingNode, startingNodeInChildLevel: false, showStartingNode: true, maxDepth: 1, drillDownToCurrent: false, visibilityAffectsDescendants: true); // Assert Assert.AreEqual("Home", result.Nodes[0].Title); Assert.AreEqual("About", result.Nodes[0].Children[0].Title); // "Contact" is inaccessible - should be skipped. So should its child node "ContactSomebody". Assert.AreEqual("Categories", result.Nodes[0].Children[1].Title); // Check counts Assert.AreEqual(1, result.Nodes.Count); Assert.AreEqual(2, result.Nodes[0].Children.Count); // Home Assert.AreEqual(0, result.Nodes[0].Children[0].Children.Count); // About Assert.AreEqual(0, result.Nodes[0].Children[1].Children.Count); // Categories }
public void BuildModel_Case1_Default_ShouldReturnAllNodesAtRootLevel() { // @Html.MvcSiteMap().SiteMap() // Arrange var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase1(); var startingNode = siteMap.RootNode; HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object); MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false); // Act var result = SiteMapHelper.BuildModel( helper: helperExtension, sourceMetadata: new SourceMetadataDictionary(), startingNode: startingNode, startingNodeInChildLevel: true, visibilityAffectsDescendants: true); // Assert // Flat structure - 3 nodes Assert.AreEqual("Home", result.Nodes[0].Title); Assert.AreEqual("About", result.Nodes[1].Title); Assert.AreEqual("Contact", result.Nodes[2].Title); // Check counts Assert.AreEqual(3, result.Nodes.Count); Assert.AreEqual(0, result.Nodes[0].Children.Count); Assert.AreEqual(0, result.Nodes[1].Children.Count); Assert.AreEqual(0, result.Nodes[2].Children.Count); }
public void BuildModel_Case2_StartingNodeNotInChildLevel_ShouldReturnHierarchicalNodes() { // @Html.MvcSiteMap().Menu(false) // Arrange var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase2(); var startingNode = siteMap.RootNode; HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object); MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false); // Act var result = SiteMapHelper.BuildModel( helper: helperExtension, sourceMetadata: new SourceMetadataDictionary(), startingNode: startingNode, startingNodeInChildLevel: false, visibilityAffectsDescendants: true); // Assert Assert.AreEqual("Home", result.Nodes[0].Title); Assert.AreEqual("About", result.Nodes[0].Children[0].Title); Assert.AreEqual("About Me", result.Nodes[0].Children[0].Children[0].Title); Assert.AreEqual("About You", result.Nodes[0].Children[0].Children[1].Title); // "Contact" is inaccessible - should be skipped. So should its child node "ContactSomebody". Assert.AreEqual("Categories", result.Nodes[0].Children[1].Title); Assert.AreEqual("Cameras", result.Nodes[0].Children[1].Children[0].Title); Assert.AreEqual("Nikon Coolpix 200", result.Nodes[0].Children[1].Children[0].Children[0].Title); Assert.AreEqual("Canon Ixus 300", result.Nodes[0].Children[1].Children[0].Children[1].Title); // "Memory Cards" is not visible. None of its children should be visible. Assert.AreEqual(1, result.Nodes[0].Children[1].Children.Count); }
public void BuildModel_Case2_StartingNodeNotInChildLevel_VisibilyDoesntAffectDescendants_ShouldReturnHierarchialNodes() { // @Html.MvcSiteMap().Menu(true, false, true, false) // Arrange var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase2(); var startingNode = siteMap.RootNode; HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object); MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false); // Act var result = MenuHelper.BuildModel( helper: helperExtension, sourceMetadata: new SourceMetadataDictionary(), startingNode: startingNode, startingNodeInChildLevel: false, showStartingNode: true, maxDepth: Int32.MaxValue, drillDownToCurrent: false, visibilityAffectsDescendants: false); // Assert Assert.AreEqual("Home", result.Nodes[0].Title); Assert.AreEqual("About", result.Nodes[0].Children[0].Title); Assert.AreEqual("About Me", result.Nodes[0].Children[0].Children[0].Title); Assert.AreEqual("About You", result.Nodes[0].Children[0].Children[1].Title); // "Contact" is inaccessible - should be skipped. So should its child node "ContactSomebody". Assert.AreEqual("Categories", result.Nodes[0].Children[1].Title); Assert.AreEqual("Cameras", result.Nodes[0].Children[1].Children[0].Title); Assert.AreEqual("Nikon Coolpix 200", result.Nodes[0].Children[1].Children[0].Children[0].Title); Assert.AreEqual("Canon Ixus 300", result.Nodes[0].Children[1].Children[0].Children[1].Title); // "Memory Cards" is not visible. However its children should be in its place. Assert.AreEqual("Kingston 256 GB SD", result.Nodes[0].Children[1].Children[1].Title); Assert.AreEqual("Sony 256 GB SD", result.Nodes[0].Children[1].Children[2].Title); Assert.AreEqual("Sony SD Card Reader", result.Nodes[0].Children[1].Children[2].Children[0].Title); // Check counts Assert.AreEqual(1, result.Nodes.Count); Assert.AreEqual(2, result.Nodes[0].Children.Count); // Home Assert.AreEqual(2, result.Nodes[0].Children[0].Children.Count); // About Assert.AreEqual(0, result.Nodes[0].Children[0].Children[0].Children.Count); // About Me Assert.AreEqual(0, result.Nodes[0].Children[0].Children[1].Children.Count); // About You Assert.AreEqual(3, result.Nodes[0].Children[1].Children.Count); // Categories Assert.AreEqual(2, result.Nodes[0].Children[1].Children[0].Children.Count); // Cameras Assert.AreEqual(0, result.Nodes[0].Children[1].Children[0].Children[0].Children.Count); // Nikon Coolpix 200 Assert.AreEqual(0, result.Nodes[0].Children[1].Children[0].Children[1].Children.Count); // Canon Ixus 300 Assert.AreEqual(0, result.Nodes[0].Children[1].Children[1].Children.Count); // Kingston 256 GB SD Assert.AreEqual(1, result.Nodes[0].Children[1].Children[2].Children.Count); // Sony 256 GB SD Assert.AreEqual(0, result.Nodes[0].Children[1].Children[2].Children[0].Children.Count); // Sony SD Card Reader }