public void Can_Generate_Page_Links()
        {
            // Arrange
            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>()))
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");
            var urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory.Setup(f => f.GetUrlHelper(It.IsAny <ActionContext>())).Returns(urlHelper.Object);
            PageLinkTagHelper helper = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                PageModel = new PagingInfo
                {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"
            };
            TagHelperContext ctx    = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), "");
            var             content = new Mock <TagHelperContent>();
            TagHelperOutput output  = new TagHelperOutput("div", new TagHelperAttributeList(), (cache, encoder) => Task.FromResult(content.Object));

            // Act
            helper.Process(ctx, output);
            // Assert
            Assert.Equal(@"<a href=""Test/Page1"">1</a>" + @"<a href=""Test/Page2"">2</a>" + @"<a href=""Test/Page3"">3</a>", output.Content.GetContent());
        }
        public void Test1()
        {
            // Arrange
            var helper = new PageLinkTagHelper(new UrlHelperFactory());

            //var x = helper.CreateTag(1, helper);
        }
        private static PageLinkTagHelper GetTagHelper(int page, int itemsPerPage, int totalItems, string href = "")
        {
            var urlHelper = A.Fake <IUrlHelper>();

            A.CallTo(() => urlHelper.Action(new UrlActionContext()))
            .WithAnyArguments()
            .Returns(href);

            var urlHelperFactory = A.Fake <IUrlHelperFactory>();

            A.CallTo(() =>
                     urlHelperFactory.GetUrlHelper(new ActionContext()))
            .WithAnyArguments()
            .Returns(urlHelper);

            var tagHelper = new PageLinkTagHelper(urlHelperFactory)
            {
                PageModel = new ViewModels.PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = itemsPerPage,
                    TotalItems   = totalItems
                }
            };

            return(tagHelper);
        }
        public void Can_Generate_Page_Links()
        {
            //przygotowanie
            Mock <IUrlHelper> urlHelper = new Mock <IUrlHelper>();

            urlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>())).Returns("Test/Page1").Returns("Test/Page2").Returns("Test/Page3");

            Mock <IUrlHelperFactory> urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory.Setup(f => f.GetUrlHelper(It.IsAny <ActionContext>())).Returns(urlHelper.Object);

            PageLinkTagHelper pageLinkTagHelper = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                Pagination = new PaginationInfo()
                {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"
            };

            TagHelperContext tagHelperContext = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), "");

            Mock <TagHelperContent> tagHelperContent = new Mock <TagHelperContent>();
            TagHelperOutput         output           = new TagHelperOutput("div", new TagHelperAttributeList(), (cache, encoder) => Task.FromResult(tagHelperContent.Object));

            //działanie
            pageLinkTagHelper.Process(tagHelperContext, output);

            //Assercje
            Assert.Equal(@"<a href=""Test/Page1"">1</a><a href=""Test/Page2"">2</a><a href=""Test/Page3"">3</a>", output.Content.GetContent());
        }
Exemplo n.º 5
0
        public void Can_Generate_Page_Links()
        {
            // Arrange
            // макет построителя гиперссылок
            var urlHelper = new Mock <IUrlHelper> ();

            // когда у построителя гиперссылок
            // будет вызван како-либо метод, типизированный UrlActionContext,
            urlHelper.SetupSequence(x =>
                                    x.Action(It.IsAny <UrlActionContext> ()))
            // - вернуть список строк с адресами
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");
            // настройка макета фабрики генераторов адресов на выдачу
            // выше определенного макета с заданным ему списком адресов
            var urlHelperFactory = new Mock <IUrlHelperFactory> ();

            urlHelperFactory.Setup(f =>
                                   f.GetUrlHelper(It.IsAny <ActionContext> ()))
            .Returns(urlHelper.Object);
            // создаем экземпляр реализации тестируемого класса,
            // передавая ему вручную ссылку на макет фабрики построителей гиперссылок
            PageLinkTagHelper helper =
                new PageLinkTagHelper(urlHelperFactory.Object)
            {
                PageModel = new PagingInfo {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"
            };
            // создание пустого объекта контекста для помощников
            TagHelperContext ctx = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object> (), "");
            // макет объекта содержимого формируемой модели узла разметки
            var             content = new Mock <TagHelperContent> ();
            TagHelperOutput output  = new TagHelperOutput("div",
                                                          new TagHelperAttributeList(),
                                                          (cache, encoder) => Task.FromResult(content.Object));

            // Act
            // вызываем вручную метод, который в приложении будет вызываться у помощника
            // представлением, в котором используется помощник
            helper.Process(ctx, output);
            // Assert
            // Проверка сгенерированного фрагмента разметки на соответствие заданной модели
            Assert.Equal(@"<a href=""Test/Page1"">1</a>" +
                         @"<a href=""Test/Page2"">2</a>" +
                         @"<a href=""Test/Page3"">3</a>",
                         output.Content.GetContent());
        }
Exemplo n.º 6
0
        public void Can_Generate_Links()
        {
            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>()))
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");

            var urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory.Setup(x => x.GetUrlHelper(It.IsAny <ActionContext>()))
            .Returns(urlHelper.Object);

            PageLinkTagHelper tagHelper = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                ActionName  = "Test",
                PagingModel = new PagingInfo
                {
                    CurrentPage  = 2,
                    ItemsPerPage = 10,
                    TotalItems   = 28
                }
            };

            TagHelperContext tagContext = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), "");

            var             content = new Mock <TagHelperContent>();
            TagHelperOutput output  = new TagHelperOutput
                                      (
                "div",
                new TagHelperAttributeList(),
                (cache, encoder) => Task.FromResult(content.Object)
                                      );

            tagHelper.Process(tagContext, output);

            var linKTemplate = @"<a href=""Test/Page{0}"">{0}</a>";

            Assert.Equal(string.Concat(
                             string.Format(linKTemplate, 1),
                             string.Format(linKTemplate, 2),
                             string.Format(linKTemplate, 3)
                             ), output.Content.GetContent());
        }
Exemplo n.º 7
0
        public void Can_Generate_Page_Links()
        {
            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>()))
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");

            var urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory.Setup(x => x.GetUrlHelper(It.IsAny <ActionContext>()))
            .Returns(urlHelper.Object);

            var helper = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                PageInfo = new PageInfo
                {
                    ItemsPerPage = 10,
                    CurrentPage  = 2,
                    TotalItems   = 28
                },
                PageAction = "Test"
            };

            var ctx = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), "");

            var content = new Mock <TagHelperContent>();

            var output = new TagHelperOutput("div", new TagHelperAttributeList(),
                                             (cache, encoder) => Task.FromResult(content.Object));

            helper.Process(ctx, output);

            var stringBuilder = new StringBuilder();

            stringBuilder
            .Append(CreateUrlElement("Test", "1"))
            .Append(CreateUrlElement("Test", "2"))
            .Append(CreateUrlElement("Test", "3"));

            Assert.Equal(
                stringBuilder.ToString(),
                output.Content.GetContent());
        }
Exemplo n.º 8
0
        void Can_generate_page_links()
        {
            //Arrange
            var mockUrlHelper = new Mock <IUrlHelper>();

            mockUrlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>()))
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");

            var mockUrlHelperFactory = new Mock <IUrlHelperFactory>();

            mockUrlHelperFactory.Setup(m => m.GetUrlHelper(It.IsAny <ActionContext>()))
            .Returns(mockUrlHelper.Object);

            var sut = new PageLinkTagHelper(mockUrlHelperFactory.Object)
            {
                PageModel = new PagingInfo()
                {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"
            };

            var tagHelperContext = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(), "");

            var mockContent = new Mock <TagHelperContent>();
            var output      = new TagHelperOutput("div",
                                                  new TagHelperAttributeList(),
                                                  (cache, encoder) => Task.FromResult(mockContent.Object));

            //Act
            sut.Process(tagHelperContext, output);

            //Assert
            Assert.Equal(@"<a href=""Test/Page1"">1</a>"
                         + @"<a href=""Test/Page2"">2</a>"
                         + @"<a href=""Test/Page3"">3</a>",
                         output.Content.GetContent());
        }
        public void Process_With3Pages_GeneratesPageLinksCorrectly()
        {
            //Arrange
            var urlHelper = Mock.Create <IUrlHelper>();

            Mock.Arrange(() => urlHelper.Action(Arg.IsAny <UrlActionContext>()))
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");

            var urlHelperFactory = Mock.Create <IUrlHelperFactory>();

            Mock.Arrange(() => urlHelperFactory.GetUrlHelper(Arg.IsAny <ActionContext>()))
            .Returns(urlHelper);

            var pageLinkHelper = new PageLinkTagHelper(urlHelperFactory)
            {
                PageModel = new PagingInfo
                {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"
            };

            TagHelperContext ctx = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(), "");

            var             content = Mock.Create <TagHelperContent>();
            TagHelperOutput output  = new TagHelperOutput("div", new TagHelperAttributeList(),
                                                          (cache, encoder) => Task.FromResult(content));

            //Act
            pageLinkHelper.Process(ctx, output);

            //Assert
            output.Content.GetContent().Should().BeEquivalentTo((@"<a href=""Test/Page1"">1</a>"
                                                                 + @"<a href=""Test/Page2"">2</a>"
                                                                 + @"<a href=""Test/Page3"">3</a>"));
        }
        public void Can_Generate_Page_Links()
        {
            //Arrange
            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>())) // IUrlHelper.Action Generates a URL with an absolute path for an action method
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");

            var urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory.Setup(f => f.GetUrlHelper(It.IsAny <ActionContext>()))
            .Returns(urlHelper.Object);

            var helper = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                PageModel = new PagingInfo
                {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"  //Because in Test/Page1, Test is an action.
            };

            //This context is not even used in the method so it doesn't matter much.
            var ctx = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), "");

            var content = new Mock <TagHelperContent>();

            var output = new TagHelperOutput("div", new TagHelperAttributeList(), (cache, encoder) => Task.FromResult(content.Object));


            //Act
            helper.Process(ctx, output);

            //Assert
            Assert.Equal("<a href=\"Test/Page1\">1</a>"
                         + @"<a href=""Test/Page2"">2</a>"
                         + @"<a href=""Test/Page3"">3</a>", output.Content.GetContent());
        }
