Skip to content

Commit

Permalink
Added additional tests for when getting children
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanforsberg committed Aug 28, 2013
1 parent 7977909 commit 7e7dae7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
19 changes: 18 additions & 1 deletion src/WhiteMagic.Tests/ContentRepository/when_getting_a_page.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using EPiServer.Core;
using NUnit.Framework;
using Shouldly;
using WhiteMagic.Tests.Pages;

namespace WhiteMagic.Tests.ContentRepository
Expand All @@ -12,7 +13,23 @@ public override void Given()
{
base.Given();
StartPageReference = ContentRepository
.Publish<StartPage>(ContentReference.RootPage, p => p.MainBody = "Hejhej!");
.Publish<StartPage>(ContentReference.RootPage, "StartPage");
}
}

public class when_getting_a_page_with_base_type_constraint : when_getting_a_page
{
private PageData _page;

public override void When()
{
_page = ContentRepository.Get<PageData>(StartPageReference);
}

[Test]
public void it_should_return_a_page_typed_to_the_base_type()
{
_page.PageName.ShouldBe("StartPage");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using EPiServer.Core;
using EPiServer.DataAccess;
using EPiServer.Security;
using NUnit.Framework;
using Shouldly;
using WhiteMagic.Tests.Pages;
Expand Down Expand Up @@ -44,4 +42,43 @@ public void it_should_not_include_page_with_none_matching_page_type()
_children.ShouldNotContain(s => s.PageName == "ChildPage3");
}
}

public class when_getting_children_with_a_none_matching_page_type : TestBase
{

IEnumerable<StandardPage> _children;
private PageReference _startPageReference;

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

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

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

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

[Test]
public void it_should_not_fetch_any_children()
{
_children.Count().ShouldBe(0);
}
}

public class when_getting_children_for_a_none_existing_page : TestBase
{
[Test]
public void it_should_throw_a_page_not_found_exception()
{
Assert.Throws<PageNotFoundException>(() => ContentRepository.GetChildren<PageData>(new ContentReference(1000)));
}
}
}
4 changes: 4 additions & 0 deletions src/WhiteMagic.Tests/InMemoryContentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ private PageDataCollection GetChildren(PageReference pageLink, int startIndex, i
children.Add(GetPage(link));
}
}
else
{
throw new PageNotFoundException(pageLink);
}

return new PageDataCollection(children);
}
Expand Down
2 changes: 1 addition & 1 deletion src/WhiteMagic.Tests/WhiteMagic.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
<Compile Include="Pages\StartPage.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ContentRepository\when_getting_children_by_page_type.cs" />
<Compile Include="ContentRepository\when_getting_children.cs" />
<Compile Include="ContentRepository\when_moving_a_page.cs" />
<Compile Include="ContentRepository\when_saving_a_page.cs" />
</ItemGroup>
Expand Down

0 comments on commit 7e7dae7

Please sign in to comment.