-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add snapshot tests to verify output HTMLs using Verify.DiffPlex
- Loading branch information
1 parent
66b9e27
commit ed4f056
Showing
11 changed files
with
444 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
101
test/SeoTags.Tests/_snapshots/VerifyExamples.TestJsonLd1.verified.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> | ||
© 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> |
Oops, something went wrong.