Skip to content

Commit

Permalink
Added a few extension methods for quickly creating pages
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanforsberg committed Mar 18, 2013
1 parent 1dc1be5 commit 3c2af98
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,11 @@ public override void Given()
{
base.Given();

_startPage = ContentRepository.GetDefaultPageData<StartPage>(ContentReference.RootPage);
ContentRepository.Save(_startPage, SaveAction.Publish, AccessLevel.NoAccess);
_startPage = ContentRepository.Publish<StartPage>(ContentReference.RootPage);

var childPage1 = ContentRepository.GetDefaultPageData<StartPage>(_startPage.PageLink);
childPage1.PageName = "ChildPage1";
ContentRepository.Save(childPage1, SaveAction.Publish, AccessLevel.NoAccess);

var childPage2 = ContentRepository.GetDefaultPageData<StartPage>(_startPage.PageLink);
childPage2.PageName = "ChildPage2";
ContentRepository.Save(childPage2, SaveAction.Publish, AccessLevel.NoAccess);

var childPage3 = ContentRepository.GetDefaultPageData<StandardPage>(_startPage.PageLink);
childPage3.PageName = "ChildPage3";
ContentRepository.Save(childPage3, SaveAction.Publish, AccessLevel.NoAccess);
ContentRepository.Publish<StartPage>(_startPage.PageLink, "ChildPage1");
ContentRepository.Publish<StartPage>(_startPage.PageLink, "ChildPage2");
ContentRepository.Publish<StandardPage>(_startPage.PageLink, "ChildPage3");
}

public override void When()
Expand Down
3 changes: 1 addition & 2 deletions src/WhiteMagic.Tests/ContentRepository/when_moving_a_page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public override void Given()
base.Given();

_startPage = ContentRepository
.GetDefault<StartPage>(ContentReference.RootPage)
.SaveAndPublish(ContentRepository);
.Publish<StartPage>(ContentReference.RootPage);

_oldParent = ContentRepository
.GetDefault<StartPage>(_startPage.PageLink)
Expand Down
26 changes: 17 additions & 9 deletions src/WhiteMagic.Tests/ContentRepository/when_saving_a_page.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using EPiServer.Core;
using EPiServer.DataAccess;
using EPiServer.Security;
using NUnit.Framework;
using Shouldly;
using WhiteMagic.Tests.Pages;
Expand All @@ -9,16 +7,26 @@ namespace WhiteMagic.Tests.ContentRepository
{
public class when_saving_a_page : TestBase
{
[Test]
public void it_should_be_returned_when_loaded()
private StartPage _startPage;
private StartPage _loadedPage;

public override void Given()
{
var startPage = ContentRepository.GetDefaultPageData<StartPage>(ContentReference.RootPage);
startPage.MainBody = "Hejhej!";
base.Given();
_startPage = ContentRepository
.Publish<StartPage>(ContentReference.RootPage, p => p.MainBody = "Hejhej!");
}

ContentRepository.Save(startPage, SaveAction.Publish, AccessLevel.NoAccess);
public override void When()
{
base.When();
_loadedPage = ContentRepository.Get<StartPage>(_startPage.PageLink);
}

var page2 = ContentRepository.Get<StartPage>(startPage.PageLink);
page2.MainBody.ShouldBe("Hejhej!");
[Test]
public void it_should_be_returned_when_loaded()
{
_loadedPage.MainBody.ShouldBe("Hejhej!");
}

}
Expand Down
13 changes: 13 additions & 0 deletions src/WhiteMagic.Tests/ContentRepositoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ public static class ContentRepositoryExtensions
public static readonly Guid RootPageGuid = new Guid("945D02B0-B744-4349-A995-87CE3FCD51F4");
public static readonly Guid WasteBasketGuid = new Guid("27D4C717-4ABC-4DC4-B3A1-5008F311E301");

public static T Publish<T>(this IContentRepository contentRepository, ContentReference parent, string pageName = "") where T : IContent
{
return contentRepository.Publish<T>(parent, p => p.Name = pageName);
}

public static T Publish<T>(this IContentRepository contentRepository, ContentReference parent, Action<T> setValues) where T : IContent
{
return contentRepository
.GetDefault<T>(parent)
.With(setValues)
.SaveAndPublish(contentRepository);
}

public static void CreateSystemPages(this IContentRepository contentRepository)
{
var rootPage = new PageData();
Expand Down

0 comments on commit 3c2af98

Please sign in to comment.