public void ShouldUsePassedInContentSerializerSettings()
        {
            var pageReference    = new PageReference(3000);
            var page             = new StandardPageBuilder().WithPageReference(pageReference).Build();
            var serviceLocator   = Substitute.For <IServiceLocator>();
            var urlHelper        = Substitute.For <IUrlHelper>();
            var pageReferenceUrl = "https://josefottosson.se/some-path";
            var contentReferencePropertyHandler = new ContentReferencePropertyHandler(urlHelper, this._contentSerializerSettings);

            urlHelper.ContentUrl(pageReference, Arg.Any <IUrlSettings>()).Returns(pageReferenceUrl);
            serviceLocator.TryGetExistingInstance(typeof(IPropertyHandler <PageReference>), out var _).Returns(x =>
            {
                x[1] = new PageReferencePropertyHandler(contentReferencePropertyHandler, _contentSerializerSettings);
                return(true);
            });
            ServiceLocator.SetLocator(serviceLocator);
            var customContentSerializerSettings = new ContentSerializerSettings
            {
                UrlSettings = new UrlSettings
                {
                    UseAbsoluteUrls = false
                }
            };

            var result = this._sut.GetStructuredData(page, customContentSerializerSettings);

            result.ShouldContainKey("PageReference");
            result["PageReference"].ShouldBe("/some-path");
        }
Exemplo n.º 2
0
        public void GivenContentAreaProperty_WhenGetStructuredData_ThenReturnsCorrectValue()
        {
            var contentArea = CreateContentArea();
            var page        = new StandardPageBuilder().WithMainContentArea(contentArea).Build();

            var result = this._sut.GetStructuredData(page, new ContentSerializerSettings());

            result.ShouldContainKey(nameof(StandardPage.MainContentArea));
        }
        public void GivenBoolProperty_WhenGetStructuredData_ThenReturnsCorrectValue()
        {
            var serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.TryGetExistingInstance(typeof(IPropertyHandler <bool>), out var _).Returns(x =>
            {
                x[1] = new BoolPropertyHandler(_contentSerializerSettings);
                return(true);
            });
            ServiceLocator.SetLocator(serviceLocator);
            var page = new StandardPageBuilder().WithPrivate(true).Build();

            var result = this._sut.GetStructuredData(page, this._contentSerializerSettings);

            result.ShouldContain(x => x.Key.Equals(nameof(StandardPage.Private)) && x.Value.Equals(page.Private));
        }
        public void GivenStringArrayProperty_WhenGetStructuredData_ThenReturnsCorrectValue()
        {
            var strings        = new[] { "any", "value" };
            var page           = new StandardPageBuilder().WithStrings(strings).Build();
            var serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.TryGetExistingInstance(typeof(IPropertyHandler <IEnumerable <string> >), out var _).Returns(x =>
            {
                x[1] = new StringListPropertyHandler(_contentSerializerSettings);
                return(true);
            });
            ServiceLocator.SetLocator(serviceLocator);

            var result = this._sut.GetStructuredData(page, this._contentSerializerSettings);

            result.ShouldContain(x => x.Key.Equals(nameof(StandardPage.Strings)) && x.Value.Equals(strings));
        }
        public void GivenDateTimeListProperty_WhenGetStructuredData_ThenReturnsCorrectValue()
        {
            var dateTimes = new List <DateTime> {
                new DateTime(2000, 1, 12), new DateTime(3000, 1, 20)
            };
            var page           = new StandardPageBuilder().WithDateTimes(dateTimes).Build();
            var serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.TryGetExistingInstance(typeof(IPropertyHandler <IEnumerable <DateTime> >), out var _).Returns(x =>
            {
                x[1] = new DateTimeListPropertyHandler(_contentSerializerSettings);
                return(true);
            });
            ServiceLocator.SetLocator(serviceLocator);

            var result = this._sut.GetStructuredData(page, this._contentSerializerSettings);

            result.ShouldContain(x => x.Key.Equals(nameof(StandardPage.DateTimes)) && x.Value.Equals(dateTimes));
        }
        public void GivenContentReferenceProperty_WhenGetStructuredData_ThenReturnsCorrectValue()
        {
            var contentReference        = new ContentReference(2000);
            var page                    = new StandardPageBuilder().WithContentReference(contentReference).Build();
            var serviceLocator          = Substitute.For <IServiceLocator>();
            var urlHelper               = Substitute.For <IUrlHelper>();
            var contentReferencePageUrl = "https://josefottosson.se/";

            urlHelper.ContentUrl(contentReference, Arg.Any <IUrlSettings>()).Returns(contentReferencePageUrl);
            serviceLocator.TryGetExistingInstance(typeof(IPropertyHandler <ContentReference>), out var _).Returns(x =>
            {
                x[1] = new ContentReferencePropertyHandler(urlHelper, this._contentSerializerSettings);
                return(true);
            });
            ServiceLocator.SetLocator(serviceLocator);

            var result = this._sut.GetStructuredData(page, this._contentSerializerSettings);

            result.ShouldContain(x => x.Key.Equals(nameof(StandardPage.ContentReference)) && x.Value.Equals(contentReferencePageUrl));
        }
        public void GivenContentAreaProperty_WhenGetStructuredData_ThenReturnsCorrectValue()
        {
            var contentArea    = CreateContentArea();
            var page           = new StandardPageBuilder().WithMainContentArea(contentArea).Build();
            var serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.TryGetExistingInstance(typeof(IPropertyHandler <ContentArea>), out var _).Returns(x =>
            {
                x[1] = new ContentAreaPropertyHandler(this._contentLoader, this._sut, this._contentSerializerSettings);
                return(true);
            });
            serviceLocator.TryGetExistingInstance(typeof(IPropertyHandler <string>), out var _).Returns(x =>
            {
                var selectStrategy = new DefaultSelectStrategy();
                x[1] = new StringPropertyHandler(selectStrategy, selectStrategy, _contentSerializerSettings);
                return(true);
            });
            ServiceLocator.SetLocator(serviceLocator);

            var result = this._sut.GetStructuredData(page, this._contentSerializerSettings);

            result.ShouldContainKey(nameof(StandardPage.MainContentArea));
        }