PageData differs a bit from other IContent implementations in meaning all its properties are backed by a PropertyData instance. So in test you need to add a corresponding PropertyData instance for the property like for example:
var page = new PageData();
page.Property.AddNoCheck(new PropertyString() { Name = MetaDataProperties.PageLanguageBranch, Value = "en" });
page.Property.AddNoCheck(new PropertyPageReference() { Name = MetaDataProperties.PageLink, Value = new PageReference(4) });
page.Property.AddNoCheck(new PropertyPageReference() { Name = MetaDataProperties.PageParentLink, Value = new PageReference(6) });
An alternative if you have a mocking framework like Moq is to create a mock of PageData like:
var page = new Mock<PageData>();
page.Setup(p => p.ContentLink).Returns(new ContentReference(6));
Thank you so much for that. I was struggling generally with setting up page data. The mocking works well for me with Rhino Mocks
var product = MockRepository.GenerateMock<PageData>();
product.Stub(p => p.ContentLink).Return(new ContentReference(6));
product.Stub(p => p.Language).Return(new CultureInfo("en"));
Thanks
Just as a note - the mocking technique above no longer appears to work in EPiServer 7.5 with objects derived from PageData (though page data itself seems to work still). Therefore the approach needs to be
var page = new PageData();
page.Property.Add(new PropertyString() { Name = MetaDataProperties.PageLanguageBranch, Value = "en" });
});
Hi
I'm trying to create a page manually for unit test purposes. It need to have a language branch but I can't create it. I'm trying
But it is failing on this piece of code
The Language is null so the .Name call throws an object can't be found error. I've also tried directly assigning in to the ILocalization cast page i,e,
But in that case the exception generated tells me that the language branch doesn' exist and can't be assigned.
Just for background I'm trying to create a ContentInLanguageReference object to mock out some episerver find results but I think the problems is more general so I am asking here.
Many Thanks for all/any help