I've had to change the page object to concrete instantiations to get the tests back working
var searchPage = new SearchPageBase();
searchPage.Property.Add(new PropertyPageReference { Name = MetaDataProperties.PageLink, Value = new PageReference(6) });
Feels like a step backwards
EPiServer.dll v7.5.409.0 has the assembly attribute set:
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
While 7.0.586.24 do not, and in that version it works, seems it should be the other way around really, but there is a difference for you atleast.
Edit: Or the fact that dynamicproxy now sees the internal set method and tries to mock it is the reason for it failing.
Found a semi-workaround for this if you use Castle.DynamicProxy to generate your page proxies, not that its much different from just creating concrete instances using new PageData(), though I personally use a interceptor to populate the Property collection with the data for whatever property I am setting to create sort of a semi-mock whenever the "set_XXX" method is called on the proxy.
This will probably fail spectacularily if you try to do something with the properties "LanguageBranch" & "PageFolderID", but they might help someone get their unit tests running until EPi releases a fix for this.
public class SomeTestUtil
{
public static T CreatePageDataProxy<T>() where T : PageData
{
var opt = ProxyGenerationOptions.Default;
opt.Hook = new PageDataHook();
return new ProxyGenerator().CreateClassProxy<T>(opt);
}
}
public class PageDataHook : AllMethodsHook
{
public override bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
{
if (typeof (PageData).IsAssignableFrom(type)) {
if (methodInfo.Name == "set_LanguageBranch" || methodInfo.Name == "set_PageFolderID") {
return false;
}
}
return base.ShouldInterceptMethod(type, methodInfo);
}
}
Edit, it will make the following test pass:
[Test]
public void Title_should_be_the_same_as_the_page_name()
{
var page = SomeTestUtil.CreatePageDataProxy<SitePageData>();
page.Property["PageName"] = new PropertyString("foo");
Assert.AreEqual("foo", page.Title);
Assert.AreEqual(page.PageName, page.Title);
}
We are looking into this.
Bug 111585 Not possible to mock page types in 7.5
I'm now on 7.7.0.0 and this is still a problem. Is ithere any further news on this please
Thanks
We have only verified the bug using Moq assuming it was the same issue in Rhino Mocks, and it was. But apparently there is also a second issue with Rhino Mocks that have been there for some time, no sure if it have ever worked or if Rhino Mocks made some change recently. We have fixed the bug and it should go out within the next 2 weeks or so..
BUG #116485 Not possible to mock content types using Rhino Mocks
Hi all
Previous to the upgrade I could mock up base page types (i.e. those inheriting from PageData) e.g.(with Rhino Mocks)
But since the upgrade the GenerateMock line crashes with the following error
Method 'set_LanguageBranch' on type 'Castle.Proxies.ProductPageBaseProxyae202e0229524fd7849a560a662d64dc' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is overriding a method that is not visible from that assembly.
I have disassembled EPiServer.dll 7.5 and the LanguageBranch set is internal however this is the same as 7.0 dll so that not so illuminating
Does anyone know why this has started to fail and what could be done to get these tests back working. It has broken quite a few tests
Many Thanks for any all help