Skip to content

Commit b515712

Browse files
committed
Fixing unit tests and adding test for new serialization encoding.
1 parent 8eb03be commit b515712

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

Tests/Schema.NET.Test/JobPostingTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class JobPostingTest
1010
private readonly JobPosting jobPosting = new JobPosting()
1111
{
1212
Title = "Fitter and Turner", // Required
13-
Description = "<p>Widget assembly role for pressing wheel assemblies.</p><p><strong>Educational Requirements:</strong> Completed level 2 ISTA Machinist Apprenticeship.</p><p><strong>Required Experience:</strong> At least 3 years in a machinist role.</p>", // Required
13+
Description = "Widget assembly role for pressing wheel assemblies. Educational Requirements: Completed level 2 ISTA Machinist Apprenticeship. Required Experience: At least 3 years in a machinist role.", // Required
1414
Identifier = new PropertyValue() // Recommended
1515
{
1616
Name = "MagsRUs Wheel Company",
@@ -51,7 +51,7 @@ public class JobPostingTest
5151
"\"@context\":\"http://schema.org\"," +
5252
"\"@type\":\"JobPosting\"," +
5353
"\"title\":\"Fitter and Turner\"," +
54-
"\"description\":\"<p>Widget assembly role for pressing wheel assemblies.</p><p><strong>Educational Requirements:</strong> Completed level 2 ISTA Machinist Apprenticeship.</p><p><strong>Required Experience:</strong> At least 3 years in a machinist role.</p>\"," +
54+
"\"description\":\"Widget assembly role for pressing wheel assemblies. Educational Requirements: Completed level 2 ISTA Machinist Apprenticeship. Required Experience: At least 3 years in a machinist role.\"," +
5555
"\"identifier\":{" +
5656
"\"@type\":\"PropertyValue\"," +
5757
"\"name\":\"MagsRUs Wheel Company\"," +

Tests/Schema.NET.Test/ProductTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class ProductTest
4444
"\"@context\":\"http://schema.org\"," +
4545
"\"@type\":\"Product\"," +
4646
"\"name\":\"Executive Anvil\"," +
47-
"\"description\":\"Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveller looking for something to drop from a height.\"," +
47+
"\"description\":\"Sleeker than ACME\\u0027s Classic Anvil, the Executive Anvil is perfect for the business traveller looking for something to drop from a height.\"," +
4848
"\"image\":\"http://www.example.com/anvil_executive.jpg\"," +
4949
"\"aggregateRating\":{" +
5050
"\"@type\":\"AggregateRating\"," +

Tests/Schema.NET.Test/RecipeTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public class RecipeTest
4545
"{" +
4646
"\"@context\":\"http://schema.org\"," +
4747
"\"@type\":\"Recipe\"," +
48-
"\"name\":\"Grandma's Holiday Apple Pie\"," +
49-
"\"description\":\"This is my grandmother's apple pie recipe. I like to add a dash of nutmeg.\"," +
48+
"\"name\":\"Grandma\\u0027s Holiday Apple Pie\"," +
49+
"\"description\":\"This is my grandmother\\u0027s apple pie recipe. I like to add a dash of nutmeg.\"," +
5050
"\"image\":\"https://example.com/image.jpg\"," +
5151
"\"aggregateRating\":{" +
5252
"\"@type\":\"AggregateRating\"," +

Tests/Schema.NET.Test/RestaurantTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class RestaurantTest
6666
"\"@context\":\"http://schema.org\"," +
6767
"\"@type\":\"Restaurant\"," +
6868
"\"@id\":\"http://davessteakhouse.example.com\"," +
69-
"\"name\":\"Dave's Steak House\"," +
69+
"\"name\":\"Dave\\u0027s Steak House\"," +
7070
"\"image\":\"http://davessteakhouse.example.com/logo.jpg\"," +
7171
"\"sameAs\":\"http://davessteakhouse.example.com\"," +
7272
"\"address\":{" +
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace Schema.NET.Test
2+
{
3+
using System;
4+
using Xunit;
5+
6+
// https://developers.google.com/search/docs/data-types/books
7+
public class SerializationTest
8+
{
9+
private readonly Book book = new Book()
10+
{
11+
Id = new Uri("http://example.com/book/1"),
12+
Name = "The Catcher in the Rye</script><script>alert('gotcha');</script>",
13+
Author = new Person()
14+
{
15+
Name = "J.D. Salinger</script><script>alert('gotcha');</script>"
16+
}
17+
};
18+
19+
private readonly string json =
20+
"{" +
21+
"\"@context\":\"http://schema.org\"," +
22+
"\"@type\":\"Book\"," +
23+
"\"@id\":\"http://example.com/book/1\"," +
24+
"\"name\":\"The Catcher in the Rye\\u003c/script\\u003e\\u003cscript\\u003ealert(\\u0027gotcha\\u0027);\\u003c/script\\u003e\"," +
25+
"\"author\":{" +
26+
"\"@type\":\"Person\"," +
27+
"\"name\":\"J.D. Salinger\\u003c/script\\u003e\\u003cscript\\u003ealert(\\u0027gotcha\\u0027);\\u003c/script\\u003e\"" +
28+
"}" +
29+
"}";
30+
31+
[Fact]
32+
public void ToString_UnsafeBookData_ReturnsExpectedJsonLd() =>
33+
Assert.Equal(this.json, this.book.ToString());
34+
}
35+
}

Tests/Schema.NET.Test/WebsiteTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void ToString_SiteLinksSearchBoxGoogleStructuredData_ReturnsExpectedJsonL
2525
"\"@type\":\"WebSite\"," +
2626
"\"potentialAction\":{" +
2727
"\"@type\":\"SearchAction\"," +
28-
"\"target\":\"http://example.com/search?&q={query}\"," +
28+
"\"target\":\"http://example.com/search?\\u0026q={query}\"," +
2929
"\"query-input\":\"required\"" +
3030
"}," +
3131
"\"url\":\"https://example.com\"" +

0 commit comments

Comments
 (0)