SaaS CMS has officially launched! Learn more now.

How can I make my first unit test pass?

Vote:
 

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");
        }
    }

    

#83059
Mar 25, 2014 12:24
Vote:
 

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?

#83068
Mar 25, 2014 13:05
Vote:
 

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.

#83646
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.