Skip to content

Commit

Permalink
Switch from .DotSettings to editorconfig. (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Choc13 authored Jan 14, 2020
1 parent edfde3c commit bc89fd8
Show file tree
Hide file tree
Showing 14 changed files with 1,876 additions and 460 deletions.
1,717 changes: 1,717 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Winton.AspNetCore.Seo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ VisualStudioVersion = 16.0.29403.142
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2509E76A-0210-4FB6-A0FA-7E992D266786}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
Expand Down
474 changes: 86 additions & 388 deletions Winton.AspNetCore.Seo.sln.DotSettings

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,24 @@ internal static OpenGraphProperty Create(PropertyInfo propertyInfo, OpenGraphTag

internal IEnumerable<MetaTag> ToMetaTags()
{
return Value switch {
return Value switch
{
null => Enumerable.Empty<MetaTag>(),
DateTime dateTime => new List<MetaTag> { new MetaTag(FullName, dateTime.ToString("o")) },
IConvertible convertible => new List<MetaTag>
{
new MetaTag(FullName, Convert.ToString(convertible, CultureInfo.InvariantCulture))
},
IEnumerable<object> enumerable => enumerable
.SelectMany(
x => new OpenGraphProperty(FullName, IsPrimary, x)
.ToMetaTags()),
.SelectMany(x => new OpenGraphProperty(FullName, IsPrimary, x).ToMetaTags()),
_ => Value
.GetType()
.GetProperties()
.Select(p => Create(p, this))
.OrderByDescending(ogp => ogp.IsPrimary)
.ThenBy(ogp => ogp.Name)
.SelectMany(ogp => ogp.ToMetaTags())
};
};
}

private static OpenGraphProperty Create(PropertyInfo propertyInfo, OpenGraphProperty parent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ internal static class PropertyInfoExtensions
internal static OpenGraphNamespaceAttribute GetOpenGraphNamespace(this PropertyInfo propertyInfo)
{
return propertyInfo
.DeclaringType?
.GetTypeInfo()
.GetCustomAttribute<OpenGraphNamespaceAttribute>()
.DeclaringType?
.GetTypeInfo()
.GetCustomAttribute<OpenGraphNamespaceAttribute>()
?? throw
new Exception(
$"The type {propertyInfo.DeclaringType?.Name} that declares the property {propertyInfo.Name} is missing the required {nameof(OpenGraphNamespaceAttribute)}");
Expand Down
10 changes: 7 additions & 3 deletions test/TestApp/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
<h1>SEO Routes</h1>
<p>The following pages should be available if the SEO routing is working correctly:</p>
<ul>
<li><a href="/robots.txt">robots.txt</a></li>
<li><a href="/sitemap.xml">sitemap.xml</a></li>
<li>
<a href="/robots.txt">robots.txt</a>
</li>
<li>
<a href="/sitemap.xml">sitemap.xml</a>
</li>
</ul>

<h1>Head Metadata</h1>
Expand Down Expand Up @@ -34,4 +38,4 @@
row.insertCell(1).innerHTML = meta.content;
}
}
</script>
</script>
23 changes: 10 additions & 13 deletions test/TestApp/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
@using System;
@using Winton.AspNetCore.Seo.HeaderMetadata.OpenGraph

@using Winton.AspNetCore.Seo.HeaderMetadata.OpenGraph
<!DOCTYPE html>
<html lang="en">
<head>
<open-graph-article
audio="@(new Audio("http://example.com"))"
authors="@(new List<string> { "http://example.com/choc13" })"
description="Test description"
images="@(new List<Image>
{
new Image("http://example.com/img1.jpg") { SecureUrl = "https://example.com/img1.jpg", Height = 250 },
new Image("http://example.com/img2.jpg") { SecureUrl = "https://example.com/img2.jpg", Height = 300, Width = 500 }
}
)"
images="@(
new List<Image>
{
new Image("http://example.com/img1.jpg") { SecureUrl = "https://example.com/img1.jpg", Height = 250 },
new Image("http://example.com/img2.jpg") { SecureUrl = "https://example.com/img2.jpg", Height = 300, Width = 500 }
})"
published-time="@(new DateTime(2019, 1, 1))"
title="Test"
>
title="Test">
</open-graph-article>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>@ViewData["Title"] - TestApp</title>
</head>
<body>
@RenderBody()
@RenderBody()
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion test/TestApp/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Winton.AspNetCore.Seo
@addTagHelper *, Winton.AspNetCore.Seo
2 changes: 1 addition & 1 deletion test/TestApp/Views/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@{
Layout = "_Layout";
}
}
8 changes: 4 additions & 4 deletions test/TestApp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
},
"Seo": {
"RobotsTxt": {
"AddSitemapUrl": false,
"AddSitemapUrl": false,
"UserAgentRecords": [
{
"UserAgent": "bing",
"Disallow": [ "/login" ]
"Disallow": ["/login"]
},
{
"UserAgent": "google",
"Disallow": [ "*" ]
"Disallow": ["*"]
}
]
},
Expand All @@ -34,4 +34,4 @@
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private void ShouldCreateWithCorrectFullName(string propertyName, string expecte
PropertyInfo propertyInfo = openGraphTagHelper.GetType().GetProperty(propertyName) ??
throw new ArgumentNullException(nameof(propertyInfo));

OpenGraphProperty openGraphProperty = OpenGraphProperty.Create(propertyInfo, openGraphTagHelper);
var openGraphProperty = OpenGraphProperty.Create(propertyInfo, openGraphTagHelper);

openGraphProperty.FullName.Should().Be(expected);
}
Expand All @@ -37,7 +37,7 @@ private void ShouldCreateWithCorrectIsPrimaryValue(string propertyName, bool exp
PropertyInfo propertyInfo = openGraphTagHelper.GetType().GetProperty(propertyName) ??
throw new ArgumentNullException(nameof(propertyInfo));

OpenGraphProperty openGraphProperty = OpenGraphProperty.Create(propertyInfo, openGraphTagHelper);
var openGraphProperty = OpenGraphProperty.Create(propertyInfo, openGraphTagHelper);

openGraphProperty.IsPrimary.Should().Be(expected);
}
Expand All @@ -57,7 +57,7 @@ private void ShouldCreateWithCorrectValue(string propertyName, string expected)
PropertyInfo propertyInfo = openGraphTagHelper.GetType().GetProperty(propertyName)
?? throw new ArgumentNullException(nameof(propertyInfo));

OpenGraphProperty openGraphProperty = OpenGraphProperty.Create(propertyInfo, openGraphTagHelper);
var openGraphProperty = OpenGraphProperty.Create(propertyInfo, openGraphTagHelper);

openGraphProperty.Value.Should().Be(expected);
}
Expand All @@ -72,7 +72,7 @@ private void ShouldReturnFinalSegmentOfFullName()
PropertyInfo propertyInfo =
openGraphTagHelper.GetType().GetProperty(nameof(TestOpenGraphTagHelper.BogStandardProperty)) ??
throw new ArgumentNullException(nameof(propertyInfo));
OpenGraphProperty openGraphProperty = OpenGraphProperty.Create(propertyInfo, openGraphTagHelper);
var openGraphProperty = OpenGraphProperty.Create(propertyInfo, openGraphTagHelper);

string name = openGraphProperty.Name;

Expand Down
42 changes: 21 additions & 21 deletions test/Winton.AspNetCore.Seo.Tests/Robots/RobotsTxtFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ public RobotsTxtFactoryTest()

public sealed class Create : RobotsTxtFactoryTest
{
[Theory]
[InlineData(false, false)]
[InlineData(true, true)]
private void ShouldIncludeSitemapUrl(bool addsiteMapUrl, bool expected)
{
_optionsSnapshot
.Setup(os => os.Value)
.Returns(
new SeoOptions
{
RobotsTxt =
{
AddSitemapUrl = addsiteMapUrl
}
});

string robotsTxt = _robotsFactory.Create();

robotsTxt.Contains("Sitemap").Should().Be(expected);
}

[Fact]
private void ShouldAddAllUserAgentRecordsSeperatedByABlankLine()
{
Expand Down Expand Up @@ -91,27 +112,6 @@ private void ShouldHaveCorrectSitemapUrl()
robotsTxt.Should().Contain("Sitemap: https://example.com:5000/app-root/sitemap.xml");
}

[Theory]
[InlineData(false, false)]
[InlineData(true, true)]
private void ShouldIncludeSitemapUrl(bool addsiteMapUrl, bool expected)
{
_optionsSnapshot
.Setup(os => os.Value)
.Returns(
new SeoOptions
{
RobotsTxt =
{
AddSitemapUrl = addsiteMapUrl
}
});

string robotsTxt = _robotsFactory.Create();

robotsTxt.Contains("Sitemap").Should().Be(expected);
}

[Fact]
private void ShouldNotAddAnyUserAgentRecordsIfEmpty()
{
Expand Down
30 changes: 15 additions & 15 deletions test/Winton.AspNetCore.Seo.Tests/Robots/UserAgentRecordTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ public class UserAgentRecordTest
{
public new sealed class ToString : UserAgentRecordTest
{
[Theory]
[InlineData("Google")]
[InlineData("Bing")]
private void ShouldSetCorrectUserAgent(string userAgent)
{
var userAgentRecord = new UserAgentRecord
{
UserAgent = userAgent
};

var record = userAgentRecord.ToString();

record.Should().Contain($"User-agent: {userAgent}");
}

[Fact]
private void ShouldAllowAllRoutesIfDisallowNotSet()
{
Expand Down Expand Up @@ -57,21 +72,6 @@ private void ShouldContainNoindexDirectiveIfDefinedForUrl()

record.Should().Contain("Noindex: /test").And.Contain("Noindex: /foo");
}

[Theory]
[InlineData("Google")]
[InlineData("Bing")]
private void ShouldSetCorrectUserAgent(string userAgent)
{
var userAgentRecord = new UserAgentRecord
{
UserAgent = userAgent
};

var record = userAgentRecord.ToString();

record.Should().Contain($"User-agent: {userAgent}");
}
}

public sealed class UserAgentProperty : UserAgentRecordTest
Expand Down
4 changes: 2 additions & 2 deletions test/Winton.AspNetCore.Seo.Tests/Sitemaps/SitemapTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ private void ShouldHaveCorrectDataContractName()
private void ShouldHaveCorrectDataContractNamespace()
{
typeof(Sitemap).GetAttribute<CollectionDataContractAttribute>()
.Namespace.Should()
.BeEquivalentTo("http://www.sitemaps.org/schemas/sitemap/0.9");
.Namespace.Should()
.BeEquivalentTo("http://www.sitemaps.org/schemas/sitemap/0.9");
}
}
}

0 comments on commit bc89fd8

Please sign in to comment.