protected override void beforeEach() { theChain = new BehaviorChain(); theChain.Route = new RouteDefinition("something") { Input = new RouteInput <FakeInput>("somepattern") }; theNode = new MenuNode(FakeKeys.Key1, r => theChain); theNode.Resolve(null); theNode.BehaviorChain.ShouldBeTheSameAs(theChain); theNode.UrlInput = new object(); theNode.Children.AddToEnd(new MenuNode(FakeKeys.Key2)); theNode.Children.AddToEnd(new MenuNode(FakeKeys.Key3)); theNode.Children.AddToEnd(new MenuNode(FakeKeys.Key4)); MockFor <IMenuStateService>().Stub(x => x.DetermineStateFor(theNode)) .Return(MenuItemState.Available); MockFor <IChainUrlResolver>().Stub(x => x.UrlFor(theNode.UrlInput, theNode.BehaviorChain)) .Return("the full url"); theToken = ClassUnderTest.BuildToken(theNode); }
private void setActiveState(MenuItemToken item) { if (item.MenuItemState == MenuItemState.Active) { AddClass("active"); } }
private static void setDisabledState(MenuItemToken item, HtmlTag link) { if (item.MenuItemState == MenuItemState.Disabled) { link.AddClass("disabled"); } }
protected override void beforeEach() { theChain = new BehaviorChain(); theChain.Route = new RouteDefinition("something") { Input = new RouteInput <FakeInput>("somepattern") }; theNode = new MenuNode(FakeKeys.Key1, r => theChain); theNode.Resolve(null); theNode.BehaviorChain.ShouldBeTheSameAs(theChain); theNode.UrlInput = new object(); theNode.Icon("some image"); theNode.Children.AddToEnd(new MenuNode(FakeKeys.Key2)); theNode.Children.AddToEnd(new MenuNode(FakeKeys.Key3)); theNode.Children.AddToEnd(new MenuNode(FakeKeys.Key4)); theUrls = new StubUrlRegistry(); Services.Inject <IUrlRegistry>(theUrls); MockFor <IMenuStateService>().Stub(x => x.DetermineStateFor(theNode)) .Return(MenuItemState.Available); MockFor <ICurrentHttpRequest>().Stub(x => x.ToFullUrl(theNode.CreateUrl())) .Return("the full url"); theToken = ClassUnderTest.BuildToken(theNode); }
public void SetUp() { theItem = new MenuItemToken{ Key = "some key", Text = "some text", MenuItemState = MenuItemState.Available }; }
private HtmlTag buildLink(MenuItemToken item) { var link = Add("a").Append(new LiteralTag(item.Text)); link.Data("key", item.Key); string linkUrl = item.Url.IsNotEmpty() ? item.Url : "#"; link.Attr("href", linkUrl); return link; }
public void value_continuation_for_non_existing_value() { var token = new MenuItemToken(); var invoked = false; token.Value <Guid>("key", x => invoked = true); invoked.ShouldBeFalse(); }
public void get_data() { var token = new MenuItemToken(); var value = Guid.NewGuid(); token.Data.Add("Test", value); token.Get<Guid>("Test").ShouldBe(value); }
public void has_data() { var token = new MenuItemToken(); var value = Guid.NewGuid(); token.Data.Add("Test", value); token.Has("Test").ShouldBeTrue(); }
public void value_continuation_for_existing_value() { var token = new MenuItemToken(); var expected = Guid.NewGuid(); token.Set("key", expected); token.Value <Guid>("key", x => x.ShouldEqual(expected)); }
public void value_continuation_for_non_existing_value() { var token = new MenuItemToken(); var invoked = false; token.Value<Guid>("key", x => invoked = true); invoked.ShouldBeFalse(); }
public void get_data() { var token = new MenuItemToken(); var value = Guid.NewGuid(); token.Data.Add("Test", value); token.Get <Guid>("Test").ShouldEqual(value); }
public void value_continuation_for_existing_value() { var token = new MenuItemToken(); var expected = Guid.NewGuid(); token.Set("key", expected); token.Value<Guid>("key", x => x.ShouldBe(expected)); }
private void writeChildren(MenuItemToken item, HtmlTag link) { link.AddClass("dropdown-toggle"); link.Attr("data-toggle", "dropdown"); link.Add("b").AddClass("caret"); var ul = Add("ul").AddClass("dropdown-menu"); item.Children.Each(child => { var childTag = new MenuItemTag(child); ul.Append(childTag); }); }
public MenuItemTag(MenuItemToken item) : base("li") { _item = item; if (item.MenuItemState == MenuItemState.Hidden) { Render(false); return; } var link = buildLink(item); if (item.Children.Any()) { writeChildren(item, link); } setActiveState(item); setDisabledState(item, link); }
// TODO -- this could really use some more end to end testing public MenuItemToken BuildToken(MenuNode node) { var token = new MenuItemToken { Children = node.Children.Select(BuildToken).ToArray(), Key = node.Key.Key, Text = node.Key.ToString(), Category = node.Category, MenuItemState = _stateService.DetermineStateFor(node) }; if (node.Icon().IsNotEmpty()) { token.IconUrl = _urls.UrlForAsset(AssetFolder.images, node.Icon()); } if (node.Type == MenuNodeType.Leaf) { token.Url = _urlResolver.UrlFor(node.UrlInput, node.BehaviorChain); } node.ForData(token.Set); return token; }