Skip to content

Commit

Permalink
When loading a page you work against you recieve a copy of the stored…
Browse files Browse the repository at this point in the history
… page
  • Loading branch information
stefanforsberg committed Mar 20, 2013
1 parent 3c2af98 commit 5496b09
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/WhiteMagic.Tests/ContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace WhiteMagic.Tests
{
public static class ContentExtensions
{
public static T SaveAndPublish<T>(this T page, IContentRepository repository) where T : IContent
public static PageReference SaveAndPublish<T>(this T page, IContentRepository repository) where T : IContent
{
repository.Save(page, SaveAction.Publish, AccessLevel.NoAccess);
return page;
return page.ContentLink.ToPageReference();
}

public static T With<T>(this T page, Action<T> with) where T : IContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ namespace WhiteMagic.Tests.ContentRepository
{
public class when_getting_children_by_page_type : TestBase
{
StartPage _startPage;

IEnumerable<StartPage> _children;
private PageReference _startPageReference;

public override void Given()
{
base.Given();

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

ContentRepository.Publish<StartPage>(_startPage.PageLink, "ChildPage1");
ContentRepository.Publish<StartPage>(_startPage.PageLink, "ChildPage2");
ContentRepository.Publish<StandardPage>(_startPage.PageLink, "ChildPage3");
ContentRepository.Publish<StartPage>(_startPageReference, "ChildPage1");
ContentRepository.Publish<StartPage>(_startPageReference, "ChildPage2");
ContentRepository.Publish<StandardPage>(_startPageReference, "ChildPage3");
}

public override void When()
{
base.When();
_children = ContentRepository.GetChildren<StartPage>(_startPage.PageLink);
_children = ContentRepository.GetChildren<StartPage>(_startPageReference);
}

[Test]
Expand Down
16 changes: 8 additions & 8 deletions src/WhiteMagic.Tests/ContentRepository/when_moving_a_page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ namespace WhiteMagic.Tests.ContentRepository
{
public class when_moving_a_page : TestBase
{
StartPage _startPage;
StartPage _oldParent;
StartPage _newParent;
StartPage _pageToMove;
private PageReference _startPageReference;
private PageReference _oldParentReference;

public override void Given()
{
base.Given();

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

_oldParent = ContentRepository
.GetDefault<StartPage>(_startPage.PageLink)
_oldParentReference = ContentRepository
.GetDefault<StartPage>(_startPageReference)
.With(p =>
{
p.PageName = "OldParent";
p.LinkURL = "oldparent";
})
.SaveAndPublish(ContentRepository);

_newParent = ContentRepository.GetDefault<StartPage>(_startPage.PageLink);
_newParent = ContentRepository.GetDefault<StartPage>(_startPageReference);
_newParent.PageName = "NewParent";
_newParent.LinkURL = "newparent";
ContentRepository.Save(_newParent, SaveAction.Publish, AccessLevel.NoAccess);

_pageToMove = ContentRepository.GetDefault<StartPage>(_oldParent.PageLink);
_pageToMove = ContentRepository.GetDefault<StartPage>(_oldParentReference);
_pageToMove.PageName = "PageToMove";
ContentRepository.Save(_pageToMove, SaveAction.Publish, AccessLevel.NoAccess);
}
Expand Down Expand Up @@ -66,7 +66,7 @@ public void it_should_be_returned_when_getting_children_for_new_parent()
public void it_should_not_be_returned_when_getting_children_for_old_parent()
{
ContentRepository
.GetChildren<StartPage>(_oldParent.PageLink)
.GetChildren<StartPage>(_oldParentReference)
.ShouldNotContain(p => p.PageName == "PageToMove");

}
Expand Down
36 changes: 33 additions & 3 deletions src/WhiteMagic.Tests/ContentRepository/when_saving_a_page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ namespace WhiteMagic.Tests.ContentRepository
{
public class when_saving_a_page : TestBase
{
private StartPage _startPage;
private StartPage _loadedPage;
private PageReference _startPageReference;

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

public override void When()
{
base.When();
_loadedPage = ContentRepository.Get<StartPage>(_startPage.PageLink);

_loadedPage = ContentRepository.Get<StartPage>(_startPageReference);
}

[Test]
Expand All @@ -30,4 +31,33 @@ public void it_should_be_returned_when_loaded()
}

}

public class when_editing_an_existing_page_without_saving_it : TestBase
{
private PageReference _startPageReference;

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

public override void When()
{
base.When();

var startPage = ContentRepository.Get<StartPage>(_startPageReference);
startPage.MainBody = "An edited mainbody";
}

[Test]
public void it_should_not_return_a_value_set_when_page_is_not_saved_afterwards()
{
ContentRepository
.Get<StartPage>(_startPageReference)
.MainBody
.ShouldBe("Hejhej!");
}
}
}
4 changes: 2 additions & 2 deletions src/WhiteMagic.Tests/ContentRepositoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ 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
public static PageReference 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
public static PageReference Publish<T>(this IContentRepository contentRepository, ContentReference parent, Action<T> setValues) where T : IContent
{
return contentRepository
.GetDefault<T>(parent)
Expand Down
2 changes: 1 addition & 1 deletion src/WhiteMagic.Tests/InMemoryContentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private PageData GetPage(PageReference pageLink)
{
throw new PageNotFoundException(pageLink);
}
return pages.Last();
return pages.Last().Copy();
}

private void RaisePageEvent(PageEventHandler pageEvent, PageEventArgs e)
Expand Down

0 comments on commit 5496b09

Please sign in to comment.