public MenuSerializationTests()
        {
            Mock<HtmlTextWriter> htmlWriter = new Mock<HtmlTextWriter>(TextWriter.Null);

            textWriter = new Mock<TextWriter>();
            textWriter.Setup(tw => tw.Write(It.IsAny<string>())).Callback<string>(s => output += s);

            menu = MenuTestHelper.CreateMenu(htmlWriter.Object, null);
            menu.Name = "myMenu";
        }
예제 #2
0
        public MenuRenderingTests()
        {
            Mock<HtmlTextWriter> writer = new Mock<HtmlTextWriter>(TextWriter.Null);

            builder = new Mock<INavigationComponentHtmlBuilder<MenuItem>>();
            builder.Setup(b => b.Build()).Returns(() => new HtmlElement("ul"));
            builder.Setup(r => r.ItemTag(It.IsAny<MenuItem>())).Returns(() => new HtmlElement("li"));
            builder.Setup(r => r.ItemInnerContentTag(It.IsAny<MenuItem>(), It.IsAny<bool>())).Returns(() => new HtmlElement("a"));
            builder.Setup(r => r.ChildrenTag(It.IsAny<MenuItem>())).Returns(() => new HtmlElement("ul"));

            menu = MenuTestHelper.CreateMenu(writer.Object, builder.Object);
            menu.Name = "Menu";

            menu.Items.Add(new MenuItem { Text = "MenuItem1" });
            menu.Items.Add(new MenuItem { Text = "MenuItem2" });
            menu.Items.Add(new MenuItem { Text = "MenuItem3" });
        }
예제 #3
0
        public static Menu CreateMenu(HtmlTextWriter writer, INavigationComponentHtmlBuilder<MenuItem> renderer)
        {
            Mock<HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext();

            if (writer != null)
            {
                httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny<TextWriter>())).Returns(writer);
            }

            Mock<INavigationComponentHtmlBuilderFactory<Menu, MenuItem>> menuRendererFactory = new Mock<INavigationComponentHtmlBuilderFactory<Menu, MenuItem>>();

            Mock<IViewDataContainer> viewDataContainer = new Mock<IViewDataContainer>();
            var viewDataDinctionary = new ViewDataDictionary();
            viewDataDinctionary.Add("sample", TestHelper.CreateXmlSiteMap());

            viewDataContainer.SetupGet(container => container.ViewData).Returns(viewDataDinctionary);

            // needed for testing serialization
            Mock<ClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock<ClientSideObjectWriterFactory>();

            UrlGenerator urlGeneratorObject = new UrlGenerator();
            Mock<INavigationItemAuthorization> authorization = new Mock<INavigationItemAuthorization>();

            TestHelper.RegisterDummyRoutes();

            ViewContext viewContext = TestHelper.CreateViewContext();
            viewContext.ViewData = viewDataDinctionary;

            authorization.Setup(a => a.IsAccessibleToUser(viewContext.RequestContext, It.IsAny<INavigatable>())).Returns(true);

            Menu menu = new Menu(viewContext, clientSideObjectWriterFactory.Object, urlGeneratorObject, authorization.Object, menuRendererFactory.Object);

            renderer = renderer ?? new MenuHtmlBuilder(menu, new Mock<IActionMethodCache>().Object);
            menuRendererFactory.Setup(f => f.Create(It.IsAny<Menu>())).Returns(renderer);

            return menu;
        }
예제 #4
0
 public MenuBuilderTests()
 {
     Mock<HtmlTextWriter> writer = new Mock<HtmlTextWriter>(TextWriter.Null);
     menu = MenuTestHelper.CreateMenu(writer.Object, null);
     builder = new MenuBuilder(menu);
 }