-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73461cb
commit 5e16326
Showing
13 changed files
with
2,608 additions
and
2,608 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,73 +1,73 @@ | ||
namespace Schema.NET.Test; | ||
|
||
using Xunit; | ||
|
||
public class ContextJsonConverterTest | ||
{ | ||
[Fact] | ||
public void ReadJson_StringContext_ContextHasName() | ||
{ | ||
var json = "{\"@context\":\"foo\",\"@type\":\"Thing\"}"; | ||
|
||
var thing = SchemaSerializer.DeserializeObject<Thing>(json); | ||
|
||
Assert.NotNull(thing?.Context); | ||
Assert.Equal("foo", thing?.Context.Name); | ||
Assert.Null(thing?.Context.Language); | ||
} | ||
|
||
[Fact] | ||
public void ReadJson_ObjectContextWithName_ContextHasName() | ||
{ | ||
var json = "{\"@context\":{\"name\":\"foo\"},\"@type\":\"Thing\"}"; | ||
|
||
var thing = SchemaSerializer.DeserializeObject<Thing>(json); | ||
|
||
Assert.NotNull(thing?.Context); | ||
Assert.Equal("foo", thing?.Context.Name); | ||
Assert.Null(thing?.Context.Language); | ||
} | ||
|
||
[Fact] | ||
public void ReadJson_ObjectContextWithNameAndLanguage_ContextHasNameAndLanguage() | ||
{ | ||
var json = "{\"@context\":{\"name\":\"foo\",\"@language\":\"en\"},\"@type\":\"Thing\"}"; | ||
|
||
var thing = SchemaSerializer.DeserializeObject<Thing>(json); | ||
|
||
Assert.NotNull(thing?.Context); | ||
Assert.Equal("foo", thing?.Context.Name); | ||
Assert.Equal("en", thing?.Context.Language); | ||
} | ||
|
||
[Fact] | ||
public void ReadJson_ArrayContextWithNameAndLanguage_ContextHasNameAndLanguage() | ||
{ | ||
var json = "{\"@context\":[\"foo\",{\"@language\":\"en\"}],\"@type\":\"Thing\"}"; | ||
|
||
var thing = SchemaSerializer.DeserializeObject<Thing>(json); | ||
|
||
Assert.NotNull(thing?.Context); | ||
Assert.Equal("foo", thing?.Context.Name); | ||
Assert.Equal("en", thing?.Context.Language); | ||
} | ||
|
||
[Fact] | ||
public void WriteJson_StringContext_ContextHasName() | ||
{ | ||
var json = new Thing().ToString(); | ||
|
||
Assert.Equal("{\"@context\":\"https://schema.org\",\"@type\":\"Thing\"}", json); | ||
} | ||
|
||
[Fact] | ||
public void WriteJson_ObjectContextWithLanguage_ContextHasName() | ||
{ | ||
var thing = new Thing(); | ||
thing.Context.Language = "en"; | ||
|
||
var json = thing.ToString(); | ||
|
||
Assert.Equal("{\"@context\":{\"name\":\"https://schema.org\",\"@language\":\"en\"},\"@type\":\"Thing\"}", json); | ||
} | ||
} | ||
namespace Schema.NET.Test; | ||
|
||
using Xunit; | ||
|
||
public class ContextJsonConverterTest | ||
{ | ||
[Fact] | ||
public void ReadJson_StringContext_ContextHasName() | ||
{ | ||
var json = "{\"@context\":\"foo\",\"@type\":\"Thing\"}"; | ||
|
||
var thing = SchemaSerializer.DeserializeObject<Thing>(json); | ||
|
||
Assert.NotNull(thing?.Context); | ||
Assert.Equal("foo", thing?.Context.Name); | ||
Assert.Null(thing?.Context.Language); | ||
} | ||
|
||
[Fact] | ||
public void ReadJson_ObjectContextWithName_ContextHasName() | ||
{ | ||
var json = "{\"@context\":{\"name\":\"foo\"},\"@type\":\"Thing\"}"; | ||
|
||
var thing = SchemaSerializer.DeserializeObject<Thing>(json); | ||
|
||
Assert.NotNull(thing?.Context); | ||
Assert.Equal("foo", thing?.Context.Name); | ||
Assert.Null(thing?.Context.Language); | ||
} | ||
|
||
[Fact] | ||
public void ReadJson_ObjectContextWithNameAndLanguage_ContextHasNameAndLanguage() | ||
{ | ||
var json = "{\"@context\":{\"name\":\"foo\",\"@language\":\"en\"},\"@type\":\"Thing\"}"; | ||
|
||
var thing = SchemaSerializer.DeserializeObject<Thing>(json); | ||
|
||
Assert.NotNull(thing?.Context); | ||
Assert.Equal("foo", thing?.Context.Name); | ||
Assert.Equal("en", thing?.Context.Language); | ||
} | ||
|
||
[Fact] | ||
public void ReadJson_ArrayContextWithNameAndLanguage_ContextHasNameAndLanguage() | ||
{ | ||
var json = "{\"@context\":[\"foo\",{\"@language\":\"en\"}],\"@type\":\"Thing\"}"; | ||
|
||
var thing = SchemaSerializer.DeserializeObject<Thing>(json); | ||
|
||
Assert.NotNull(thing?.Context); | ||
Assert.Equal("foo", thing?.Context.Name); | ||
Assert.Equal("en", thing?.Context.Language); | ||
} | ||
|
||
[Fact] | ||
public void WriteJson_StringContext_ContextHasName() | ||
{ | ||
var json = new Thing().ToString(); | ||
|
||
Assert.Equal("{\"@context\":\"https://schema.org\",\"@type\":\"Thing\"}", json); | ||
} | ||
|
||
[Fact] | ||
public void WriteJson_ObjectContextWithLanguage_ContextHasName() | ||
{ | ||
var thing = new Thing(); | ||
thing.Context.Language = "en"; | ||
|
||
var json = thing.ToString(); | ||
|
||
Assert.Equal("{\"@context\":{\"name\":\"https://schema.org\",\"@language\":\"en\"},\"@type\":\"Thing\"}", json); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,66 +1,66 @@ | ||
namespace Schema.NET.Test; | ||
|
||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
public class JsonLdContextTest | ||
{ | ||
public static IEnumerable<object[]> EqualContexts => new List<object[]> | ||
{ | ||
new object[] { new JsonLdContext(), new JsonLdContext() }, | ||
new object[] { new JsonLdContext() { Name = "a" }, new JsonLdContext() { Name = "a" } }, | ||
new object[] | ||
{ | ||
new JsonLdContext() { Name = "a", Language = "b" }, | ||
new JsonLdContext() { Name = "a", Language = "b" }, | ||
}, | ||
}; | ||
|
||
public static IEnumerable<object[]> NotEqualContexts => new List<object[]> | ||
{ | ||
new object[] { new JsonLdContext(), null! }, | ||
new object[] { new JsonLdContext(), new JsonLdContext() { Name = "a" } }, | ||
new object[] { new JsonLdContext() { Name = "a" }, new JsonLdContext() }, | ||
new object[] { new JsonLdContext() { Name = "a" }, new JsonLdContext() { Name = "b" } }, | ||
new object[] | ||
{ | ||
new JsonLdContext() { Name = "a", Language = "b" }, | ||
new JsonLdContext() { Name = "a", Language = "c" }, | ||
}, | ||
}; | ||
|
||
public static IEnumerable<object[]> ToStringContexts => new List<object[]> | ||
{ | ||
new object[] { new JsonLdContext(), "https://schema.org" }, | ||
new object[] { new JsonLdContext() { Name = "a" }, "a" }, | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(EqualContexts))] | ||
public void Equals_IsEqual_ReturnsTrue(JsonLdContext a, JsonLdContext b) => Assert.True(a.Equals(b)); | ||
|
||
[Theory] | ||
[MemberData(nameof(NotEqualContexts))] | ||
public void Equals_IsNotEqual_ReturnsFalse(JsonLdContext a, JsonLdContext b) => Assert.False(a.Equals(b)); | ||
|
||
[Theory] | ||
[MemberData(nameof(EqualContexts))] | ||
public void EqualsOperator_IsEqual_ReturnsTrue(JsonLdContext a, JsonLdContext b) => Assert.True(a == b); | ||
|
||
[Theory] | ||
[MemberData(nameof(NotEqualContexts))] | ||
public void EqualsOperator_IsNotEqual_ReturnsFalse(JsonLdContext a, JsonLdContext b) => Assert.False(a == b); | ||
|
||
[Theory] | ||
[MemberData(nameof(EqualContexts))] | ||
public void NotEqualsOperator_IsEqual_ReturnsFalse(JsonLdContext a, JsonLdContext b) => Assert.False(a != b); | ||
|
||
[Theory] | ||
[MemberData(nameof(NotEqualContexts))] | ||
public void NotEqualsOperator_IsNotEqual_ReturnsTrue(JsonLdContext a, JsonLdContext b) => Assert.True(a != b); | ||
|
||
[Theory] | ||
[MemberData(nameof(ToStringContexts))] | ||
public void ToString_MatchesExpected_ReturnsName(JsonLdContext context, string expectedValue) => | ||
Assert.Equal(expectedValue, context.ToString()); | ||
} | ||
namespace Schema.NET.Test; | ||
|
||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
public class JsonLdContextTest | ||
{ | ||
public static IEnumerable<object[]> EqualContexts => new List<object[]> | ||
{ | ||
new object[] { new JsonLdContext(), new JsonLdContext() }, | ||
new object[] { new JsonLdContext() { Name = "a" }, new JsonLdContext() { Name = "a" } }, | ||
new object[] | ||
{ | ||
new JsonLdContext() { Name = "a", Language = "b" }, | ||
new JsonLdContext() { Name = "a", Language = "b" }, | ||
}, | ||
}; | ||
|
||
public static IEnumerable<object[]> NotEqualContexts => new List<object[]> | ||
{ | ||
new object[] { new JsonLdContext(), null! }, | ||
new object[] { new JsonLdContext(), new JsonLdContext() { Name = "a" } }, | ||
new object[] { new JsonLdContext() { Name = "a" }, new JsonLdContext() }, | ||
new object[] { new JsonLdContext() { Name = "a" }, new JsonLdContext() { Name = "b" } }, | ||
new object[] | ||
{ | ||
new JsonLdContext() { Name = "a", Language = "b" }, | ||
new JsonLdContext() { Name = "a", Language = "c" }, | ||
}, | ||
}; | ||
|
||
public static IEnumerable<object[]> ToStringContexts => new List<object[]> | ||
{ | ||
new object[] { new JsonLdContext(), "https://schema.org" }, | ||
new object[] { new JsonLdContext() { Name = "a" }, "a" }, | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(EqualContexts))] | ||
public void Equals_IsEqual_ReturnsTrue(JsonLdContext a, JsonLdContext b) => Assert.True(a.Equals(b)); | ||
|
||
[Theory] | ||
[MemberData(nameof(NotEqualContexts))] | ||
public void Equals_IsNotEqual_ReturnsFalse(JsonLdContext a, JsonLdContext b) => Assert.False(a.Equals(b)); | ||
|
||
[Theory] | ||
[MemberData(nameof(EqualContexts))] | ||
public void EqualsOperator_IsEqual_ReturnsTrue(JsonLdContext a, JsonLdContext b) => Assert.True(a == b); | ||
|
||
[Theory] | ||
[MemberData(nameof(NotEqualContexts))] | ||
public void EqualsOperator_IsNotEqual_ReturnsFalse(JsonLdContext a, JsonLdContext b) => Assert.False(a == b); | ||
|
||
[Theory] | ||
[MemberData(nameof(EqualContexts))] | ||
public void NotEqualsOperator_IsEqual_ReturnsFalse(JsonLdContext a, JsonLdContext b) => Assert.False(a != b); | ||
|
||
[Theory] | ||
[MemberData(nameof(NotEqualContexts))] | ||
public void NotEqualsOperator_IsNotEqual_ReturnsTrue(JsonLdContext a, JsonLdContext b) => Assert.True(a != b); | ||
|
||
[Theory] | ||
[MemberData(nameof(ToStringContexts))] | ||
public void ToString_MatchesExpected_ReturnsName(JsonLdContext context, string expectedValue) => | ||
Assert.Equal(expectedValue, context.ToString()); | ||
} |
Oops, something went wrong.