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"); }
public ContentReferencePropertyHandlerTests() { this._contentSerializerSettings = Substitute.For <IContentSerializerSettings>(); this._contentSerializerSettings.UrlSettings = new UrlSettings(); this._urlHelper = Substitute.For <IUrlHelper>(); this._sut = new ContentReferencePropertyHandler(this._urlHelper, this._contentSerializerSettings); }
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)); }