I read a good article regarding set up the basic unit test in episerver 7 (http://tedgustaf.com/blog/2013/10/unit-testing-in-episerver-7/)
I copy the same code from the above article with slight modification and trying to run it in my episerver 7.5 project with nunit instead of VisualStudio Unit test, However I keep receiving " EPiServer.Core.EPiServerException : Property 'PageName' does not exist, can only assign values to existing properties" error.
Can someone tell me where I made the mistake?
Thanks
[TestFixture]
public class Test1
{
[SetUp]
public void Setup()
{
// Create a mock repository
var mockRepository = new Mock<IContentRepository>();
// Setup the repository to return a start page with a preset property value
mockRepository.Setup(r => r.Get<StartPage>(ContentReference.StartPage)).Returns(new StartPage { Name = "Start" });
// Create a mock service locator
var mockLocator = new Mock<IServiceLocator>();
// Setup the service locator to return our mock repository when an IContentRepository is requested
mockLocator.Setup(l => l.GetInstance<IContentRepository>()).Returns(mockRepository.Object);
// Make use of our mock objects throughout EPiServer
ServiceLocator.SetLocator(mockLocator.Object);
}
[Test]
public void TestStartPage()
{
var startPage =
ServiceLocator.Current.GetInstance<IContentRepository>().Get<StartPage>(ContentReference.StartPage);
Assert.AreEqual(startPage.Name, "Start");
}
}
Thanks Petter. You are right. I use custom property for test, it's all passed. I tried other pagedata properties, none of them worked. Does it mean I can't simulate the page with a given name or page data property.
I read a good article regarding set up the basic unit test in episerver 7 (http://tedgustaf.com/blog/2013/10/unit-testing-in-episerver-7/)
I copy the same code from the above article with slight modification and trying to run it in my episerver 7.5 project with nunit instead of VisualStudio Unit test, However I keep receiving " EPiServer.Core.EPiServerException : Property 'PageName' does not exist, can only assign values to existing properties" error.
Can someone tell me where I made the mistake?
Thanks