Skip to content

Commit e4a90a0

Browse files
committed
Introduced test to validate IsPrivateBranch behavior
The test adds a new `Page` marked with the `IsPrivateBranch` attribute, as well as a child, and confirms that neither the page, nor its child, appear in the `SitemapController`. This validates the functionality introduced in dfd98af, and as specified in #72.
1 parent dfd98af commit e4a90a0

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

OnTopic.AspNetCore.Mvc.Tests/TestDoubles/TestTopicRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ private static Topic CreateFakeData() {
6868
_ = new Topic("NoIndexChild", "Page", noIndexPage);
6969
var noIndexContainer = new Topic("NoIndexContainer", "Container", webTopic);
7070
_ = new Topic("NoIndexContainerChild", "Page", noIndexContainer);
71+
var privateBranch = new Topic("PrivateBranch", "Page", webTopic);
72+
_ = new Topic("PrivateBranchChild", "Page", privateBranch);
7173
var disabledPage = new Topic("Disabled", "Page", webTopic);
7274
var pageGroup = new Topic("PageGroup", "PageGroup", rootTopic);
7375
_ = new Topic("PageGroupChild", "Page", pageGroup);
@@ -97,6 +99,7 @@ private static Topic CreateFakeData() {
9799

98100
//Excluded descendants
99101
noIndexContainer.Attributes.SetBoolean("NoIndex", true);
102+
privateBranch.Attributes.SetBoolean("IsPrivateBranch", true);
100103

101104
/*------------------------------------------------------------------------------------------------------------------------
102105
| Return data

OnTopic.AspNetCore.Mvc.Tests/TopicControllerTest.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ public void SitemapController_Index_ExcludesContentTypes() {
207207
[Fact]
208208
public void SitemapController_Index_ExcludesContainerDescendants() {
209209

210-
var controller = new SitemapController(_topicRepository) {
211-
ControllerContext = new(_context)
210+
var controller = new SitemapController(_topicRepository) {
211+
ControllerContext = new(_context)
212212
};
213-
var result = controller.Extended(true) as ContentResult;
214-
var model = result?.Content as string;
213+
var result = controller.Extended(true) as ContentResult;
214+
var model = result?.Content as string;
215215

216216
controller.Dispose();
217217

@@ -221,6 +221,29 @@ public void SitemapController_Index_ExcludesContainerDescendants() {
221221

222222
}
223223

224+
/*==========================================================================================================================
225+
| TEST: SITEMAP CONTROLLER: INDEX: EXCLUDES PRIVATE BRANCHES
226+
\-------------------------------------------------------------------------------------------------------------------------*/
227+
/// <summary>
228+
/// Triggers the index action of the <see cref="SitemapController.Index(Boolean, Boolean)" /> action and verifies that it
229+
/// properly excludes the topics that are marked as <c>IsPrivateBranch</c>, including their descendants.
230+
/// </summary>
231+
[Fact]
232+
public void SitemapController_Index_ExcludesPrivateBranches() {
233+
234+
var controller = new SitemapController(_topicRepository) {
235+
ControllerContext = new(_context)
236+
};
237+
var result = controller.Extended(true) as ContentResult;
238+
var model = result?.Content as string;
239+
240+
controller.Dispose();
241+
242+
Assert.NotNull(model);
243+
Assert.False(model!.Contains("PrivateBranch/</loc>", StringComparison.Ordinal));
244+
Assert.False(model!.Contains("PrivateBranchChild/</loc>", StringComparison.Ordinal));
245+
246+
}
224247

225248
/*==========================================================================================================================
226249
| TEST: SITEMAP CONTROLLER: EXTENDED: INCLUDES ATTRIBUTES

0 commit comments

Comments
 (0)