public void Can_deserialize_with_changed_context() { // given var expanded = JObject.Parse(@" { '@id': 'http://t-code.pl/#tomasz', '@type': 'http://xmlns.com/foaf/0.1/Person', 'http://xmlns.com/foaf/0.1/name': 'Tomasz', 'http://xmlns.com/foaf/0.1/familyName': 'Pluskiewicz' }"); var @context = JObject.Parse(@" { 'foaf': 'http://xmlns.com/foaf/0.1/', 'name': 'foaf:name', 'lastName': 'foaf:familyName', 'Person': 'foaf:Person' }"); var contextProvider = new StaticContextProvider(); contextProvider.SetContext(typeof(Person), @context); // when IEntitySerializer serializer = new EntitySerializer(contextProvider); var person = serializer.Deserialize <Person>(expanded); // then Assert.Equal("Tomasz", person.Name); Assert.Equal("Pluskiewicz", person.LastName); Assert.Equal(new Uri("http://t-code.pl/#tomasz"), person.Id); }
public void Can_serialize_object_to_JSON_LD() { // given var person = new Person { Id = new Uri("http://t-code.pl/#tomasz"), Name = "Tomasz", LastName = "Pluskiewicz" }; var @context = JObject.Parse("{ '@context': 'http://example.org/context/Person' }"); var contextProvider = new StaticContextProvider(); contextProvider.SetContext(typeof(Person), @context); // when IEntitySerializer serializer = new EntitySerializer(contextProvider); dynamic json = serializer.Serialize(person); // then Assert.That((string)json.name, Is.EqualTo("Tomasz")); Assert.That((string)json.lastName, Is.EqualTo("Pluskiewicz")); Assert.That((string)json["@id"], Is.EqualTo("http://t-code.pl/#tomasz")); Assert.That((string)json["@type"][0], Is.EqualTo("http://xmlns.com/foaf/0.1/Person")); Assert.That(json["@context"], Is.Not.Null); }
public RepositoryScenarioContext() { Store = new TripleStore(); var contextProvider = new StaticContextProvider(); var jObject = new JObject( "hydra".IsPrefixOf(Hydra.Hydra.BaseUri), "member".IsProperty(Hydra.Hydra.member).Container().Set(), "totalItems".IsProperty(Hydra.Hydra.totalItems)); contextProvider.SetContext(typeof(Collection <Book>), jObject); var frameProvider = new WikibusModelFrames(); var serializer = new EntitySerializer(contextProvider, frameProvider); Repository = new Wikibus.Sources.DotNetRDF.SourcesRepository(new Lazy <ISparqlQueryProcessor>(() => new LeviathanQueryProcessor(Store)), serializer); }
public void Can_deserialize_framed_document() { // given var contextProvider = new StaticContextProvider(); contextProvider.SetContext(typeof(PersonWithAddress), Context); var frameProvider = new StaticFrameProvider(); frameProvider.SetFrame(typeof(PersonWithAddress), Frame); // when IEntitySerializer serializer = new EntitySerializer(contextProvider, frameProvider); var person = serializer.Deserialize <PersonWithAddress>(JsonLd); // then Assert.Equal("90-210", person.Address.PostalCode); Assert.Equal("Programmer's Avenue 1337", person.Address.Street); Assert.Equal(new Uri("http://sws.geonames.org/5328041/"), person.Address.City.Id); Assert.Equal("Beverly Hills", person.Address.City.Name); }
public void ShouldForceCompactSerializedModelWhenSetByAttribute_Inherited() { // given var person = new PersonWithInterest3 { Name = "Tomasz Pluskiewicz", Interest = new Interest { Name = "JSON-LD" } }; var contextProvider = new StaticContextProvider(); contextProvider.SetContext(typeof(PersonWithInterest3), Context); var serializer = new EntitySerializer(contextProvider); // when dynamic serialized = serializer.Serialize(person); // then Assert.Equal("Tomasz Pluskiewicz", serialized.name.ToString()); Assert.Equal("JSON-LD", serialized.interest.name.ToString()); }
public void Can_serialize_class_instance_to_literal() { // given var entity = new RequestLogItem { Ip = IPAddress.Parse("148.9.20.34") }; var contextProvider = new StaticContextProvider(); var context = JObject.Parse(@" { 'ip': { '@id': 'http://rdfs.org/sioc/ns#ip_address' } }"); contextProvider.SetContext(typeof(RequestLogItem), context); // when IEntitySerializer serializer = new EntitySerializer(contextProvider); dynamic jsonLd = serializer.Serialize(entity); // then Assert.Equal("148.9.20.34", (string)jsonLd.ip); }
public void ShouldForceCompactSerializedModelWhenRequested() { // given var person = new PersonWithInterest { Name = "Tomasz Pluskiewicz", Interest = new Interest { Name = "JSON-LD" } }; var contextProvider = new StaticContextProvider(); contextProvider.SetContext(typeof(PersonWithInterest), Context); var serializer = new EntitySerializer(contextProvider); // when dynamic serialized = serializer.Serialize(person, new SerializationOptions { SerializeCompacted = true }); // then Assert.That(serialized.name.ToString(), Is.EqualTo("Tomasz Pluskiewicz")); Assert.That(serialized.interest.name.ToString(), Is.EqualTo("JSON-LD")); }