Skip to content

Commit d3e2955

Browse files
Revert "Makes this solution testable (bypassing EssentialCSharp.Common)"
This reverts commit 710418c.
1 parent 710418c commit d3e2955

File tree

3 files changed

+5
-132
lines changed

3 files changed

+5
-132
lines changed

EssentialCSharp.Web/Controllers/HomeController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public HomeController(ILogger<HomeController> logger, IWebHostEnvironment hostin
2525
public IActionResult Index(string key)
2626
{
2727
// if no key (default case), then load up home page
28-
Services.SiteMapping? siteMapping = _SiteMappingService.SiteMappings.Find(key);
28+
SiteMapping? siteMapping = _SiteMappingService.SiteMappings.Find(key);
2929

3030
if (string.IsNullOrEmpty(key))
3131
{
@@ -107,7 +107,7 @@ private string FlipPage(int currentChapter, int currentPage, bool next)
107107
page = 1;
108108
}
109109

110-
Services.SiteMapping? siteMap = _SiteMappingService.SiteMappings.FirstOrDefault(f => f.ChapterNumber == currentChapter && f.PageNumber == currentPage + page);
110+
SiteMapping? siteMap = _SiteMappingService.SiteMappings.FirstOrDefault(f => f.ChapterNumber == currentChapter && f.PageNumber == currentPage + page);
111111

112112
if (siteMap is null)
113113
{

EssentialCSharp.Web/Extensions/SiteMappingListExtensions.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using EssentialCSharp.Web.Services;
2-
3-
namespace EssentialCSharp.Web.Extensions;
1+
namespace EssentialCSharp.Web.Extensions;
42

53
public static class SiteMappingListExtensions
64
{
@@ -10,15 +8,15 @@ public static class SiteMappingListExtensions
108
/// <param name="siteMappings">IList of SiteMappings</param>
119
/// <param name="key">If null, uses the first key in the list</param>
1210
/// <returns>If found, the site mapping that matches the key, otherwise null.</returns>
13-
public static Services.SiteMapping? Find(this IList<Services.SiteMapping> siteMappings, string? key)
11+
public static SiteMapping? Find(this IList<SiteMapping> siteMappings, string? key)
1412
{
1513
if (string.IsNullOrWhiteSpace(key))
1614
{
1715
return siteMappings.FirstOrDefault();
1816
}
1917
foreach (string? potentialMatch in key.GetPotentialMatches())
2018
{
21-
if (siteMappings.FirstOrDefault(x => x.Keys.Any(k => k == potentialMatch)) is { } siteMap)
19+
if (siteMappings.FirstOrDefault(x => x.Keys.Any(x => x == potentialMatch)) is { } siteMap)
2220
{
2321
return siteMap;
2422
}

EssentialCSharp.Web/Services/SiteMappingService.cs

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -51,128 +51,3 @@ private static IEnumerable<SiteMappingDto> GetItems(IEnumerable<SiteMapping> cha
5151
});
5252
}
5353
}
54-
55-
/// <summary>
56-
/// A model for a site mapping to transport between the tooling and the web app so the web app knows where to find the content a user is looking for.
57-
/// </summary>
58-
public class SiteMapping
59-
{
60-
/// <param name="keys">The key for the site mapping.</param>
61-
/// <param name="pagePath">The path to the actual HTML page.</param>
62-
/// <param name="chapterNumber">The chapter number of the content.</param>
63-
/// <param name="pageNumber">The page number of the content.</param>
64-
/// <param name="orderOnPage">A number indicating order on a page.</param>
65-
/// <param name="chapterTitle">The title of the chapter.</param>
66-
/// <param name="rawHeading">The raw heading of the content.</param>
67-
/// <param name="anchorId">The anchor ID of the content. This allows you to know what anchors are on a page and get to that specific area.</param>
68-
/// <param name="indentLevel">The indent level of the content. This is used to determine how the content is displayed in the table of contents.</param>
69-
/// <param name="contentHash">A hash of the content. This is used to determine if the content has changed and needs to be updated.</param>
70-
/// <param name="includeInSitemapXml"><see cref="IncludeInSitemapXml"/></param>
71-
public SiteMapping(List<string> keys, string[] pagePath, int chapterNumber, int pageNumber, int orderOnPage, string chapterTitle, string rawHeading, string? anchorId,
72-
int indentLevel, string? contentHash = null, bool includeInSitemapXml = true)
73-
{
74-
Keys = keys;
75-
PagePath = pagePath;
76-
ChapterNumber = chapterNumber;
77-
PageNumber = pageNumber;
78-
OrderOnPage = orderOnPage;
79-
ChapterTitle = chapterTitle;
80-
RawHeading = rawHeading;
81-
ContentHash = contentHash;
82-
AnchorId = anchorId;
83-
IndentLevel = indentLevel;
84-
IncludeInSitemapXml = includeInSitemapXml;
85-
}
86-
87-
/// <summary>
88-
/// The key for the site mapping.
89-
/// </summary>
90-
public List<string> Keys { get; }
91-
/// <summary>
92-
/// The path to the actual HTML page.
93-
/// </summary>
94-
public string[] PagePath { get; }
95-
/// <summary>
96-
/// The chapter number of the content.
97-
/// </summary>
98-
public int ChapterNumber { get; }
99-
/// <summary>
100-
/// The page number of the content.
101-
/// </summary>
102-
public int PageNumber { get; }
103-
/// <summary>
104-
/// A number indicating order on a page.
105-
/// </summary>
106-
public int OrderOnPage { get; set; }
107-
/// <summary>
108-
/// The title of the chapter.
109-
/// </summary>
110-
public string ChapterTitle { get; }
111-
/// <summary>
112-
/// The raw heading of the content.
113-
/// </summary>
114-
public string RawHeading { get; set; }
115-
/// <summary>
116-
/// The hash of the content. This is used to determine if the content has changed and needs to be updated.
117-
/// This should be a base64 encoded string of the hash.
118-
/// This should not be null by the time parsing is complete.
119-
/// </summary>
120-
public string? ContentHash { get; set; }
121-
/// <summary>
122-
/// The anchor ID of the content. This allows you to know what anchors are on a page and get to that specific area.
123-
/// </summary>
124-
public string? AnchorId { get; }
125-
/// <summary>
126-
/// The indent level of the content. This is used to determine how the content is displayed in the table of contents.
127-
/// </summary>
128-
public int IndentLevel { get; }
129-
/// <summary>
130-
/// Whether or not to include this in the sitemap. This is used to determine if a page should be included in the sitemap XML file.
131-
/// Only the top most heading of a page should be included in the sitemap, and the rest will be canonical links.
132-
/// This is only used to parse the Sitemap XML file.
133-
/// </summary>
134-
public bool IncludeInSitemapXml { get; }
135-
136-
/// <inheritdoc/>
137-
public override bool Equals(object? obj)
138-
{
139-
if (obj is SiteMapping other)
140-
{
141-
return Keys == other.Keys &&
142-
PagePath?.SequenceEqual(other.PagePath) == true &&
143-
ChapterNumber == other.ChapterNumber &&
144-
PageNumber == other.PageNumber &&
145-
OrderOnPage == other.OrderOnPage &&
146-
ChapterTitle == other.ChapterTitle &&
147-
RawHeading == other.RawHeading &&
148-
AnchorId == other.AnchorId &&
149-
IndentLevel == other.IndentLevel &&
150-
IncludeInSitemapXml == other.IncludeInSitemapXml;
151-
}
152-
return false;
153-
}
154-
155-
/// <inheritdoc/>
156-
public override int GetHashCode()
157-
{
158-
// HashCode.Combine doesn't work for more than 8 items.
159-
HashCode hash = new();
160-
hash.Add(Keys);
161-
hash.Add(PagePath);
162-
hash.Add(ChapterNumber);
163-
hash.Add(PageNumber);
164-
hash.Add(OrderOnPage);
165-
hash.Add(ChapterTitle);
166-
hash.Add(RawHeading);
167-
hash.Add(AnchorId);
168-
hash.Add(IndentLevel);
169-
hash.Add(IncludeInSitemapXml);
170-
return hash.ToHashCode();
171-
}
172-
173-
/// <inheritdoc/>
174-
public override string ToString()
175-
{
176-
return $"{ChapterNumber}.{PageNumber} - {ChapterTitle} - Raw Heading: {RawHeading} - Hash: {ContentHash} {Environment.NewLine} {string.Join(", ", Keys)}";
177-
}
178-
}

0 commit comments

Comments
 (0)