Esempio n. 1
0
        public static SeoHelper Create(ViewContext viewContext = null)
        {
            viewContext = viewContext ?? ViewContextTestFactory.Create();

            var seo = viewContext.ViewData.GetSeoHelper();

            return(seo);
        }
        public static HtmlHelper Create(ViewContext viewContext = null)
        {
            viewContext = viewContext ?? ViewContextTestFactory.Create();

            var viewDataContainer = new Mock <IViewDataContainer>();

            viewDataContainer.Setup(x => x.ViewData).Returns(viewContext.ViewData);

            var htmlHelper = new HtmlHelper(viewContext, viewDataContainer.Object);

            return(htmlHelper);
        }
Esempio n. 3
0
        public void SeoTitle_EmptyArgumentWithBaseTitleInSeoHelper_ReturnsHtmlContainingValue()
        {
            // Arrange
            var viewContext = ViewContextTestFactory.Create();
            var htmlHelper  = HtmlHelperTestFactory.Create(viewContext);
            var seoHelper   = SeoHelperTestFactory.Create(viewContext);

            seoHelper.BaseTitle = TestData.TestBaseTitle;

            // Act
            var html = htmlHelper.SeoTitle();

            // Assert
            bool htmlContainsValue = html.Contains(TestData.TestBaseTitle);

            Assert.True(htmlContainsValue);
        }
Esempio n. 4
0
        public void SeoLinkCanonical_EmptyArgumentWithValueInSeoHelper_ReturnsHtmlContainingValue()
        {
            // Arrange
            var viewContext = ViewContextTestFactory.Create();
            var htmlHelper  = HtmlHelperTestFactory.Create(viewContext);
            var seoHelper   = SeoHelperTestFactory.Create(viewContext);

            seoHelper.LinkCanonical = $"{TestData.TestLinkCanonical}";

            // Act
            var html = htmlHelper.SeoLinkCanonical();

            // Assert
            bool htmlContainsValue = html.Contains(TestData.TestLinkCanonical);

            Assert.True(htmlContainsValue);
        }
Esempio n. 5
0
        public void SeoMetaKeywords_EmptyArgumentWithValueInSeoHelper_ReturnsHtmlContainingValue()
        {
            // Arrange
            var viewContext = ViewContextTestFactory.Create();
            var htmlHelper  = HtmlHelperTestFactory.Create(viewContext);
            var seoHelper   = SeoHelperTestFactory.Create(viewContext);

            seoHelper.MetaKeywords = TestData.TestMetaKeywords;

            // Act
            var html = htmlHelper.SeoMetaKeywords();

            // Assert
            bool htmlContainsValue = html.Contains(TestData.TestMetaKeywords);

            Assert.True(htmlContainsValue);
        }
Esempio n. 6
0
        public void SeoMetaRobotsIndex_EmptyArgumentWithMetaRobotsNoIndexInSeoHelper_ReturnsHtmlContainingValue()
        {
            // Arrange
            var viewContext = ViewContextTestFactory.Create();
            var htmlHelper  = HtmlHelperTestFactory.Create(viewContext);
            var seoHelper   = SeoHelperTestFactory.Create(viewContext);

            seoHelper.MetaRobotsNoIndex = true;

            // Act
            var html = htmlHelper.SeoMetaRobotsIndex();

            // Assert
            bool htmlContainsRobots      = html.Contains("robots");
            var  defaultRobotsNoIndex    = RobotsIndexManager.GetMetaContent(RobotsIndexManager.DefaultRobotsNoIndex);
            bool htmlContainsMetaContent = html.Contains(defaultRobotsNoIndex);

            Assert.True(htmlContainsRobots);
            Assert.True(htmlContainsMetaContent);
        }
Esempio n. 7
0
        SeoLinkCanonical_EmptyArgumentWithAppRelativeValueInSeoHelper_ReturnsHtmlContainingValueAndIsAbsolute()
        {
            // Arrange
            var viewContext = ViewContextTestFactory.Create();
            var htmlHelper  = HtmlHelperTestFactory.Create(viewContext);
            var seoHelper   = SeoHelperTestFactory.Create(viewContext);

            seoHelper.LinkCanonical = TestData.TestAppRelativeLinkCanonical;

            // Act
            var html = htmlHelper.SeoLinkCanonical();

            // Assert
            bool htmlContainsValue  = html.Contains(TestData.TestLinkCanonical);
            bool htmlContainsDomain = html.Contains(RequestContextTestFactory.Domain);
            bool htmlContainsAppRelativeCharacter = html.Contains("~");

            Assert.True(htmlContainsValue);
            Assert.True(htmlContainsDomain);
            Assert.False(htmlContainsAppRelativeCharacter);
        }
Esempio n. 8
0
        public void SeoMetaRobotsIndex_EmptyArgumentWithValuesInSeoHelper_ReturnsHtmlContainingValue(
            RobotsIndex robotsIndex,
            string expectedContent)
        {
            // Arrange
            var viewContext = ViewContextTestFactory.Create();
            var htmlHelper  = HtmlHelperTestFactory.Create(viewContext);
            var seoHelper   = SeoHelperTestFactory.Create(viewContext);

            seoHelper.MetaRobotsIndex = robotsIndex;

            // Act
            var html = htmlHelper.SeoMetaRobotsIndex();

            // Assert
            bool htmlContainsRobots          = html.Contains("robots");
            var  metaContent                 = RobotsIndexManager.GetMetaContent(robotsIndex);
            bool htmlContainsMetaContent     = html.Contains(metaContent);
            bool htmlContainsExpectedContent = html.Contains(expectedContent);

            Assert.True(htmlContainsRobots);
            Assert.True(htmlContainsMetaContent);
            Assert.True(htmlContainsExpectedContent);
        }