コード例 #1
0
        public void GetFocusKeyword_OnExectureWithNullParameter_ThrowsException()
        {
            var dashboardSettingsSerializerMock = new Mock <IDashboardSettingsSerializer>();
            var focusKeywordHelper = new FocusKeywordHelper(dashboardSettingsSerializerMock.Object);

            focusKeywordHelper.GetFocusKeyword(null);
        }
コード例 #2
0
        public void GetFocusKeywordReturnsFocusKeywordFromDashboardProperty()
        {
            using (ShimsContext.Create())
            {
                var propertyMock = new Mock <IPublishedProperty>();
                propertyMock.SetupGet(x => x.HasValue).Returns(true);
                propertyMock.SetupGet(x => x.Value).Returns("{\"focusKeyword\": \"umbraco\"}");

                IPublishedContent publishedContent = new StubPublishedContentBase
                {
                    PropertiesGet = () => new List <IPublishedProperty> {
                        propertyMock.Object
                    }
                };

                Umbraco.Web.Fakes.ShimPublishedContentExtensions.HasPropertyIPublishedContentString = (node, alias) =>
                {
                    return(false);
                };

                var focusKeywordHelper = new FocusKeywordHelper();
                var result             = focusKeywordHelper.GetFocusKeyword(publishedContent);

                Assert.AreEqual("umbraco", result);
            }
        }
コード例 #3
0
        public void GetFocusKeywordReturnsNullWithNoProperties()
        {
            var mockedIPublishedContent = new PublishedContentMock();

            mockedIPublishedContent.Properties = new List <IPublishedProperty>()
            {
            };

            var focusKeywordHelper = new FocusKeywordHelper();
            var result             = focusKeywordHelper.GetFocusKeyword(mockedIPublishedContent);

            Assert.IsNull(result);
        }
コード例 #4
0
        public void GetFocusKeywordReturnsFocusKeywordProperty()
        {
            var mockedIPublishedContent = new PublishedContentMock();

            mockedIPublishedContent.Properties = new List <IPublishedProperty>()
            {
                new PublishedPropertyMock()
                {
                    PropertyTypeAlias = "focusKeyword", Value = "test keyword"
                }
            };
            var dashboardSettingsSerializerMock = new Mock <IDashboardSettingsSerializer>();
            var focusKeywordHelper = new FocusKeywordHelper(dashboardSettingsSerializerMock.Object);
            var result             = focusKeywordHelper.GetFocusKeyword(mockedIPublishedContent);

            Assert.AreEqual("test keyword", result);
        }
コード例 #5
0
        public PageAnalysis CreateAnalysis(IPublishedContent node, string focusKeyword = null)
        {
            if (node.TemplateId == 0)
            {
                throw new MissingFieldException("TemplateId is not set");
            }

            if (!string.IsNullOrEmpty(focusKeyword))
            {
                focusKeyword = _focusKeywordHelper.GetFocusKeyword(node);
            }

            var analysis = _pageAnalysisService.CreatePageAnalysis(node, focusKeyword);

            CreateCachedAnalysisItem(node.Id, analysis);

            return(analysis);
        }
コード例 #6
0
        public void GetFocusKeywordReturnsNullFromEmptyDashboardProperty()
        {
            var mockedIPublishedContent = new PublishedContentMock();

            mockedIPublishedContent.Properties = new List <IPublishedProperty>()
            {
                new PublishedPropertyMock()
                {
                    PropertyTypeAlias = "otherProperty", Value = "{\"focusKeyword\": \"\"}"
                }
            };
            var dashboardSettingsSerializerMock = new Mock <IDashboardSettingsSerializer>();

            var focusKeywordHelper = new FocusKeywordHelper();
            var result             = focusKeywordHelper.GetFocusKeyword(mockedIPublishedContent);

            Assert.IsNull(result);
        }
コード例 #7
0
        public void GetFocusKeywordReturnsNullWithNoProperties()
        {
            using (ShimsContext.Create())
            {
                IPublishedContent publishedContent = new StubPublishedContentBase
                {
                    PropertiesGet = () => new List <IPublishedProperty>()
                };

                Umbraco.Web.Fakes.ShimPublishedContentExtensions.HasPropertyIPublishedContentString = (node, alias) =>
                {
                    return(false);
                };

                var focusKeywordHelper = new FocusKeywordHelper();
                var result             = focusKeywordHelper.GetFocusKeyword(publishedContent);

                Assert.IsNull(result);
            }
        }
コード例 #8
0
        public void GetFocusKeywordReturnsFocusKeywordProperty()
        {
            using (ShimsContext.Create())
            {
                IPublishedContent publishedContent = new StubPublishedContentBase();

                // Fake HasProperty extension method
                Umbraco.Web.Fakes.ShimPublishedContentExtensions.HasPropertyIPublishedContentString = (node, alias) =>
                {
                    switch (alias)
                    {
                    case "focusKeyword":
                        return(true);

                    default:
                        return(false);
                    }
                };

                // Fake GetPropertyValue<string> extension method
                Umbraco.Web.Fakes.ShimPublishedContentExtensions.GetPropertyValueOf1IPublishedContentString(
                    (node, alias) =>
                {
                    switch (alias)
                    {
                    case "focusKeyword":
                        return("test keyword");

                    default:
                        return(null);
                    }
                });

                var focusKeywordHelper = new FocusKeywordHelper();
                var result             = focusKeywordHelper.GetFocusKeyword(publishedContent);

                Assert.AreEqual("test keyword", result);
            }
        }