Exemplo n.º 11
0
        public void Can_Generate_Page_Links()
        {
            //Организация
            var urlHelper = new Mock <IUrlHelper>();                              //Имитирует IUrlHelper

            urlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>())) //имитируем возращение методом Action()
            .Returns("Test/Page1")                                                //It - проверям параметр принадлежит классу UrlActionContext?
            .Returns("Test/Page2")
            .Returns("Test/Page3");                                               //Тогда возращаем

            var urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory.Setup(f => f.GetUrlHelper(It.IsAny <ActionContext>()))
            .Returns(urlHelper.Object);    //возращаем объект который имитирует IUrlHelper если параметр ActionContext

            PageLinkTagHelper helper = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                PageModel = new PagingInfo
                {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"
            };
            TagHelperContext ctx = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(), "");
            var             content = new Mock <TagHelperContent>();
            TagHelperOutput output  = new TagHelperOutput("div",
                                                          new TagHelperAttributeList(),
                                                          (cache, encoder) => Task.FromResult(content.Object));

            //Действие
            helper.Process(ctx, output);
            //Утверждение
            Assert.Equal(@"<a href=""Test/Page1"">1</a>"
                         + @"<a href=""Test/Page2"">2</a>"
                         + @"<a href=""Test/Page3"">3</a>",
                         output.Content.GetContent());
        }
Exemplo n.º 12
0
        public void Can_Generate_Page_Links()
        {
#warning почитать про Moq
            var urlHelper = new Mock <IUrlHelper>();
            urlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>()))
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");
            var urlHelperFactory = new Mock <IUrlHelperFactory>();
            urlHelperFactory.Setup(f => f.GetUrlHelper(It.IsAny <ActionContext>())).Returns(urlHelper.Object);

            PageLinkTagHelper helper = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                PageModel = new PagingInfo
                {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"
            };

            TagHelperContext ctx = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(), "");

            var             content = new Mock <TagHelperContent>();
            TagHelperOutput output  = new TagHelperOutput("div",
                                                          new TagHelperAttributeList(),
                                                          (cache, encoder) => Task.FromResult(content.Object));

            helper.ProcessAsync(ctx, output);

            Assert.Equal(@"<a href=""Test/Page1"">Первая</a>"
                         + @"<a href=""Test/Page2"">Страница 2</a>"
                         + @"<a href=""Test/Page3"">Последняя</a>",
#warning зачем надо decode?
                         HttpUtility.HtmlDecode(output.Content.GetContent()));
        }
