-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for ancestors and descendents
- Loading branch information
1 parent
7e7dae7
commit 5104896
Showing
5 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/WhiteMagic.Tests/ContentRepository/when_getting_ancestors.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using EPiServer.Core; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using WhiteMagic.Tests.Pages; | ||
|
||
namespace WhiteMagic.Tests.ContentRepository | ||
{ | ||
public class when_getting_ancestors : TestBase | ||
{ | ||
private PageReference _pageToUseRef; | ||
private IEnumerable<IContent> _ancestors; | ||
|
||
public override void Given() | ||
{ | ||
base.Given(); | ||
|
||
var startPageReference = ContentRepository.Publish<StartPage>(ContentReference.RootPage, "StartPage"); | ||
var childPage1Reference = ContentRepository.Publish<StartPage>(startPageReference, "ChildPage1"); | ||
var childPage1ChildPage1Reference = ContentRepository.Publish<StandardPage>(childPage1Reference, "ChildPage1-ChildPage1"); | ||
|
||
_pageToUseRef = ContentRepository.Publish<StandardPage>(childPage1ChildPage1Reference, "ChildPage1-ChildPage3-ChildPage1"); | ||
} | ||
|
||
public override void When() | ||
{ | ||
base.When(); | ||
_ancestors = ContentRepository.GetAncestors(_pageToUseRef); | ||
} | ||
|
||
[Test] | ||
public void it_should_return_the_correct_number_of_pages() | ||
{ | ||
_ancestors.Count().ShouldBe(4); | ||
} | ||
|
||
[Test] | ||
public void it_should_return_the_pages_in_order_of_distance_to_origin() | ||
{ | ||
_ancestors.ElementAt(0).Name.ShouldBe("ChildPage1-ChildPage1"); | ||
_ancestors.ElementAt(1).Name.ShouldBe("ChildPage1"); | ||
_ancestors.ElementAt(2).Name.ShouldBe("StartPage"); | ||
_ancestors.ElementAt(3).Name.ShouldBe("RootPage"); | ||
} | ||
} | ||
|
||
public class when_getting_ancestors_for_the_root_page : TestBase | ||
{ | ||
private IEnumerable<IContent> _ancestors; | ||
|
||
//public override void Given() | ||
//{ | ||
// base.Given(); | ||
|
||
// var startPageReference = ContentRepository.Publish<StartPage>(ContentReference.RootPage, "StartPage"); | ||
// var childPage1Reference = ContentRepository.Publish<StartPage>(startPageReference, "ChildPage1"); | ||
// var childPage1ChildPage1Reference = ContentRepository.Publish<StandardPage>(childPage1Reference, "ChildPage1-ChildPage1"); | ||
|
||
// _pageToUseRef = ContentRepository.Publish<StandardPage>(childPage1ChildPage1Reference, "ChildPage1-ChildPage3-ChildPage1"); | ||
//} | ||
|
||
public override void When() | ||
{ | ||
base.When(); | ||
_ancestors = ContentRepository.GetAncestors(ContentReference.RootPage); | ||
} | ||
|
||
[Test] | ||
public void it_should_not_have_any_ancestors() | ||
{ | ||
_ancestors.Count().ShouldBe(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/WhiteMagic.Tests/ContentRepository/when_getting_descendents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using EPiServer.Core; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using WhiteMagic.Tests.Pages; | ||
|
||
namespace WhiteMagic.Tests.ContentRepository | ||
{ | ||
public class when_getting_descendents : TestBase | ||
{ | ||
protected PageReference StartPageReference; | ||
protected PageReference ChildPage3Reference; | ||
protected PageReference ChildPage3ChildPage3Reference; | ||
protected IEnumerable<ContentReference> Descendants; | ||
|
||
public override void Given() | ||
{ | ||
base.Given(); | ||
|
||
StartPageReference = ContentRepository.Publish<StartPage>(ContentReference.RootPage); | ||
|
||
ContentRepository.Publish<StartPage>(StartPageReference, "ChildPage1"); | ||
ContentRepository.Publish<StartPage>(StartPageReference, "ChildPage2"); | ||
ChildPage3Reference = ContentRepository.Publish<StartPage>(StartPageReference, "ChildPage3"); | ||
|
||
ContentRepository.Publish<StandardPage>(ChildPage3Reference, "ChildPage3-ChildPage1"); | ||
ContentRepository.Publish<StandardPage>(ChildPage3Reference, "ChildPage3-ChildPage2"); | ||
ChildPage3ChildPage3Reference = ContentRepository.Publish<StandardPage>(ChildPage3Reference, "ChildPage3-ChildPage3"); | ||
|
||
ContentRepository.Publish<StandardPage>(ChildPage3ChildPage3Reference, "ChildPage3-ChildPage3-ChildPage1"); | ||
ContentRepository.Publish<StandardPage>(ChildPage3ChildPage3Reference, "ChildPage3-ChildPage3-ChildPage2"); | ||
ContentRepository.Publish<StandardPage>(ChildPage3ChildPage3Reference, "ChildPage3-ChildPage3-ChildPage3"); | ||
} | ||
} | ||
|
||
public class when_getting_descendents_from_start_page : when_getting_descendents | ||
{ | ||
public override void When() | ||
{ | ||
base.When(); | ||
Descendants = ContentRepository.GetDescendents(ContentReference.RootPage); | ||
} | ||
|
||
[Test] | ||
public void it_should_return_the_correct_number_of_descendants_including_the_waste_basket_page() | ||
{ | ||
Descendants.Count().ShouldBe(11); | ||
} | ||
} | ||
|
||
public class when_getting_descendents_from_page_deeper_in_structure : when_getting_descendents | ||
{ | ||
|
||
public override void When() | ||
{ | ||
base.When(); | ||
Descendants = ContentRepository.GetDescendents(ChildPage3Reference); | ||
} | ||
|
||
[Test] | ||
public void it_should_return_the_correct_number_of_descendants() | ||
{ | ||
Descendants.Count().ShouldBe(6); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters