Skip to content

Commit

Permalink
Add snapshot tests to verify output HTMLs using Verify.DiffPlex
Browse files Browse the repository at this point in the history
  • Loading branch information
mjebrahimi committed Aug 17, 2024
1 parent 66b9e27 commit ed4f056
Show file tree
Hide file tree
Showing 11 changed files with 444 additions and 10 deletions.
25 changes: 21 additions & 4 deletions SeoTags.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
# 17
VisualStudioVersion = 17.11.35208.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeoTags", "src\SeoTags\SeoTags.csproj", "{79B6DCB0-A90A-4FAE-8991-54E8B074238E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SeoTags", "src\SeoTags\SeoTags.csproj", "{79B6DCB0-A90A-4FAE-8991-54E8B074238E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeoTags.Sample", "samples\SeoTags.Sample\SeoTags.Sample.csproj", "{1E4A16D9-D32A-4861-A16D-E159BFCAE242}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SeoTags.Sample", "samples\SeoTags.Sample\SeoTags.Sample.csproj", "{1E4A16D9-D32A-4861-A16D-E159BFCAE242}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{423B1D61-B72F-49B0-92DB-9C43A47373B1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{34790F8E-1E62-4C8D-B800-1286A5DA2CF3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{30E17BFF-8BD2-44EC-9161-E84165169F0F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SeoTags.Tests", "test\SeoTags.Tests\SeoTags.Tests.csproj", "{5F9CC441-47F2-4101-B478-B265843B5EFE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,10 +29,19 @@ Global
{1E4A16D9-D32A-4861-A16D-E159BFCAE242}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E4A16D9-D32A-4861-A16D-E159BFCAE242}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E4A16D9-D32A-4861-A16D-E159BFCAE242}.Release|Any CPU.Build.0 = Release|Any CPU
{5F9CC441-47F2-4101-B478-B265843B5EFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F9CC441-47F2-4101-B478-B265843B5EFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F9CC441-47F2-4101-B478-B265843B5EFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F9CC441-47F2-4101-B478-B265843B5EFE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{79B6DCB0-A90A-4FAE-8991-54E8B074238E} = {34790F8E-1E62-4C8D-B800-1286A5DA2CF3}
{1E4A16D9-D32A-4861-A16D-E159BFCAE242} = {423B1D61-B72F-49B0-92DB-9C43A47373B1}
{5F9CC441-47F2-4101-B478-B265843B5EFE} = {30E17BFF-8BD2-44EC-9161-E84165169F0F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4FD97B23-0BC0-4048-A060-C3D0F160AB50}
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion samples/SeoTags.Sample/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public IActionResult Index()
{
//HttpContext.SetSeoInfo(seoInfo =>
//{
// //Set seo info
// //Set SEO info
//});
return View();
}
Expand Down
2 changes: 1 addition & 1 deletion samples/SeoTags.Sample/SeoTags.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SeoTags\SeoTags.csproj" />
<ProjectReference Include="..\..\src\SeoTags\SeoTags.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions samples/SeoTags.Sample/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
cardType: SeoTags.TwitterCardType.SummaryLargeImage)
.SetArticleInfo(
authorName: "Author Name",
publishDate: DateTimeOffset.Now,
modifiedDate: DateTimeOffset.Now,
publishDate: DateTimeOffset.Parse("2024-08-17 22:00"),
modifiedDate: DateTimeOffset.Parse("2024-08-17 23:00"),
authorTwitterId: "@MyTwitterId",
authorFacebookId: "https://facebook.com/MyUserId",
authorUrl: "https://github.com/author-profile",
Expand Down
4 changes: 2 additions & 2 deletions samples/SeoTags.Sample/Views/Home/JsonLd2.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
Description = "Page Description",
Keywords = new[] { "SEO", "AspNetCore", "MVC", "RazorPages" },
Images = new[] { ImageInfo.ReferTo(image) },
DatePublished = DateTimeOffset.Now,
DateModified = DateTimeOffset.Now,
DatePublished = DateTimeOffset.Parse("2024-08-17 22:00"),
DateModified = DateTimeOffset.Parse("2024-08-17 23:00"),
InLanguage = "en-US",
Author = author.Id, //or PersonInfo.ReferTo(author.Id) or PersonInfo.ReferTo(author)
WebSite = website.Id, //or WebSiteInfo.ReferTo(website.Id) or WebSiteInfo.ReferTo(website)
Expand Down
31 changes: 31 additions & 0 deletions test/SeoTags.Tests/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Mvc.Testing;
using SeoTags.Sample;
using VerifyTests.DiffPlex;

namespace ParkBee.Assessment.IntegrationTests.Common;

public class IntegrationTestBase(WebApplicationFactory<Program> webApplicationFactory) : IClassFixture<WebApplicationFactory<Program>>
{
private static readonly string _snapshotsPath = Path.Combine(GetProjectDirectory(), "_snapshots");

static IntegrationTestBase()
{
VerifyDiffPlex.Initialize(OutputType.Compact);
DerivePathInfo((_, _, type, method) => new PathInfo(_snapshotsPath, type.Name, method.Name));
}

protected WebApplicationFactory<Program> WebApplicationFactory { get; } = webApplicationFactory;
protected HttpClient HttpClient { get; } = webApplicationFactory.CreateClient();

public async Task VerifyHtml(string html)
{
await Verify(html, "html");
}

private static string GetProjectDirectory()
{
var currentDirectory = AppContext.BaseDirectory;
var path = Path.Combine(currentDirectory, "..", "..", "..");
return Path.GetFullPath(path);
}
}
32 changes: 32 additions & 0 deletions test/SeoTags.Tests/SeoTags.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="All" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="FluentAssertions.Analyzers" Version="0.33.0" PrivateAssets="All" />
<PackageReference Include="Verify.DiffPlex" Version="3.1.0" />
<PackageReference Include="Verify.Xunit" Version="26.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\samples\SeoTags.Sample\SeoTags.Sample.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions test/SeoTags.Tests/VerifyExamples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc.Testing;
using ParkBee.Assessment.IntegrationTests.Common;
using SeoTags.Sample;
namespace SeoTags.Tests;

public class VerifyExamples(WebApplicationFactory<Program> webApplicationFactory) : IntegrationTestBase(webApplicationFactory)
{
[Fact]
public async Task TestSimple()
{
var html = await HttpClient.GetStringAsync("/");
await VerifyHtml(html);
}

[Fact]
public async Task TestJsonLd1()
{
var html = await HttpClient.GetStringAsync("/Home/JsonLd1");
await VerifyHtml(html);
}

[Fact]
public async Task TestJsonLd2()
{
var html = await HttpClient.GetStringAsync("/Home/JsonLd2");
await VerifyHtml(html);
}
}
101 changes: 101 additions & 0 deletions test/SeoTags.Tests/_snapshots/VerifyExamples.TestJsonLd1.verified.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin />
<link rel="preconnect" href="https://www.google-analytics.com" crossorigin />
<link rel="dns-prefetch" href="https://fonts.gstatic.com/" />
<link rel="dns-prefetch" href="https://www.google-analytics.com" />
<link rel="preload" as="style" href="https://site.com/site.css" />
<link rel="preload" as="script" href="https://site.com/app.js" />
<link rel="preload" as="font" type="font/woff2" href="https://site.com/fonts/Font.woff2" crossorigin />
<link rel="preload" as="font" type="font/woff2" href="https://site.com/fonts/Font_Light.woff2" crossorigin />
<link rel="preload" as="font" type="font/woff2" href="https://site.com/fonts/Font_Medium.woff2" crossorigin />
<link rel="preload" as="font" type="font/woff2" href="https://site.com/fonts/Font_Bold.woff2" crossorigin />

<title> - My Site Title</title>
<meta name="title" content=" - My Site Title" />
<link rel="application/opensearchdescription+xml" title="My Site Title" href="https://site.com/open-search.xml" />
<link rel="alternate" type="application/rss+xml" title="Post Feeds" href="https://site.com/rss/" />
<meta name="robots" content="index, follow" />

<meta name="twitter:site" content="@MySiteTwitter" />

<meta property="og:site_name" content="My Site Title" />
<meta property="og:locale" content="en_US" />

<script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"Product","@id":"https://site.com/product-url/#product","name":"Product Name","description":"Product Description","alternateName":"Product AlternateName","image":[{"@type":"ImageObject","@id":"https://site.com/uploads/image-1.jpg#image","url":"https://site.com/uploads/image-1.jpg","inLanguage":"en-US","contentUrl":"https://site.com/uploads/image-1.jpg","height":"720","width":"1280","caption":"Image Name"},{"@type":"ImageObject","@id":"https://site.com/uploads/image-2.jpg#image","url":"https://site.com/uploads/image-2.jpg","inLanguage":"en-US","contentUrl":"https://site.com/uploads/image-2.jpg","height":"720","width":"1280","caption":"Image Name 2"}],"url":"https://site.com/product-url/","aggregateRating":{"@type":"AggregateRating","bestRating":5.0,"ratingValue":4.5,"worstRating":1.0,"ratingCount":123,"reviewCount":123},"brand":{"@type":"Brand","name":"Brand Name"},"category":"Product Category","mpn":"12345","offers":{"@type":"AggregateOffer","priceCurrency":"USD","highPrice":1500.0,"lowPrice":1499.0,"offerCount":2,"offers":[{"@type":"Offer","url":"https://site.com/product-url/","price":1500.0,"priceCurrency":"USD","priceValidUntil":"2024-08-27"},{"@type":"Offer","url":"https://site.com/product-url/","price":1499.0,"priceCurrency":"USD","priceValidUntil":"2024-09-01"}]},"review":[{"@type":"Review","description":"Review Description 1","author":{"@type":"Person","name":"Review Author 1","url":"https://site.com/author1"},"reviewBody":"Review Description 1","reviewRating":{"@type":"Rating","bestRating":5.0,"ratingValue":4.5,"worstRating":1.0}},{"@type":"Review","description":"Review Description 2","author":{"@type":"Person","name":"Review Author 2","url":"https://site.com/author2"},"reviewBody":"Review Description 2","reviewRating":{"@type":"Rating","bestRating":5.0,"ratingValue":5.0,"worstRating":1.0}}],"sku":"12345"}]}</script>


<link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="/css/site.css" />

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/base16/one-light.min.css" />
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/xcode.min.css" />-->
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" href="/">SeoTags.Sample</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" href="/">[Demo Sample]</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="/Home/JsonLd1">[JSON-LD Sample 1]</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="/Home/JsonLd2">[JSON-LD Sample 2]</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">


<div>
<h1>SeoTags</h1>
<p>
<a href="https://github.com/mjebrahimi/SeoTags">SeoTags</a> create all SEO tags you need such as meta, link, twitter card (twitter:), open graph (og:), and JSON-LD schema (structred data)..
</p>
<h2>JSON-LD Sample 1 (Nested Values)</h2>
<p>
SeoTags now supports popular JSON-LD types such as <b>Article</b>, <b>Product</b>, <b>Book</b>, <b>Organization</b>, <b>WebSite</b>, <b>WebPage</b>, and etc...
<br>
This example shows JSOLD-LD in a nested values usage.
</p>
<p>
Visit <a href="https://mjebrahimi.github.io/SeoTags/jsonld1.html">this page</a> for usage and more information.
</p>
</div>

</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2021 - SeoTags.Sample - <a href="/Home/Privacy">Privacy</a>
</div>
</footer>

<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/languages/json.min.js"></script>
<script>
hljs.highlightAll();
</script>
</body>
</html>
Loading

0 comments on commit ed4f056

Please sign in to comment.