How can I make my first unit test pass?


I read a good article regarding set up the basic unit test 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?



    public class Test1
        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
        public void TestStartPage()
            var startPage =

            Assert.AreEqual(startPage.Name, "Start");


Mar 25, 2014 12:24

Seems you ran into a Naming missmatch.

EpiServers PageData has a Name property that gets the PageName property. If you call it Foo instead does it pass?

Mar 25, 2014 13:05

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.

Mar 30, 2014 14:47
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.