Exemplo n.º 13
0
        public void Can_Generate_Page_Links()
        {
            // Arrange
            Mock <IUrlHelper> urlHelper = new Mock <IUrlHelper>();

            urlHelper.SetupSequence(h => h.Action(It.IsAny <UrlActionContext>()))
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");

            Mock <IUrlHelperFactory> urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory.Setup(m => m.GetUrlHelper(It.IsAny <ActionContext>()))
            .Returns(urlHelper.Object);

            PageLinkTagHelper target = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                PageModel = new PagingInfo {
                    TotalItems   = 28,
                    ItemsPerPage = 10,
                    CurrentPage  = 2
                },
                PageAction = "Test"
            };

            // Empty object. Not used in target.
            TagHelperContext ctx = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), String.Empty);

            Mock <TagHelperContent> content = new Mock <TagHelperContent>();
            TagHelperOutput         output  = new TagHelperOutput("div", new TagHelperAttributeList(), (cache, encoder) => Task.FromResult(content.Object));

            // Act
            target.Process(ctx, output);

            // Assert
            string result = output.Content.GetContent();

            Assert.Equal(@"<a href=""Test/Page1"">1</a><a href=""Test/Page2"">2</a><a href=""Test/Page3"">3</a>", result);
        }
Exemplo n.º 14
0
        public void Process_PageInfo_ReturnsContent()
        {
            var urlHelper = Substitute.For <IUrlHelper>();

            urlHelper.Action(Arg.Any <UrlActionContext>())
            .Returns("Test/Page1",
                     "Test/Page2",
                     "Test/Page3");
            var urlHelperFactory = Substitute.For <IUrlHelperFactory>();

            urlHelperFactory.GetUrlHelper(Arg.Any <ActionContext>())
            .Returns(urlHelper);
            PageLinkTagHelper tagHelper = new PageLinkTagHelper(urlHelperFactory)
            {
                PageModel = new PagingInfo
                {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"
            };
            TagHelperContext ctx = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(), "");
            var             content = Substitute.For <TagHelperContent>();
            TagHelperOutput output  = new TagHelperOutput("div",
                                                          new TagHelperAttributeList(),
                                                          (cache, encoder) => Task.FromResult(content));

            tagHelper.Process(ctx, output);

            var res = output.Content.GetContent();

            Assert.Equal(@"<a href=""Test/Page1"">1</a>"
                         + @"<a href=""Test/Page2"">2</a>"
                         + @"<a href=""Test/Page3"">3</a>",
                         res);
        }
Exemplo n.º 15
0
        public void CanGeneratePageLinks()
        {
            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>()))
            .Returns("Test/Page1")
            .Returns("Test/Page2")
            .Returns("Test/Page3");

            var urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory
            .Setup(f => f.GetUrlHelper(It.IsAny <ActionContext>()))
            .Returns(urlHelper.Object);

            var helper = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                PageModel = new PagingInfo {
                    CurrentPage  = 2,
                    TotalItems   = 28,
                    ItemsPerPage = 10
                },
                PageAction = "Test"
            };

            var tagHelperContext = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(), "");

            var content = new Mock <TagHelperContent>();
            var outPut  = new TagHelperOutput("div", new TagHelperAttributeList(),
                                              (_, __) => Task.FromResult(content.Object));

            helper.Process(tagHelperContext, outPut);
            const string str = @"<a href=""Test/Page1"">1</a><a href=""Test/Page2"">2</a><a href=""Test/Page3"">3</a>";

            Assert.Equal(str, outPut.Content.GetContent());
        }
Exemplo n.º 16
0
        public void Can_Gererate_Page_Links()
        {
            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.SetupSequence(x => x.Action(It.IsAny <UrlActionContext>()))
            .Returns("/Test/Page1")
            .Returns("/Test/Page2")
            .Returns("/Test/Page3");

            var urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory.Setup(f => f.GetUrlHelper(It.IsAny <ActionContext>())).Returns(urlHelper.Object);

            var helper = new PageLinkTagHelper(urlHelperFactory.Object)
            {
                PageModel = new PagingInfo()
                {
                    Page = 2, PageSize = 10, TotalItems = 25
                },
                PageAction = "Test",
                PageClass  = "class1"
            };

            var content = new Mock <TagHelperContent>();
            var context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), "");
            var output  = new TagHelperOutput("div", new TagHelperAttributeList(), (cache, encoder) => Task.FromResult(content.Object));

            helper.Process(context, output);

            Assert.Equal(
                @"<div>" +
                @"<a class=""class1"" href=""/Test/Page1"">1</a>" +
                @"<a class=""class1"" href=""/Test/Page2"">2</a>" +
                @"<a class=""class1"" href=""/Test/Page3"">3</a>" +
                @"</div>",
                output.Content.GetContent());
        }