November Happy Hour will be moved to Thursday December 5th.

Can't Instaniate PageData ContentLink for unit test

Vote:
 

Hi all

I'm trying to instaniate the ContentLink property of an object inheriting from pagedata. I want to do this to unit test episerver find but i think the question is general so I'll ask in this forum. So far I've tried

 

var product = new ProductPage { ProductName = "Product 1"};
((IContent)product).ContentLink = ContentReference.EmptyReference;

Which crashes at runtime saying the property doesn't exist.  And

         var product = new ProductPage { ProductName = "Product 1"};
         product.Property.Add("ContentLink", ContentReference.EmptyReference);

Which won't compile. I'm trying to instaniate a ContentInLanguageReference object to mock up some episerver find test results and disassembling it shows that it accesses the ContentLink and will (and does) crash if it is null

All help gratefully received.

Many Thanks 

#77687
Nov 22, 2013 15:56
Vote:
 

Try this:

[Test]
public void Foo()
{
    var product = new ProductPage();
    product.Property["PageLink"] = new PropertyPageReference(PageReference.EmptyReference);

    Assert.AreEqual(product.ContentLink, ContentReference.EmptyReference);
}

The same goes for ProductName. You can't use strongly typed properties :(

#77696
Nov 24, 2013 0:10
Vote:
 

That works. Great. Thanks very much

#77703
Nov 25, 2013 10:37
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.