Skip to content

Commit 73829be

Browse files
committed
Merge branch 'release/4.1.0'
2 parents c802c44 + de79c61 commit 73829be

25 files changed

+168
-115
lines changed

OnTopic.AspNetCore.Mvc.Tests/OnTopic.AspNetCore.Mvc.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
10-
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
11-
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
10+
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
11+
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

OnTopic.AspNetCore.Mvc.Tests/TopicControllerTest.cs

+11-10
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,24 @@ public void RedirectController_TopicRedirect_ReturnsRedirectResult() {
126126
/// <summary>
127127
/// Triggers the index action of the <see cref="SitemapController.Index()" /> action.
128128
/// </summary>
129-
/// <remarks>
130-
/// Because the <see cref="SitemapController.Index()"/> method references the <see cref="Controller.Response"/> property,
131-
/// which is not set during unit testing, this test is <i>expected</i> to throw an exception. This is not ideal. In the
132-
/// future, this may be modified to instead use a mock <see cref="ControllerContext"/> for a more sophisticated test.
133-
/// </remarks>
134129
[TestMethod]
135-
[ExpectedException(typeof(NullReferenceException), AllowDerivedTypes=false)]
136130
public void SitemapController_Index_ReturnsSitemapXml() {
137131

138-
var controller = new SitemapController(_topicRepository);
139-
var result = controller.Index() as ViewResult;
140-
var model = result.Model as string;
132+
var actionContext = new ActionContext {
133+
HttpContext = new DefaultHttpContext(),
134+
RouteData = new RouteData(),
135+
ActionDescriptor = new ControllerActionDescriptor()
136+
};
137+
var controller = new SitemapController(_topicRepository) {
138+
ControllerContext = new ControllerContext(actionContext)
139+
};
140+
var result = controller.Index() as ContentResult;
141+
var model = result.Content as string;
141142

142143
controller.Dispose();
143144

144145
Assert.IsNotNull(model);
145-
Assert.IsTrue(model.StartsWith("<?xml version=\"1.0\" encoding=\"utf-16\"?>"));
146+
Assert.IsTrue(model.StartsWith("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>"));
146147
Assert.IsTrue(model.Contains("/Web/Web_1/Web_1_1/Web_1_1_1/</loc>"));
147148

148149
}

OnTopic.AspNetCore.Mvc/Controllers/SitemapController.cs

+6-8
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public SitemapController(ITopicRepository topicRepository) {
9090
/// <summary>
9191
/// Provides the Sitemap.org sitemap for the site.
9292
/// </summary>
93+
/// <param name="indent">Optionally enables indentation of XML elements in output for human readability.</param>
9394
/// <returns>The site's homepage view.</returns>
94-
public virtual ActionResult Index() {
95+
public virtual ActionResult Index(bool indent = false) {
9596

9697
/*------------------------------------------------------------------------------------------------------------------------
9798
| Ensure topics are loaded
@@ -107,16 +108,14 @@ public virtual ActionResult Index() {
107108
/*------------------------------------------------------------------------------------------------------------------------
108109
| Establish sitemap
109110
\-----------------------------------------------------------------------------------------------------------------------*/
110-
var sitemap = GenerateSitemap(rootTopic);
111-
var sitemapFile = new StringBuilder();
112-
using (var writer = new StringWriter(sitemapFile)) {
113-
sitemap.Save(writer);
114-
}
111+
var declaration = new XDeclaration("1.0", "utf-8", "no");
112+
var sitemap = GenerateSitemap(rootTopic);
113+
var settings = indent? SaveOptions.None : SaveOptions.DisableFormatting;
115114

116115
/*------------------------------------------------------------------------------------------------------------------------
117116
| Return the homepage view
118117
\-----------------------------------------------------------------------------------------------------------------------*/
119-
return Content(sitemapFile.ToString(), "text/xml");
118+
return Content(declaration.ToString() + sitemap.ToString(settings), "text/xml");
120119

121120
}
122121

@@ -129,7 +128,6 @@ public virtual ActionResult Index() {
129128
/// <returns>The site's homepage view.</returns>
130129
public virtual XDocument GenerateSitemap(Topic rootTopic) =>
131130
new XDocument(
132-
new XDeclaration("1.0", "utf-8", String.Empty),
133131
new XElement(_sitemapNamespace + "urlset",
134132
from topic in rootTopic?.Children
135133
select AddTopic(topic)

OnTopic.AspNetCore.Mvc/OnTopic.AspNetCore.Mvc.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939

4040
<ItemGroup>
4141
<FrameworkReference Include="Microsoft.AspNetCore.App" />
42-
<PackageReference Include="GitVersionTask" Version="5.0.1">
42+
<PackageReference Include="GitVersionTask" Version="5.2.4">
4343
<PrivateAssets>all</PrivateAssets>
44+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4445
</PackageReference>
45-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4">
46+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
4647
<PrivateAssets>all</PrivateAssets>
4748
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
4849
</PackageReference>

OnTopic.Data.Caching/OnTopic.Data.Caching.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
</PropertyGroup>
4040

4141
<ItemGroup>
42-
<PackageReference Include="GitVersionTask" Version="5.0.1">
42+
<PackageReference Include="GitVersionTask" Version="5.2.4">
4343
<PrivateAssets>all</PrivateAssets>
44+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4445
</PackageReference>
45-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4">
46+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
4647
<PrivateAssets>all</PrivateAssets>
4748
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
4849
</PackageReference>

OnTopic.Data.Sql.Database/Stored Procedures/GetTopics.sql

+5-3
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,18 @@ ORDER BY SortOrder
102102
--------------------------------------------------------------------------------------------------------------------------------
103103
SELECT Attributes.TopicID,
104104
Attributes.AttributeKey,
105-
Attributes.AttributeValue
105+
Attributes.AttributeValue,
106+
Attributes.Version
106107
FROM AttributeIndex Attributes
107108
JOIN #Topics AS Storage
108109
ON Storage.TopicID = Attributes.TopicID
109110

110111
--------------------------------------------------------------------------------------------------------------------------------
111-
-- SELECT AttributeXml
112+
-- SELECT EXTENDED ATTRIBUTES
112113
--------------------------------------------------------------------------------------------------------------------------------
113114
SELECT Attributes.TopicID,
114-
Attributes.AttributesXml
115+
Attributes.AttributesXml,
116+
Attributes.Version
115117
FROM ExtendedAttributeIndex AS Attributes
116118
JOIN #Topics AS Storage
117119
ON Storage.TopicID = Attributes.TopicID

OnTopic.Data.Sql.Database/Stored Procedures/MoveTopic.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ BEGIN
220220
WHERE RangeLeft
221221
BETWEEN @InsertionPoint
222222
AND @OriginalRight
223-
OR RangeRight
223+
OR ISNULL(RangeRight, -1)
224224
BETWEEN @InsertionPoint
225225
AND @OriginalRight
226226

@@ -290,7 +290,7 @@ BEGIN
290290
WHERE RangeLeft
291291
BETWEEN @OriginalLeft
292292
AND @InsertionPoint - 1
293-
OR RangeRight
293+
OR ISNULL(RangeRight, 0)
294294
BETWEEN @OriginalLeft
295295
AND @InsertionPoint - 1
296296

OnTopic.Data.Sql.Database/Stored Procedures/UpdateRelationships.sql

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,29 @@ DECLARE @Existing_TopicIDs TopicList
2020
--------------------------------------------------------------------------------------------------------------------------------
2121
INSERT
2222
INTO @Existing_TopicIDs (
23-
TopicId
23+
TopicID
2424
)
25-
SELECT Target_TopicId
25+
SELECT Target_TopicID
2626
FROM Relationships
27-
WHERE Source_TopicId = @TopicID
27+
WHERE Source_TopicID = @TopicID
2828
AND RelationshipKey = @RelationshipKey
2929

3030
--------------------------------------------------------------------------------------------------------------------------------
3131
-- INSERT NOVEL VALUES
3232
--------------------------------------------------------------------------------------------------------------------------------
3333
INSERT
3434
INTO Relationships (
35-
Source_TopicId,
35+
Source_TopicID,
3636
RelationshipKey,
37-
Target_TopicId
37+
Target_TopicID
3838
)
3939
SELECT @TopicId,
4040
@RelationshipKey,
41-
Target.TopicId
41+
Target.TopicID
4242
FROM @RelatedTopics Target
4343
FULL JOIN @Existing_TopicIDs Existing
44-
ON Existing.TopicId = Target.TopicId
45-
WHERE Existing.TopicId is null
44+
ON Existing.TopicID = Target.TopicID
45+
WHERE Existing.TopicID is null
4646

4747
--------------------------------------------------------------------------------------------------------------------------------
4848
-- RETURN TOPIC ID

OnTopic.Data.Sql.Database/Stored Procedures/ValidateHierarchy.sql

+12-10
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ AS
2020
--------------------------------------------------------------------------------------------------------------------------------
2121
PRINT 'Detect range overlaps'
2222

23-
SELECT *
23+
SELECT TopicID,
24+
RangeLeft,
25+
RangeRight
2426
FROM Topics OuterTopics
2527
WHERE (
2628
SELECT COUNT(TopicID)
2729
FROM Topics InnerTopics
2830
WHERE ( RangeLeft < OuterTopics.RangeLeft
29-
AND RangeRight < OuterTopics.RangeRight
30-
AND RangeRight > OuterTopics.RangeLeft
31+
AND ISNULL(RangeRight, -1) < ISNULL(OuterTopics.RangeRight, -1)
32+
AND ISNULL(RangeRight, -1) > OuterTopics.RangeLeft
3133
)
3234
OR ( RangeLeft > OuterTopics.RangeLeft
33-
AND RangeRight > OuterTopics.RangeRight
34-
AND RangeLeft < OuterTopics.RangeRight
35+
AND ISNULL(RangeRight, -1) > ISNULL(OuterTopics.RangeRight, -1)
36+
AND RangeLeft < ISNULL(OuterTopics.RangeRight, -1)
3537
)
3638
) > 0
3739

@@ -54,11 +56,11 @@ WHERE (
5456
WHERE TopicID != OuterTopics.TopicID
5557
AND ( RangeLeft
5658
IN ( OuterTopics.RangeLeft,
57-
OuterTopics.RangeRight
59+
ISNULL(OuterTopics.RangeRight, -1)
5860
)
59-
OR RangeRight
61+
OR ISNULL(RangeRight, 0)
6062
IN ( OuterTopics.RangeLeft,
61-
OuterTopics.RangeRight
63+
ISNULL(OuterTopics.RangeRight, -1)
6264
)
6365
)
6466
) > 0
@@ -74,7 +76,7 @@ SELECT TopicID,
7476
RangeLeft,
7577
RangeRight
7678
FROM Topics
77-
WHERE RangeLeft >= RangeRight
79+
WHERE RangeLeft >= ISNULL(RangeRight, -1)
7880

7981
--------------------------------------------------------------------------------------------------------------------------------
8082
-- DETECT PARENT ID MISMATCHES
@@ -88,4 +90,4 @@ SELECT TopicID,
8890
AttributeValue
8991
FROM Attributes
9092
WHERE AttributeKey = 'ParentID'
91-
AND AttributeValue != dbo.GetParentID(TopicID)
93+
AND AttributeValue != CAST(dbo.GetParentID(TopicID) AS VARCHAR(255))

OnTopic.Data.Sql.Database/Types/TopicList.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
CREATE
88
TYPE [dbo].[TopicList]
99
AS TABLE (
10-
TopicId INT NOT NULL
11-
PRIMARY KEY ( TopicId )
10+
TopicID INT NOT NULL
11+
PRIMARY KEY ( TopicID )
1212
)

OnTopic.Data.Sql.Database/Views/AttributeIndex.sql

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITH Attributes AS (
1313
SELECT TopicID,
1414
AttributeKey,
1515
AttributeValue,
16+
Version,
1617
RowNumber = ROW_NUMBER() OVER (
1718
PARTITION BY TopicID,
1819
AttributeKey
@@ -27,6 +28,7 @@ WITH Attributes AS (
2728
)
2829
SELECT Attributes.TopicID,
2930
Attributes.AttributeKey,
30-
Attributes.AttributeValue
31+
Attributes.AttributeValue,
32+
Attributes.Version
3133
FROM Attributes
3234
WHERE RowNumber = 1

OnTopic.Data.Sql.Database/Views/ExtendedAttributeIndex.sql

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ AS
1212
WITH TopicExtendedAttributes AS (
1313
SELECT TopicID,
1414
AttributesXml,
15+
Version,
1516
RowNumber = ROW_NUMBER() OVER (
1617
PARTITION BY TopicID
1718
ORDER BY Version DESC
1819
)
1920
FROM [dbo].[ExtendedAttributes]
2021
)
2122
SELECT TopicID,
22-
AttributesXml
23+
AttributesXml,
24+
Version
2325
FROM TopicExtendedAttributes
2426
WHERE RowNumber = 1

OnTopic.Data.Sql/OnTopic.Data.Sql.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
</PropertyGroup>
3737

3838
<ItemGroup>
39-
<PackageReference Include="GitVersionTask" Version="5.0.1">
39+
<PackageReference Include="GitVersionTask" Version="5.2.4">
4040
<PrivateAssets>all</PrivateAssets>
41+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4142
</PackageReference>
42-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4">
43+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
4344
<PrivateAssets>all</PrivateAssets>
4445
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
4546
</PackageReference>
46-
<PackageReference Include="System.Data.SqlClient" Version="4.7.0" />
47+
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.1" />
4748
</ItemGroup>
4849

4950
<ItemGroup>

0 commit comments

Comments
 (0)