Skip to content

Commit 44be682

Browse files
kirk-marpleRehanSaeed
authored andcommitted
Added SCHEMA_ORG_LENGTH comment; added five new tests.
1 parent f7ebef0 commit 44be682

File tree

6 files changed

+419
-1
lines changed

6 files changed

+419
-1
lines changed

Source/Schema.NET/ValuesJsonConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public virtual void WriteObject(JsonWriter writer, object value, JsonSerializer
163163

164164
private static object ParseTokenArguments(JToken token, JsonToken tokenType, Type type, object value)
165165
{
166-
const int SCHEMA_ORG_LENGTH = 18;
166+
const int SCHEMA_ORG_LENGTH = 18; // equivalent to "http://schema.org/".Length
167167
object args = null;
168168
var unwrappedType = type.GetUnderlyingTypeFromNullable();
169169
if (unwrappedType.GetTypeInfo().IsEnum)
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
namespace Schema.NET.Test
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using Newtonsoft.Json;
6+
using Xunit;
7+
8+
public class MusicAlbumTest
9+
{
10+
private readonly MusicAlbum musicAlbum = new MusicAlbum()
11+
{
12+
Name = "Hail to the Thief", // Required
13+
Identifier = "1oW3v5Har9mvXnGk0x4fHm", // Recommended
14+
Image = new List<IImageObject> {
15+
new ImageObject() // Recommended
16+
{
17+
ContentUrl = new Uri("https://i.scdn.co/image/5ded47fd3d05325dd0faaf4619481e1f25a21ec7") // Required
18+
},
19+
new ImageObject() // Recommended
20+
{
21+
ContentUrl = new Uri("https://is4-ssl.mzstatic.com/image/thumb/Music69/v4/cc/1c/90/cc1c9039-c3ba-4256-e251-1687df46cb0a/cover.jpg/1400x1400bb.jpeg") // Required
22+
},
23+
},
24+
SameAs = new Uri("https://music.apple.com/us/album/hail-to-the-thief/1097863576"), // Recommended
25+
Url = new Uri("https://open.spotify.com/album/1oW3v5Har9mvXnGk0x4fHm"), // Recommended
26+
DatePublished = new DateTime(2003, 5, 26), // Recommended
27+
Offers = new Offer() // Recommended
28+
{
29+
Gtin12 = "634904078560"
30+
},
31+
NumTracks = 14, // Recommended
32+
AlbumRelease = new MusicRelease() // Recommended
33+
{
34+
RecordLabel = new Organization()
35+
{
36+
Name = "XL Recordings"// Required
37+
}
38+
},
39+
ByArtist = new MusicGroup() // Recommended
40+
{
41+
Name = "Radiohead", // Required
42+
Identifier = "4Z8W4fKeB5YxbusRsdQVPb" // Recommended
43+
},
44+
};
45+
46+
private readonly string json =
47+
"{" +
48+
"\"@context\": \"http://schema.org\"," +
49+
"\"@type\": \"MusicAlbum\"," +
50+
"\"name\": \"Hail to the Thief\"," +
51+
"\"identifier\": \"1oW3v5Har9mvXnGk0x4fHm\"," +
52+
"\"image\": [{" +
53+
"\"$type\": \"Schema.NET.ImageObject, Schema.NET\"," +
54+
"\"@context\": \"http://schema.org\"," +
55+
"\"@type\": \"ImageObject\"," +
56+
"\"contentUrl\": \"https://i.scdn.co/image/5ded47fd3d05325dd0faaf4619481e1f25a21ec7\"" +
57+
"}, {" +
58+
"\"$type\": \"Schema.NET.ImageObject, Schema.NET\"," +
59+
"\"@context\": \"http://schema.org\"," +
60+
"\"@type\": \"ImageObject\"," +
61+
"\"contentUrl\": \"https://is4-ssl.mzstatic.com/image/thumb/Music69/v4/cc/1c/90/cc1c9039-c3ba-4256-e251-1687df46cb0a/cover.jpg/1400x1400bb.jpeg\"" +
62+
"}" +
63+
"]," +
64+
"\"sameAs\": \"https://music.apple.com/us/album/hail-to-the-thief/1097863576\"," +
65+
"\"url\": \"https://open.spotify.com/album/1oW3v5Har9mvXnGk0x4fHm\"," +
66+
"\"datePublished\": \"2003-05-26\"," +
67+
"\"offers\": {" +
68+
"\"@context\": \"http://schema.org\"," +
69+
"\"@type\": \"Offer\"," +
70+
"\"gtin12\": \"634904078560\"" +
71+
"}," +
72+
"\"numTracks\": 14," +
73+
"\"albumRelease\": {" +
74+
"\"@context\": \"http://schema.org\"," +
75+
"\"@type\": \"MusicRelease\"," +
76+
"\"recordLabel\": {" +
77+
"\"@context\": \"http://schema.org\"," +
78+
"\"@type\": \"Organization\"," +
79+
"\"name\": \"XL Recordings\"" +
80+
"}" +
81+
"}," +
82+
"\"byArtist\": {" +
83+
"\"@context\": \"http://schema.org\"," +
84+
"\"@type\": \"MusicGroup\"," +
85+
"\"name\": \"Radiohead\"," +
86+
"\"identifier\": \"4Z8W4fKeB5YxbusRsdQVPb\"" +
87+
"}" +
88+
"}";
89+
90+
[Fact]
91+
public void Deserializing_MusicAlbumJsonLd_ReturnsMusicAlbum()
92+
{
93+
var serializerSettings = new JsonSerializerSettings()
94+
{
95+
DateParseHandling = DateParseHandling.DateTimeOffset
96+
};
97+
98+
Assert.Equal(this.musicAlbum.ToString(), JsonConvert.DeserializeObject<MusicAlbum>(this.json, serializerSettings).ToString());
99+
}
100+
}
101+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
namespace Schema.NET.Test
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using Newtonsoft.Json;
6+
using Xunit;
7+
8+
public class MusicEventTest
9+
{
10+
private readonly MusicEvent musicEvent = new MusicEvent()
11+
{
12+
Name = "Arash & Tohi", // Required
13+
Identifier = "vv1AaZAQ8Gkds-P77",
14+
Url = new Uri("https://www.ticketmaster.com/arash-tohi-hollywood-california-06-22-2019/event/09005690F1865104"), // Recommended
15+
Location = new MusicVenue() // Recommended
16+
{
17+
Name = "Dolby Theatre", // Required
18+
Identifier = "KovZpZAdtaEA" // Recommended
19+
},
20+
Offers = new Offer() // Recommended
21+
{
22+
Url = new Uri("https://www.ticketmaster.com/arash-tohi-hollywood-california-06-22-2019/event/09005690F1865104"), // Recommended
23+
AvailabilityStarts = DateTimeOffset.Parse("2019-04-24T21:00:00-07:00"), // Recommended
24+
AvailabilityEnds = DateTimeOffset.Parse("2019-06-23T01:00:00-07:00"), // Recommended
25+
PriceSpecification = new PriceSpecification() // Recommended
26+
{
27+
MinPrice = 80, // Recommended
28+
MaxPrice = 295, // Recommended
29+
PriceCurrency = "USD" // Recommended
30+
}
31+
},
32+
Performer = new List<IOrganization>() // Recommended
33+
{
34+
new MusicGroup() // Recommended
35+
{
36+
Name = "Arash", // Required
37+
Identifier = "K8vZ917ukD7" // Recommended
38+
},
39+
new MusicGroup() // Recommended
40+
{
41+
Name = "Tohi", // Required
42+
Identifier = "K8vZ917bA70" // Recommended
43+
}
44+
},
45+
StartDate = DateTimeOffset.Parse("2019-06-23T03:00:00-07:00") // Recommended
46+
};
47+
48+
private readonly string json =
49+
"{" +
50+
"\"@context\": \"http://schema.org\"," +
51+
"\"@type\": \"MusicEvent\"," +
52+
"\"name\": \"Arash & Tohi\"," +
53+
"\"identifier\": \"vv1AaZAQ8Gkds-P77\"," +
54+
"\"url\": \"https://www.ticketmaster.com/arash-tohi-hollywood-california-06-22-2019/event/09005690F1865104\"," +
55+
"\"location\": {" +
56+
"\"@context\": \"http://schema.org\"," +
57+
"\"@type\": \"MusicVenue\"," +
58+
"\"name\": \"Dolby Theatre\"," +
59+
"\"identifier\": \"KovZpZAdtaEA\"" +
60+
"}," +
61+
"\"offers\": {" +
62+
"\"@context\": \"http://schema.org\"," +
63+
"\"@type\": \"Offer\"," +
64+
"\"url\": \"https://www.ticketmaster.com/arash-tohi-hollywood-california-06-22-2019/event/09005690F1865104\"," +
65+
"\"availabilityEnds\": \"2019-06-23T01:00:00-07:00\"," +
66+
"\"availabilityStarts\": \"2019-04-24T21:00:00-07:00\"," +
67+
"\"priceSpecification\": {" +
68+
"\"@context\": \"http://schema.org\"," +
69+
"\"@type\": \"PriceSpecification\"," +
70+
"\"maxPrice\": 295," +
71+
"\"minPrice\": 80," +
72+
"\"priceCurrency\": \"USD\"" +
73+
"}" +
74+
"}," +
75+
"\"performer\": [" +
76+
"{" +
77+
"\"$type\": \"Schema.NET.MusicGroup, Schema.NET\"," +
78+
"\"@context\": \"http://schema.org\"," +
79+
"\"@type\": \"MusicGroup\"," +
80+
"\"name\": \"Arash\"," +
81+
"\"identifier\": \"K8vZ917ukD7\"" +
82+
"}," +
83+
"{" +
84+
"\"$type\": \"Schema.NET.MusicGroup, Schema.NET\"," +
85+
"\"@context\": \"http://schema.org\"," +
86+
"\"@type\": \"MusicGroup\"," +
87+
"\"name\": \"Tohi\"," +
88+
"\"identifier\": \"K8vZ917bA70\"" +
89+
"}" +
90+
"]," +
91+
"\"startDate\": \"2019-06-23T03:00:00-07:00\"" +
92+
"}";
93+
94+
[Fact]
95+
public void Deserializing_MusicEventJsonLd_ReturnsMusicEvent()
96+
{
97+
var serializerSettings = new JsonSerializerSettings()
98+
{
99+
DateParseHandling = DateParseHandling.DateTimeOffset
100+
};
101+
102+
Assert.Equal(this.musicEvent.ToString(), JsonConvert.DeserializeObject<MusicEvent>(this.json, serializerSettings).ToString());
103+
}
104+
}
105+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace Schema.NET.Test
2+
{
3+
using System;
4+
using Newtonsoft.Json;
5+
using Xunit;
6+
7+
public class MusicGroupTest
8+
{
9+
private readonly MusicGroup musicGroup = new MusicGroup()
10+
{
11+
Name = "Radiohead", // Required
12+
Identifier = "4Z8W4fKeB5YxbusRsdQVPb", // Recommended
13+
Image = new ImageObject() // Recommended
14+
{
15+
ContentUrl = new Uri("https://i.scdn.co/image/afcd616e1ef2d2786f47b3b4a8a6aeea24a72adc") // Required
16+
},
17+
SameAs = new Uri("https://music.apple.com/us/artist/radiohead/657515"), // Recommended
18+
Url = new Uri("https://open.spotify.com/artist/4Z8W4fKeB5YxbusRsdQVPb") // Recommended
19+
};
20+
21+
private readonly string json =
22+
"{" +
23+
"\"@context\": \"http://schema.org\"," +
24+
"\"@type\": \"MusicGroup\"," +
25+
"\"name\": \"Radiohead\"," +
26+
"\"identifier\": \"4Z8W4fKeB5YxbusRsdQVPb\"," +
27+
"\"image\": {" +
28+
"\"@context\": \"http://schema.org\"," +
29+
"\"@type\": \"ImageObject\"," +
30+
"\"contentUrl\": \"https://i.scdn.co/image/afcd616e1ef2d2786f47b3b4a8a6aeea24a72adc\"" +
31+
"}," +
32+
"\"sameAs\": \"https://music.apple.com/us/artist/radiohead/657515\"," +
33+
"\"url\": \"https://open.spotify.com/artist/4Z8W4fKeB5YxbusRsdQVPb\"" +
34+
"}";
35+
36+
[Fact]
37+
public void Deserializing_MusicGroupJsonLd_ReturnsMusicGroup()
38+
{
39+
var serializerSettings = new JsonSerializerSettings()
40+
{
41+
DateParseHandling = DateParseHandling.DateTimeOffset
42+
};
43+
44+
Assert.Equal(this.musicGroup.ToString(), JsonConvert.DeserializeObject<MusicGroup>(this.json, serializerSettings).ToString());
45+
}
46+
}
47+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
namespace Schema.NET.Test
2+
{
3+
using System;
4+
using Newtonsoft.Json;
5+
using Xunit;
6+
7+
public class MusicRecordingTest
8+
{
9+
private readonly MusicRecording musicRecording = new MusicRecording()
10+
{
11+
Name = "2 + 2 = 5", // Required
12+
Identifier = "37kUGdEJJ7NaMl5LFW4EA4", // Recommended
13+
Image = new ImageObject() // Recommended
14+
{
15+
ContentUrl = new Uri("https://is4-ssl.mzstatic.com/image/thumb/Music69/v4/cc/1c/90/cc1c9039-c3ba-4256-e251-1687df46cb0a/cover.jpg/1400x1400bb.jpeg") // Required
16+
},
17+
SameAs = new Uri("https://music.apple.com/us/album/2-2-5/1097863576?i=1097863810"), // Recommended
18+
Url = new Uri("https://open.spotify.com/track/37kUGdEJJ7NaMl5LFW4EA4"), // Recommended
19+
DatePublished = new DateTime(2003, 5, 26), // Recommended
20+
IsFamilyFriendly = true, // Recommended
21+
Position = "1.1", // Recommended
22+
ByArtist = new MusicGroup() // Recommended
23+
{
24+
Name = "Radiohead", // Required
25+
Identifier = "4Z8W4fKeB5YxbusRsdQVPb" // Recommended
26+
},
27+
Duration = new TimeSpan(0, 0, 3, 19, 360), // Recommended
28+
InAlbum = new MusicAlbum() // Recommended
29+
{
30+
Name = "Hail To the Thief", // Required
31+
Identifier = "1oW3v5Har9mvXnGk0x4fHm" // Recommended
32+
},
33+
IsrcCode = "GBAYE0300801" // Recommended
34+
};
35+
36+
private readonly string json =
37+
"{" +
38+
"\"@context\": \"http://schema.org\"," +
39+
"\"@type\": \"MusicRecording\"," +
40+
"\"name\": \"2 + 2 = 5\"," +
41+
"\"identifier\": \"37kUGdEJJ7NaMl5LFW4EA4\"," +
42+
"\"image\": {" +
43+
"\"@context\": \"http://schema.org\"," +
44+
"\"@type\": \"ImageObject\"," +
45+
"\"contentUrl\": \"https://is4-ssl.mzstatic.com/image/thumb/Music69/v4/cc/1c/90/cc1c9039-c3ba-4256-e251-1687df46cb0a/cover.jpg/1400x1400bb.jpeg\"" +
46+
"}," +
47+
"\"sameAs\": \"https://music.apple.com/us/album/2-2-5/1097863576?i=1097863810\"," +
48+
"\"url\": \"https://open.spotify.com/track/37kUGdEJJ7NaMl5LFW4EA4\"," +
49+
"\"datePublished\": \"2003-05-26\"," +
50+
"\"isFamilyFriendly\": true," +
51+
"\"position\": \"1.1\"," +
52+
"\"byArtist\": {" +
53+
"\"@context\": \"http://schema.org\"," +
54+
"\"@type\": \"MusicGroup\"," +
55+
"\"name\": \"Radiohead\"," +
56+
"\"identifier\": \"4Z8W4fKeB5YxbusRsdQVPb\"" +
57+
"}," +
58+
"\"duration\": \"PT3M19.36S\"," +
59+
"\"inAlbum\": {" +
60+
"\"@context\": \"http://schema.org\"," +
61+
"\"@type\": \"MusicAlbum\"," +
62+
"\"name\": \"Hail To the Thief\"," +
63+
"\"identifier\": \"1oW3v5Har9mvXnGk0x4fHm\"" +
64+
"}," +
65+
"\"isrcCode\": \"GBAYE0300801\"" +
66+
"}";
67+
68+
[Fact]
69+
public void Deserializing_MusicRecordingJsonLd_ReturnsMusicRecording()
70+
{
71+
var serializerSettings = new JsonSerializerSettings()
72+
{
73+
DateParseHandling = DateParseHandling.DateTimeOffset
74+
};
75+
76+
Assert.Equal(this.musicRecording.ToString(), JsonConvert.DeserializeObject<MusicRecording>(this.json, serializerSettings).ToString());
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)