From 73741ffe46971436064a1e71424dc2305901a979 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Wed, 6 Apr 2016 15:34:41 +0200 Subject: [PATCH 01/11] body deserializers --- paket.dependencies | 3 +- paket.lock | 14 ++-- .../ModelBinding/RdfModelBinderTests.cs | 78 +++++++++++++++++++ src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj | 59 +++++++------- src/Nancy.Rdf/FodyWeavers.xml | 1 + .../ModelBinding/JsonldBodyDeserializer.cs | 43 ++++++++++ .../NonJsonLdRdfBodyDeserializer.cs | 67 ++++++++++++++++ .../ModelBinding/Notation3BodyDeserializer.cs | 19 +++++ .../ModelBinding/NtriplesBodyDeserializer.cs | 33 ++++++++ .../ModelBinding/RdfBodyDeserializer.cs | 44 +++++++++++ .../ModelBinding/RdfXmlBodyDeserializer.cs | 19 +++++ .../ModelBinding/TurtleBodyDeserializer.cs | 19 +++++ src/Nancy.Rdf/Nancy.Rdf.csproj | 64 +++++++++------ src/Nancy.Rdf/paket.references | 3 +- 14 files changed, 406 insertions(+), 60 deletions(-) create mode 100644 src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs create mode 100644 src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs create mode 100644 src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs create mode 100644 src/Nancy.Rdf/ModelBinding/Notation3BodyDeserializer.cs create mode 100644 src/Nancy.Rdf/ModelBinding/NtriplesBodyDeserializer.cs create mode 100644 src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs create mode 100644 src/Nancy.Rdf/ModelBinding/RdfXmlBodyDeserializer.cs create mode 100644 src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs diff --git a/paket.dependencies b/paket.dependencies index d493ef8..5fc0a42 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -26,4 +26,5 @@ nuget JetbrainsAnnotations.Fody nuget Nancy.Owin nuget Microsoft.Owin.Host.SystemWeb nuget Microsoft.Owin.Hosting -nuget Rdf.Vocabularies \ No newline at end of file +nuget Rdf.Vocabularies +nuget infoof.fody \ No newline at end of file diff --git a/paket.lock b/paket.lock index 4685778..139023f 100644 --- a/paket.lock +++ b/paket.lock @@ -8,13 +8,15 @@ NUGET dotNetRDF (1.0.9.3683) HtmlAgilityPack (>= 1.4.9) Newtonsoft.Json (>= 6.0.8) - VDS.Common (1.6.0) + VDS.Common (1.6) FakeItEasy (1.25.3) FluentAssertions (4.2.2) Fody (1.29.4) - gitlink (2.2.0) + gitlink (2.2) GitVersionTask (3.4.1) HtmlAgilityPack (1.4.9) + InfoOf.Fody (1.0.4) + Fody (>= 1.29.2) JetBrainsAnnotations.Fody (1.0.4) Fody (>= 1.29.2) JsonLd.Entities (0.3.1) @@ -42,9 +44,9 @@ NUGET NUnit (2.6.4) OpenCover (4.6.519) Owin (1.0) - Rdf.Vocabularies (1.1.0) - SpecFlow (2.0.0) + Rdf.Vocabularies (1.1) + SpecFlow (2.0) StyleCop.MSBuild (4.7.50) StyleCopPlus.MSBuild (4.7.49.5) - StyleCop.MSBuild (>= 4.7.49.0) - VDS.Common (1.6.0) + StyleCop.MSBuild (>= 4.7.49) + VDS.Common (1.6) diff --git a/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs b/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs new file mode 100644 index 0000000..8e87795 --- /dev/null +++ b/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs @@ -0,0 +1,78 @@ +using System.IO; +using System.Text; +using FakeItEasy; +using FluentAssertions; +using JsonLD.Entities; +using Nancy.ModelBinding; +using Nancy.Rdf.ModelBinding; +using Newtonsoft.Json.Linq; +using NUnit.Framework; + +namespace Nancy.Rdf.Tests.ModelBinding +{ + public class RdfModelBinderTests + { + [Test] + public void CanDeserialize_should_return_true_supported_media_type() + { + // given + var binder = new RdfBodyDeserializerTestable(A.Fake()); + + // when + var canDeserialize = binder.CanDeserialize(RdfSerialization.NTriples.MediaType, new BindingContext()); + + // then + canDeserialize.Should().BeTrue(); + } + + [Test] + public void Deserialize_should_deserialize_JSONLD_proper_type_using_entity_serializer() + { + // given + var entitySerializer = A.Fake(); + var binder = new JsonldBodyDeserializer(entitySerializer); + var bindingContext = new BindingContext { DestinationType = typeof(TestModel) }; + var body = new MemoryStream(Encoding.UTF8.GetBytes("{}")); + + // when + binder.Deserialize(RdfSerialization.JsonLd.MediaType, body, bindingContext); + + // then + A.CallTo(() => entitySerializer.Deserialize(A._)).MustHaveHappened(); + } + + [Test] + public void Deserialize_should_deserialize_directly_from_ntriples() + { + // given + var entitySerializer = A.Fake(); + var binder = new NtriplesBodyDeserializer(entitySerializer); + var bindingContext = new BindingContext { DestinationType = typeof(TestModel) }; + const string bodyString = "some nquads"; + var body = new MemoryStream(Encoding.UTF8.GetBytes(bodyString)); + + // when + binder.Deserialize(RdfSerialization.NTriples.MediaType, body, bindingContext); + + // then + A.CallTo(() => entitySerializer.Deserialize(bodyString)).MustHaveHappened(); + } + + private class RdfBodyDeserializerTestable : RdfBodyDeserializer + { + public RdfBodyDeserializerTestable(IEntitySerializer entitySerializer) + : base(RdfSerialization.NTriples, entitySerializer) + { + } + + public override object Deserialize(string contentType, Stream body, BindingContext context) + { + throw new System.NotImplementedException(); + } + } + + private class TestModel + { + } + } +} diff --git a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj index 6d01e9a..aabb89e 100644 --- a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj +++ b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj @@ -60,6 +60,7 @@ + @@ -98,6 +99,35 @@ + + + + <__paket__StyleCopPlus_MSBuild_props>StyleCopPlus.MSBuild + + + + + + + + <__paket__StyleCop_MSBuild_Targets>StyleCop.MSBuild + + + + + + + <__paket__GitVersionTask_targets>\packages\GitVersionTask\Build\portable-net+sl+win+wpa+wp\GitVersionTask + + + + + + + <__paket__Fody_targets>portable-net+sl+win+wpa+wp\Fody + + + @@ -164,20 +194,6 @@ - - - - <__paket__Fody_targets>portable-net+sl+win+wpa+wp\Fody - - - - - - - <__paket__GitVersionTask_targets>\packages\GitVersionTask\Build\portable-net+sl+win+wpa+wp\GitVersionTask - - - @@ -306,20 +322,6 @@ - - - - <__paket__StyleCop_MSBuild_Targets>StyleCop.MSBuild - - - - - - - <__paket__StyleCopPlus_MSBuild_props>StyleCopPlus.MSBuild - - - @@ -331,7 +333,6 @@ - diff --git a/src/Nancy.Rdf/FodyWeavers.xml b/src/Nancy.Rdf/FodyWeavers.xml index f95bddc..0d760ae 100644 --- a/src/Nancy.Rdf/FodyWeavers.xml +++ b/src/Nancy.Rdf/FodyWeavers.xml @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs new file mode 100644 index 0000000..ab06552 --- /dev/null +++ b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using System.Reflection; +using JsonLD.Entities; +using Nancy.ModelBinding; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Nancy.Rdf.ModelBinding +{ + /// + /// Deserializes JSON-LD request body to model + /// + public class JsonldBodyDeserializer : RdfBodyDeserializer + { + private static readonly MethodInfo DeserializeJsonLdMethod = Info.OfMethod( + "JsonLd.Entities", + "JsonLD.Entities.IEntitySerializer", + "Deserialize", + "JToken"); + + /// + /// Initializes a new instance of the class. + /// + public JsonldBodyDeserializer(IEntitySerializer serializer) : base(RdfSerialization.JsonLd, serializer) + { + } + + /// + /// Deserialize the request body to a model + /// + public override object Deserialize(string contentType, Stream body, BindingContext context) + { + body.Position = 0; + using (var bodyReader = new StreamReader(body)) + { + var deserialize = DeserializeJsonLdMethod.MakeGenericMethod(context.DestinationType); + + return deserialize.Invoke(Serializer, new object[] { JToken.ReadFrom(new JsonTextReader(bodyReader)) }); + } + } + } +} diff --git a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs new file mode 100644 index 0000000..92b61f5 --- /dev/null +++ b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs @@ -0,0 +1,67 @@ +using System.IO; +using System.Reflection; +using JsonLD.Entities; +using Nancy.ModelBinding; +using VDS.RDF; +using VDS.RDF.Parsing; +using VDS.RDF.Writing; +using StringWriter = System.IO.StringWriter; + +namespace Nancy.Rdf.ModelBinding +{ + /// + /// Converts body, first converting it to NQuads + /// + public abstract class NonJsonLdRdfBodyDeserializer : RdfBodyDeserializer + { + private static readonly MethodInfo DeserializeNquadsMethod = Info.OfMethod( + "JsonLd.Entities", + "JsonLD.Entities.IEntitySerializer", + "Deserialize", + "String"); + + private static readonly IRdfWriter RdfWriter = new NTriplesWriter(NTriplesSyntax.Rdf11); + private readonly IRdfReader _reader; + + /// + /// Initializes a new instance of the class. + /// + protected NonJsonLdRdfBodyDeserializer( + RdfSerialization serialization, + IEntitySerializer serializer, + IRdfReader reader) : base(serialization, serializer) + { + _reader = reader; + } + + /// + /// Deserialize the request body to a model + /// + public override object Deserialize(string contentType, Stream body, BindingContext context) + { + var deserialize = DeserializeNquadsMethod.MakeGenericMethod(context.DestinationType); + + return deserialize.Invoke(Serializer, new object[] { GetNquads(body) }); + } + + /// + /// Converts body to N-Triples + /// + protected virtual string GetNquads(Stream body) + { + // todo: implement actual parsers for json-ld.net so that it's not necessary to parse and write to ntriples + IGraph g = new Graph(); + + using (var streamReader = new StreamReader(body)) + { + _reader.Load(g, streamReader); + } + + using (var stringWriter = new StringWriter()) + { + RdfWriter.Save(g, stringWriter); + return stringWriter.ToString(); + } + } + } +} diff --git a/src/Nancy.Rdf/ModelBinding/Notation3BodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/Notation3BodyDeserializer.cs new file mode 100644 index 0000000..b0c2db5 --- /dev/null +++ b/src/Nancy.Rdf/ModelBinding/Notation3BodyDeserializer.cs @@ -0,0 +1,19 @@ +using JsonLD.Entities; +using VDS.RDF.Parsing; + +namespace Nancy.Rdf.ModelBinding +{ + /// + /// Deserializes N3 request body to model + /// + public class Notation3BodyDeserializer : NonJsonLdRdfBodyDeserializer + { + /// + /// Initializes a new instance of the class. + /// + public Notation3BodyDeserializer(IEntitySerializer serializer) + : base(RdfSerialization.Notation3, serializer, new Notation3Parser()) + { + } + } +} diff --git a/src/Nancy.Rdf/ModelBinding/NtriplesBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/NtriplesBodyDeserializer.cs new file mode 100644 index 0000000..664ccc5 --- /dev/null +++ b/src/Nancy.Rdf/ModelBinding/NtriplesBodyDeserializer.cs @@ -0,0 +1,33 @@ +using System.IO; +using JsonLD.Entities; +using VDS.RDF.Parsing; + +namespace Nancy.Rdf.ModelBinding +{ + /// + /// Deserializes N-Triples request body to model + /// + public class NtriplesBodyDeserializer : NonJsonLdRdfBodyDeserializer + { + /// + /// Initializes a new instance of the class. + /// + /// The serializer. + public NtriplesBodyDeserializer(IEntitySerializer serializer) + : base(RdfSerialization.NTriples, serializer, new NTriplesParser()) + { + } + + /// + /// Reads the into NQuads. + /// + protected override string GetNquads(Stream body) + { + body.Position = 0; + using (var bodyReader = new StreamReader(body)) + { + return bodyReader.ReadToEnd(); + } + } + } +} diff --git a/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs new file mode 100644 index 0000000..7cfd046 --- /dev/null +++ b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using JsonLD.Entities; +using Nancy.ModelBinding; +using Nancy.Responses.Negotiation; + +namespace Nancy.Rdf.ModelBinding +{ + /// + /// Deserializes RDF bodies to POCO models + /// + public abstract class RdfBodyDeserializer : IBodyDeserializer + { + private readonly RdfSerialization _serialization; + + /// + /// The serializer + /// + protected readonly IEntitySerializer Serializer; + + /// + /// Initializes a new instance of the class. + /// + protected RdfBodyDeserializer(RdfSerialization serialization, IEntitySerializer serializer) + { + _serialization = serialization; + Serializer = serializer; + } + + /// + /// Determines whether this instance can deserialize the specified content type. + /// + /// true for any of + public bool CanDeserialize(string contentType, BindingContext context) + { + return new MediaRange(contentType).Matches(_serialization.MediaType); + } + + /// + /// Deserialize the request body to a model + /// + public abstract object Deserialize(string contentType, Stream body, BindingContext context); + } +} diff --git a/src/Nancy.Rdf/ModelBinding/RdfXmlBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/RdfXmlBodyDeserializer.cs new file mode 100644 index 0000000..91ac7e9 --- /dev/null +++ b/src/Nancy.Rdf/ModelBinding/RdfXmlBodyDeserializer.cs @@ -0,0 +1,19 @@ +using JsonLD.Entities; +using VDS.RDF.Parsing; + +namespace Nancy.Rdf.ModelBinding +{ + /// + /// Deserializes RDF/XML request body to model + /// + public class RdfXmlBodyDeserializer : NonJsonLdRdfBodyDeserializer + { + /// + /// Initializes a new instance of the class. + /// + public RdfXmlBodyDeserializer(IEntitySerializer serializer) + : base(RdfSerialization.RdfXml, serializer, new RdfXmlParser()) + { + } + } +} diff --git a/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs new file mode 100644 index 0000000..8bd3716 --- /dev/null +++ b/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs @@ -0,0 +1,19 @@ +using JsonLD.Entities; +using VDS.RDF.Parsing; + +namespace Nancy.Rdf.ModelBinding +{ + /// + /// Deserializes Turtle request body to model + /// + public class TurtleBodyDeserializer : NonJsonLdRdfBodyDeserializer + { + /// + /// Initializes a new instance of the class. + /// + public TurtleBodyDeserializer(IEntitySerializer serializer) + : base(RdfSerialization.Turtle, serializer, new TurtleParser()) + { + } + } +} \ No newline at end of file diff --git a/src/Nancy.Rdf/Nancy.Rdf.csproj b/src/Nancy.Rdf/Nancy.Rdf.csproj index dbe9845..3185c77 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.csproj +++ b/src/Nancy.Rdf/Nancy.Rdf.csproj @@ -54,6 +54,13 @@ + + + + + + + @@ -88,19 +95,16 @@ - - - ..\..\packages\dotNetRDF\lib\net40\dotNetRDF.dll - True - True - - + + <__paket__StyleCopPlus_MSBuild_props>StyleCopPlus.MSBuild + + - <__paket__Fody_targets>portable-net+sl+win+wpa+wp\Fody + <__paket__StyleCop_MSBuild_Targets>StyleCop.MSBuild @@ -111,6 +115,24 @@ + + + + <__paket__Fody_targets>portable-net+sl+win+wpa+wp\Fody + + + + + + + + ..\..\packages\dotNetRDF\lib\net40\dotNetRDF.dll + True + True + + + + @@ -131,6 +153,17 @@ + + + + + ..\..\packages\InfoOf.Fody\Lib\portable-net4+sl5+wp8+win8+wpa81+MonoAndroid16+MonoTouch40\InfoOf.dll + True + True + + + + @@ -206,20 +239,6 @@ - - - - <__paket__StyleCop_MSBuild_Targets>StyleCop.MSBuild - - - - - - - <__paket__StyleCopPlus_MSBuild_props>StyleCopPlus.MSBuild - - - @@ -231,7 +250,6 @@ - diff --git a/src/Nancy.Rdf/paket.references b/src/Nancy.Rdf/paket.references index 86f8133..65416f1 100644 --- a/src/Nancy.Rdf/paket.references +++ b/src/Nancy.Rdf/paket.references @@ -4,4 +4,5 @@ GitVersionTask JsonLd.Entities NullGuard.Fody StyleCopPlus.MSBuild -Rdf.Vocabularies \ No newline at end of file +Rdf.Vocabularies +infoof.fody \ No newline at end of file From f432ea1ff29233c0f788f5590ee7da8ec2ecd991 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Wed, 6 Apr 2016 16:06:10 +0200 Subject: [PATCH 02/11] stylecop fixes --- src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs | 2 +- .../ModelBinding/NonJsonLdRdfBodyDeserializer.cs | 2 +- src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs | 11 +++++------ src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs index ab06552..31636a7 100644 --- a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs @@ -36,7 +36,7 @@ public override object Deserialize(string contentType, Stream body, BindingConte { var deserialize = DeserializeJsonLdMethod.MakeGenericMethod(context.DestinationType); - return deserialize.Invoke(Serializer, new object[] { JToken.ReadFrom(new JsonTextReader(bodyReader)) }); + return deserialize.Invoke(_serializer, new object[] { JToken.ReadFrom(new JsonTextReader(bodyReader)) }); } } } diff --git a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs index 92b61f5..c078e10 100644 --- a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs @@ -41,7 +41,7 @@ public override object Deserialize(string contentType, Stream body, BindingConte { var deserialize = DeserializeNquadsMethod.MakeGenericMethod(context.DestinationType); - return deserialize.Invoke(Serializer, new object[] { GetNquads(body) }); + return deserialize.Invoke(_serializer, new object[] { GetNquads(body) }); } /// diff --git a/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs index 7cfd046..7522bfa 100644 --- a/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using JsonLD.Entities; using Nancy.ModelBinding; using Nancy.Responses.Negotiation; @@ -11,12 +10,12 @@ namespace Nancy.Rdf.ModelBinding /// public abstract class RdfBodyDeserializer : IBodyDeserializer { - private readonly RdfSerialization _serialization; - /// /// The serializer /// - protected readonly IEntitySerializer Serializer; + protected readonly IEntitySerializer _serializer; + + private readonly RdfSerialization _serialization; /// /// Initializes a new instance of the class. @@ -24,7 +23,7 @@ public abstract class RdfBodyDeserializer : IBodyDeserializer protected RdfBodyDeserializer(RdfSerialization serialization, IEntitySerializer serializer) { _serialization = serialization; - Serializer = serializer; + _serializer = serializer; } /// diff --git a/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs index 8bd3716..58f1344 100644 --- a/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs @@ -16,4 +16,4 @@ public TurtleBodyDeserializer(IEntitySerializer serializer) { } } -} \ No newline at end of file +} From 599a5ba590308b33873846e91967f572ed59d6c2 Mon Sep 17 00:00:00 2001 From: tpluscode Date: Fri, 16 Sep 2016 11:24:45 -0400 Subject: [PATCH 03/11] fix expansion by accept header profile (didn't work with quotes) --- .../SerializingToJsonLd.feature | 10 ++++++--- .../SerializingToJsonLd.feature.cs | 22 ++++++++++++------- src/Nancy.Rdf/Responses/JsonLdSerializer.cs | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Nancy.Rdf.Tests/SerializingToJsonLd.feature b/src/Nancy.Rdf.Tests/SerializingToJsonLd.feature index 516af1b..be5cccd 100644 --- a/src/Nancy.Rdf.Tests/SerializingToJsonLd.feature +++ b/src/Nancy.Rdf.Tests/SerializingToJsonLd.feature @@ -28,7 +28,7 @@ Scenario: Should pass through serialized model @Brochure @JsonLd -Scenario: Should allow expanded profile +Scenario Template: Should allow expanded profile Given A serialized model: """ { @@ -39,7 +39,7 @@ Scenario: Should allow expanded profile 'title': 'Jelcz M11 - mały, stary autobus' } """ - Given accepted media type 'application/ld+json; profile=http://www.w3.org/ns/json-ld#expanded' + Given accepted media type '' When model is serialized Then output stream should equal """ @@ -49,4 +49,8 @@ Scenario: Should allow expanded profile '@value': 'Jelcz M11 - mały, stary autobus' }] }] - """ \ No newline at end of file + """ +Examples: + | mediaType | + | application/ld+json; profile="http://www.w3.org/ns/json-ld#expanded" | + | application/ld+json; profile=http://www.w3.org/ns/json-ld#expanded | # without quotes \ No newline at end of file diff --git a/src/Nancy.Rdf.Tests/SerializingToJsonLd.feature.cs b/src/Nancy.Rdf.Tests/SerializingToJsonLd.feature.cs index dcc81fc..ae36b14 100644 --- a/src/Nancy.Rdf.Tests/SerializingToJsonLd.feature.cs +++ b/src/Nancy.Rdf.Tests/SerializingToJsonLd.feature.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by SpecFlow (http://www.specflow.org/). -// SpecFlow Version:2.0.0.0 +// SpecFlow Version:2.1.0.0 // SpecFlow Generator Version:2.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if @@ -15,7 +15,7 @@ namespace Nancy.Rdf.Tests using TechTalk.SpecFlow; - [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.0.0.0")] + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.1.0.0")] [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [NUnit.Framework.TestFixtureAttribute()] [NUnit.Framework.DescriptionAttribute("Serializing to JSON-LD")] @@ -94,11 +94,18 @@ public virtual void ShouldPassThroughSerializedModel() [NUnit.Framework.DescriptionAttribute("Should allow expanded profile")] [NUnit.Framework.CategoryAttribute("Brochure")] [NUnit.Framework.CategoryAttribute("JsonLd")] - public virtual void ShouldAllowExpandedProfile() + [NUnit.Framework.TestCaseAttribute("application/ld+json; profile=\"http://www.w3.org/ns/json-ld#expanded\"", new string[0])] + [NUnit.Framework.TestCaseAttribute("application/ld+json; profile=http://www.w3.org/ns/json-ld#expanded", new string[0])] + public virtual void ShouldAllowExpandedProfile(string mediaType, string[] exampleTags) { - TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Should allow expanded profile", new string[] { - "Brochure", - "JsonLd"}); + string[] @__tags = new string[] { + "Brochure", + "JsonLd"}; + if ((exampleTags != null)) + { + @__tags = System.Linq.Enumerable.ToArray(System.Linq.Enumerable.Concat(@__tags, exampleTags)); + } + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Should allow expanded profile", @__tags); #line 31 this.ScenarioSetup(scenarioInfo); #line hidden @@ -107,8 +114,7 @@ public virtual void ShouldAllowExpandedProfile() "p://wikibus.org/brochure/12345\',\r\n\t\'title\': \'Jelcz M11 - mały, stary autobus\'\r\n}" + "", ((TechTalk.SpecFlow.Table)(null)), "Given "); #line 42 - testRunner.Given("accepted media type \'application/ld+json; profile=http://www.w3.org/ns/json-ld#ex" + - "panded\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); + testRunner.Given(string.Format("accepted media type \'{0}\'", mediaType), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line 43 testRunner.When("model is serialized", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); #line hidden diff --git a/src/Nancy.Rdf/Responses/JsonLdSerializer.cs b/src/Nancy.Rdf/Responses/JsonLdSerializer.cs index eaf59a1..1d9b21d 100644 --- a/src/Nancy.Rdf/Responses/JsonLdSerializer.cs +++ b/src/Nancy.Rdf/Responses/JsonLdSerializer.cs @@ -76,7 +76,7 @@ public void Serialize(string contentType, TModel model, Stream outputStr var mediaRange = new MediaRange(contentType); - if (mediaRange.Parameters["profile"] == JsonLdProfiles.Expanded) + if (mediaRange.Parameters["profile"]?.Trim('"') == JsonLdProfiles.Expanded) { serialized = JsonLdProcessor.Expand(serialized); } From 4dc19cd38a041e6f45281dcccd89fc1440fa559f Mon Sep 17 00:00:00 2001 From: tpluscode Date: Fri, 16 Sep 2016 13:37:10 -0400 Subject: [PATCH 04/11] remove InfoOf Fody plugin --- paket.dependencies | 3 +- paket.lock | 31 ++++++++----------- src/Nancy.Rdf.Tests/App.config | 2 +- src/Nancy.Rdf/FodyWeavers.xml | 1 - .../ModelBinding/JsonldBodyDeserializer.cs | 6 +--- .../NonJsonLdRdfBodyDeserializer.cs | 6 +--- src/Nancy.Rdf/Nancy.Rdf.csproj | 10 +----- src/Nancy.Rdf/paket.references | 3 +- 8 files changed, 19 insertions(+), 43 deletions(-) diff --git a/paket.dependencies b/paket.dependencies index b2a7d20..e4f702e 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -26,5 +26,4 @@ nuget JetbrainsAnnotations.Fody nuget Nancy.Owin nuget Microsoft.Owin.Host.SystemWeb nuget Microsoft.Owin.Hosting -nuget Rdf.Vocabularies -nuget infoof.fody \ No newline at end of file +nuget Rdf.Vocabularies \ No newline at end of file diff --git a/paket.lock b/paket.lock index e9c2a7d..ed2d348 100644 --- a/paket.lock +++ b/paket.lock @@ -3,22 +3,21 @@ CONTENT: NONE FRAMEWORK: NET40, NET45 NUGET remote: https://www.nuget.org/api/v2 - specs: CsQuery (1.3.4) - dotNetRDF (1.0.9.3683) + dotNetRDF (1.0.12) HtmlAgilityPack (>= 1.4.9) - Newtonsoft.Json (>= 6.0.8) - VDS.Common (1.6) - FakeItEasy (2.0) - FluentAssertions (4.6.3) + Newtonsoft.Json (>= 8.0.3) + VDS.Common (1.6.4) + FakeItEasy (2.2) + FluentAssertions (4.14) Fody (1.29.4) - gitlink (2.2) - GitVersionTask (3.5.4) - HtmlAgilityPack (1.4.9) - InfoOf.Fody (1.0.4) - Fody (>= 1.29.2) - JetBrainsAnnotations.Fody (1.0.4) + gitlink (2.3) + GitVersionTask (3.6.3) + HtmlAgilityPack (1.4.9.5) + JetBrainsAnnotations.Fody (1.0.5) Fody (>= 1.29.2) + JsonLd.Entities (0.3.3) + json-ld.net (>= 1.0.5) json-ld.net (1.0.5) Newtonsoft.Json (>= 6.0.4) Microsoft.Owin (3.0.1) @@ -36,7 +35,7 @@ NUGET Nancy.Testing (1.4.1) CsQuery (>= 1.3.3) Nancy (>= 1.4.1) - Newtonsoft.Json (8.0.3) + Newtonsoft.Json (9.0.1) NullGuard.Fody (1.4.6) Fody (>= 1.29.2) NUnit (2.6.4) @@ -45,8 +44,4 @@ NUGET Rdf.Vocabularies (1.1.1) SpecFlow (2.1) StyleCop.Analyzers (1.0) - VDS.Common (1.6) - remote: https://ci.appveyor.com/nuget/jsonld-entities-aavhsnxi7xjp - specs: - JsonLD.Entities (0.3.3) - json-ld.net + VDS.Common (1.6.4) diff --git a/src/Nancy.Rdf.Tests/App.config b/src/Nancy.Rdf.Tests/App.config index 6431d52..d7f75d9 100644 --- a/src/Nancy.Rdf.Tests/App.config +++ b/src/Nancy.Rdf.Tests/App.config @@ -30,7 +30,7 @@ True - + diff --git a/src/Nancy.Rdf/FodyWeavers.xml b/src/Nancy.Rdf/FodyWeavers.xml index 0d760ae..f95bddc 100644 --- a/src/Nancy.Rdf/FodyWeavers.xml +++ b/src/Nancy.Rdf/FodyWeavers.xml @@ -1,5 +1,4 @@  - \ No newline at end of file diff --git a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs index ab06552..186c731 100644 --- a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs @@ -13,11 +13,7 @@ namespace Nancy.Rdf.ModelBinding /// public class JsonldBodyDeserializer : RdfBodyDeserializer { - private static readonly MethodInfo DeserializeJsonLdMethod = Info.OfMethod( - "JsonLd.Entities", - "JsonLD.Entities.IEntitySerializer", - "Deserialize", - "JToken"); + private static readonly MethodInfo DeserializeJsonLdMethod = typeof(IEntitySerializer).GetMethod("Deserialize", new[] { typeof(JToken) }); /// /// Initializes a new instance of the class. diff --git a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs index 92b61f5..7433a0c 100644 --- a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs @@ -14,11 +14,7 @@ namespace Nancy.Rdf.ModelBinding /// public abstract class NonJsonLdRdfBodyDeserializer : RdfBodyDeserializer { - private static readonly MethodInfo DeserializeNquadsMethod = Info.OfMethod( - "JsonLd.Entities", - "JsonLD.Entities.IEntitySerializer", - "Deserialize", - "String"); + private static readonly MethodInfo DeserializeNquadsMethod = typeof(IEntitySerializer).GetMethod("Deserialize", new[] { typeof(string) }); private static readonly IRdfWriter RdfWriter = new NTriplesWriter(NTriplesSyntax.Rdf11); private readonly IRdfReader _reader; diff --git a/src/Nancy.Rdf/Nancy.Rdf.csproj b/src/Nancy.Rdf/Nancy.Rdf.csproj index 60e74d2..8256485 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.csproj +++ b/src/Nancy.Rdf/Nancy.Rdf.csproj @@ -143,15 +143,7 @@ - - - - ..\..\packages\InfoOf.Fody\Lib\portable-net4+sl5+wp8+win8+wpa81+MonoAndroid16+MonoTouch40\InfoOf.dll - True - True - - - + diff --git a/src/Nancy.Rdf/paket.references b/src/Nancy.Rdf/paket.references index ada3c56..866cb25 100644 --- a/src/Nancy.Rdf/paket.references +++ b/src/Nancy.Rdf/paket.references @@ -4,5 +4,4 @@ GitVersionTask JsonLd.Entities NullGuard.Fody StyleCop.Analyzers -Rdf.Vocabularies -infoof.fody \ No newline at end of file +Rdf.Vocabularies \ No newline at end of file From f403d171f60d866e380df0d21b73b39160e6c71e Mon Sep 17 00:00:00 2001 From: tpluscode Date: Wed, 16 Nov 2016 20:54:29 +0100 Subject: [PATCH 05/11] update to nancy 2 --- paket.dependencies | 9 +- paket.lock | 8 +- .../Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj | 41 +++---- src/Example/Nancy.Rdf.Sample/Startup.cs | 10 +- src/Example/Nancy.Rdf.Sample/Web.config | 32 +++--- .../AcceptHeaderCoercion.feature.cs | 6 +- src/Nancy.Rdf.Tests/App.config | 18 ++-- src/Nancy.Rdf.Tests/ContextModuleTests.cs | 8 +- .../ModelBinding/RdfModelBinderTests.cs | 3 +- src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj | 102 ++++++------------ .../RdfResponseProcessorTests.cs | 19 ++-- .../SerializingToRdf.feature.cs | 12 +-- src/Nancy.Rdf/Contexts/JsonLdContextModule.cs | 2 +- src/Nancy.Rdf/Installer.cs | 2 +- .../ModelBinding/JsonldBodyDeserializer.cs | 6 +- .../NonJsonLdRdfBodyDeserializer.cs | 3 +- .../ModelBinding/RdfBodyDeserializer.cs | 6 +- src/Nancy.Rdf/Nancy.Rdf.csproj | 70 +++++------- src/Nancy.Rdf/Responses/JsonLdSerializer.cs | 12 +-- src/Nancy.Rdf/Responses/RdfSerializer.cs | 5 +- src/Nancy.Rdf/app.config | 15 ++- 21 files changed, 181 insertions(+), 208 deletions(-) diff --git a/paket.dependencies b/paket.dependencies index e4f702e..56ff3fd 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -1,11 +1,10 @@ source https://nuget.org/api/v2 -source https://ci.appveyor.com/nuget/jsonld-entities-aavhsnxi7xjp content: none redirects: on -framework: net40, net45 +framework: net452 -nuget Nancy +nuget Nancy prerelease nuget newtonsoft.json nuget dotNetRDF nuget json-ld.net @@ -20,10 +19,10 @@ nuget StyleCop.Analyzers nuget GitLink nuget JsonLd.Entities prerelease nuget Nullguard.Fody -nuget Nancy.Testing +nuget Nancy.Testing prerelease nuget FluentAssertions nuget JetbrainsAnnotations.Fody -nuget Nancy.Owin +nuget Nancy.Owin prerelease nuget Microsoft.Owin.Host.SystemWeb nuget Microsoft.Owin.Hosting nuget Rdf.Vocabularies \ No newline at end of file diff --git a/paket.lock b/paket.lock index ed2d348..e9c014e 100644 --- a/paket.lock +++ b/paket.lock @@ -1,6 +1,6 @@ REDIRECTS: ON CONTENT: NONE -FRAMEWORK: NET40, NET45 +FRAMEWORK: NET452 NUGET remote: https://www.nuget.org/api/v2 CsQuery (1.3.4) @@ -8,11 +8,11 @@ NUGET HtmlAgilityPack (>= 1.4.9) Newtonsoft.Json (>= 8.0.3) VDS.Common (1.6.4) - FakeItEasy (2.2) - FluentAssertions (4.14) + FakeItEasy (2.3.1) + FluentAssertions (4.17) Fody (1.29.4) gitlink (2.3) - GitVersionTask (3.6.3) + GitVersionTask (3.6.4) HtmlAgilityPack (1.4.9.5) JetBrainsAnnotations.Fody (1.0.5) Fody (>= 1.29.2) diff --git a/src/Example/Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj b/src/Example/Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj index b04a84c..5d73273 100644 --- a/src/Example/Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj +++ b/src/Example/Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj @@ -13,7 +13,7 @@ Properties Nancy.Rdf.Sample Nancy.Rdf.Sample - v4.5 + v4.5.2 true @@ -54,9 +54,9 @@ - + @@ -118,10 +118,10 @@ --> - + - - ..\..\..\packages\JsonLD.Entities\lib\net40\JsonLD.Entities.dll + + ..\..\..\packages\json-ld.net\lib\net40-client\json-ld.net.dll True True @@ -129,10 +129,10 @@ - + - - ..\..\..\packages\json-ld.net\lib\net40-client\json-ld.net.dll + + ..\..\..\packages\JsonLd.Entities\lib\net40\JsonLD.Entities.dll True True @@ -140,7 +140,7 @@ - + ..\..\..\packages\Microsoft.Owin\lib\net45\Microsoft.Owin.dll @@ -151,7 +151,7 @@ - + ..\..\..\packages\Microsoft.Owin.Host.SystemWeb\lib\net45\Microsoft.Owin.Host.SystemWeb.dll @@ -162,7 +162,7 @@ - + ..\..\..\packages\Microsoft.Owin.Hosting\lib\net45\Microsoft.Owin.Hosting.dll @@ -173,7 +173,7 @@ - + ..\..\..\packages\Nancy\lib\net40\Nancy.dll @@ -184,7 +184,7 @@ - + ..\..\..\packages\Nancy.Owin\lib\net40\Nancy.Owin.dll @@ -195,16 +195,7 @@ - - - - ..\..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll - True - True - - - - + ..\..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll @@ -215,7 +206,7 @@ - + ..\..\..\packages\Owin\lib\net40\Owin.dll @@ -226,7 +217,7 @@ - + ..\..\..\packages\Rdf.Vocabularies\lib\portable-net4+sl5+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\Rdf.Vocabularies.dll diff --git a/src/Example/Nancy.Rdf.Sample/Startup.cs b/src/Example/Nancy.Rdf.Sample/Startup.cs index a76fca5..8e9c18e 100644 --- a/src/Example/Nancy.Rdf.Sample/Startup.cs +++ b/src/Example/Nancy.Rdf.Sample/Startup.cs @@ -1,4 +1,5 @@ using System; +using JsonLD.Entities; using JsonLD.Entities.Context; using Microsoft.Owin; using Nancy.Rdf.Sample; @@ -30,6 +31,8 @@ public class Person public DateTime DateOfBirth { get; set; } + public string Friend { get; set; } + [JsonProperty] private string Type { @@ -55,16 +58,17 @@ public class PersonModule : NancyModule { public PersonModule() { - Get["person/{id}"] = _ => + Get("person/{id}", _ => { return new Person { Id = "http://api.guru/person/" + _.id, Name = "John", LastName = "Doe", - DateOfBirth = new DateTime(1967, 8, 2) + DateOfBirth = new DateTime(1967, 8, 2), + Friend = ("http://api.guru/person/" + _.id + 10) }; - }; + }); } } diff --git a/src/Example/Nancy.Rdf.Sample/Web.config b/src/Example/Nancy.Rdf.Sample/Web.config index 814ffee..20e400c 100644 --- a/src/Example/Nancy.Rdf.Sample/Web.config +++ b/src/Example/Nancy.Rdf.Sample/Web.config @@ -1,4 +1,4 @@ - + - - + + - - + + - - - True - - - - \ No newline at end of file + + + + True + + + + + True + + + + + + \ No newline at end of file diff --git a/src/Nancy.Rdf.Tests/AcceptHeaderCoercion.feature.cs b/src/Nancy.Rdf.Tests/AcceptHeaderCoercion.feature.cs index cbba052..16a344e 100644 --- a/src/Nancy.Rdf.Tests/AcceptHeaderCoercion.feature.cs +++ b/src/Nancy.Rdf.Tests/AcceptHeaderCoercion.feature.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by SpecFlow (http://www.specflow.org/). -// SpecFlow Version:2.0.0.0 +// SpecFlow Version:2.1.0.0 // SpecFlow Generator Version:2.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if @@ -15,7 +15,7 @@ namespace Nancy.Rdf.Tests using TechTalk.SpecFlow; - [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.0.0.0")] + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.1.0.0")] [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [NUnit.Framework.TestFixtureAttribute()] [NUnit.Framework.DescriptionAttribute("Accept Header Coercion")] @@ -31,7 +31,7 @@ public partial class AcceptHeaderCoercionFeature public virtual void FeatureSetup() { testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); - TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Accept Header Coercion", "\tTo be more dev-friendly\r\n\tI want default to return Rdf from routes by default", ProgrammingLanguage.CSharp, ((string[])(null))); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Accept Header Coercion", "\tTo be more dev-friendly\r\n\tI want default to return RDF from routes by default", ProgrammingLanguage.CSharp, ((string[])(null))); testRunner.OnFeatureStart(featureInfo); } diff --git a/src/Nancy.Rdf.Tests/App.config b/src/Nancy.Rdf.Tests/App.config index d7f75d9..6ecbd95 100644 --- a/src/Nancy.Rdf.Tests/App.config +++ b/src/Nancy.Rdf.Tests/App.config @@ -7,10 +7,6 @@ - - - - @@ -27,10 +23,20 @@ + + True + + + + + True + + + True - + - + diff --git a/src/Nancy.Rdf.Tests/ContextModuleTests.cs b/src/Nancy.Rdf.Tests/ContextModuleTests.cs index 04259db..8303ed1 100644 --- a/src/Nancy.Rdf.Tests/ContextModuleTests.cs +++ b/src/Nancy.Rdf.Tests/ContextModuleTests.cs @@ -30,14 +30,14 @@ public void Setup() } [Test] - public void Should_serve_type_jsonld_context_by_default() + public async void Should_serve_type_jsonld_context_by_default() { // given const string context = "{ 'sch': 'http://schema.org' }"; string expected = string.Format("{{'@context': {0} }}", context); // when - var response = _browser.Get("/context/staticString"); + var response = await _browser.Get("/context/staticString"); // then response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -45,10 +45,10 @@ public void Should_serve_type_jsonld_context_by_default() } [Test] - public void Should_not_serve_jsonld_context_in_other_format() + public async void Should_not_serve_jsonld_context_in_other_format() { // when - var response = _browser.Get("/context/staticString", with => with.Accept(new MediaRange(RdfSerialization.Turtle.MediaType))); + var response = await _browser.Get("/context/staticString", with => with.Accept(new MediaRange(RdfSerialization.Turtle.MediaType))); // then response.StatusCode.Should().Be(HttpStatusCode.NotAcceptable); diff --git a/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs b/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs index 8e87795..d68e2c4 100644 --- a/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs +++ b/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs @@ -5,6 +5,7 @@ using JsonLD.Entities; using Nancy.ModelBinding; using Nancy.Rdf.ModelBinding; +using Nancy.Responses.Negotiation; using Newtonsoft.Json.Linq; using NUnit.Framework; @@ -65,7 +66,7 @@ public RdfBodyDeserializerTestable(IEntitySerializer entitySerializer) { } - public override object Deserialize(string contentType, Stream body, BindingContext context) + public override object Deserialize(MediaRange contentType, Stream body, BindingContext context) { throw new System.NotImplementedException(); } diff --git a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj index 191e86c..3b93b08 100644 --- a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj +++ b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj @@ -1,5 +1,5 @@  - + Debug @@ -12,7 +12,7 @@ Nancy.Rdf.Tests Nancy.Rdf.Tests .NETFramework - v4.5 + v4.5.2 512 @@ -99,11 +99,25 @@ + + + + <__paket__GitVersionTask_targets>portable-net+sl+win+wpa+wp\GitVersionTask + + + + + + + <__paket__Fody_targets>portable-net+sl+win+wpa+wp\Fody + + + - + ..\..\packages\CsQuery\lib\net40\CsQuery.dll @@ -114,7 +128,7 @@ - + ..\..\packages\dotNetRDF\lib\net40\dotNetRDF.dll @@ -125,7 +139,7 @@ - + ..\..\packages\FakeItEasy\lib\net40\FakeItEasy.dll @@ -136,21 +150,7 @@ - - - - ..\..\packages\FluentAssertions\lib\net40\FluentAssertions.Core.dll - True - True - - - ..\..\packages\FluentAssertions\lib\net40\FluentAssertions.dll - True - True - - - - + ..\..\packages\FluentAssertions\lib\net45\FluentAssertions.Core.dll @@ -166,30 +166,7 @@ - - - <__paket__Fody_targets>portable-net+sl+win+wpa+wp\Fody - - - - - - - <__paket__GitVersionTask_targets>portable-net+sl+win+wpa+wp\GitVersionTask - - - - - - - - ..\..\packages\HtmlAgilityPack\lib\Net40\HtmlAgilityPack.dll - True - True - - - - + ..\..\packages\HtmlAgilityPack\lib\Net45\HtmlAgilityPack.dll @@ -200,7 +177,7 @@ - + ..\..\packages\JetBrainsAnnotations.Fody\Lib\JetBrains.Annotations.dll @@ -211,10 +188,10 @@ - + - - ..\..\packages\JsonLD.Entities\lib\net40\JsonLD.Entities.dll + + ..\..\packages\json-ld.net\lib\net40-client\json-ld.net.dll True True @@ -222,10 +199,10 @@ - + - - ..\..\packages\json-ld.net\lib\net40-client\json-ld.net.dll + + ..\..\packages\JsonLd.Entities\lib\net40\JsonLD.Entities.dll True True @@ -233,7 +210,7 @@ - + ..\..\packages\Nancy\lib\net40\Nancy.dll @@ -244,7 +221,7 @@ - + ..\..\packages\Nancy.Testing\lib\net40\Nancy.Testing.dll @@ -255,16 +232,7 @@ - - - - ..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll - True - True - - - - + ..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll @@ -275,7 +243,7 @@ - + ..\..\packages\NUnit\lib\nunit.framework.dll @@ -286,7 +254,7 @@ - + ..\..\packages\Rdf.Vocabularies\lib\portable-net4+sl5+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\Rdf.Vocabularies.dll @@ -297,7 +265,7 @@ - + ..\..\packages\SpecFlow\lib\net45\TechTalk.SpecFlow.dll @@ -321,7 +289,7 @@ - + ..\..\packages\VDS.Common\lib\net40-client\VDS.Common.dll diff --git a/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs b/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs index ceb6878..6c17824 100644 --- a/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs +++ b/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs @@ -48,7 +48,7 @@ public void Should_match_wildcard_when_set_up() { // given var serializer = A.Fake(); - A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); + A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); var nancyContext = new NancyContext(); nancyContext.Items.Add(FallbackSerializationKey, RdfSerialization.RdfXml); var processor = new RdfResponseProcessorTestable(new[] { serializer }); @@ -66,7 +66,7 @@ public void Should_not_match_wildcard_when_another_fallback_set_up() { // given var serializer = A.Fake(); - A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); + A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); var nancyContext = new NancyContext(); nancyContext.Items.Add(FallbackSerializationKey, RdfSerialization.Turtle); var processor = new RdfResponseProcessorTestable(new[] { serializer }); @@ -84,7 +84,7 @@ public void Should_not_match_wildcard_when_not_set_up() { // given var serializer = A.Fake(); - A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); + A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); var processor = new RdfResponseProcessorTestable(new[] { serializer }); // when @@ -100,7 +100,7 @@ public void Should_pass_SiteBase_from_context_to_serializtion() { // given var serializer = A.Fake(); - A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); + A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); var processor = new RdfResponseProcessorTestable(new[] { serializer }); // when @@ -109,7 +109,7 @@ public void Should_pass_SiteBase_from_context_to_serializtion() // then A.CallTo(() => serializer.Serialize( - RdfSerialization.RdfXml.MediaType, + A.That.Matches(mr => mr == RdfSerialization.RdfXml.MediaType), A.That.Matches(wm => wm.BaseUrl == new Uri(NancyContext.Request.Url.SiteBase)), A._)).MustHaveHappened(); } @@ -118,9 +118,9 @@ public void Should_pass_SiteBase_from_context_to_serializtion() public void Should_pass_actual_requested() { // given - const string contentType = "application/rdf+xml;profile=testprofile"; + var contentType = new MediaRange("application/rdf+xml;profile=testprofile"); var serializer = A.Fake(); - A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); + A.CallTo(() => serializer.CanSerialize(A.Ignored)).Returns(true); var processor = new RdfResponseProcessorTestable(new[] { serializer }); // when @@ -128,7 +128,10 @@ public void Should_pass_actual_requested() response.Contents(new MemoryStream()); // then - A.CallTo(() => serializer.Serialize(contentType, A._, A._)).MustHaveHappened(); + A.CallTo(() => serializer.Serialize( + A.That.Matches(mr => mr.Equals(contentType)), + A._, + A._)).MustHaveHappened(); } private class RdfResponseProcessorTestable : RdfResponseProcessor diff --git a/src/Nancy.Rdf.Tests/SerializingToRdf.feature.cs b/src/Nancy.Rdf.Tests/SerializingToRdf.feature.cs index 7be5708..7ec068c 100644 --- a/src/Nancy.Rdf.Tests/SerializingToRdf.feature.cs +++ b/src/Nancy.Rdf.Tests/SerializingToRdf.feature.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by SpecFlow (http://www.specflow.org/). -// SpecFlow Version:2.0.0.0 +// SpecFlow Version:2.1.0.0 // SpecFlow Generator Version:2.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if @@ -15,10 +15,10 @@ namespace Nancy.Rdf.Tests using TechTalk.SpecFlow; - [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.0.0.0")] + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.1.0.0")] [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [NUnit.Framework.TestFixtureAttribute()] - [NUnit.Framework.DescriptionAttribute("Serializing to Rdf")] + [NUnit.Framework.DescriptionAttribute("Serializing to RDF")] public partial class SerializingToRDFFeature { @@ -31,7 +31,7 @@ public partial class SerializingToRDFFeature public virtual void FeatureSetup() { testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); - TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Serializing to Rdf", "\tTest serializing models to Rdf", ProgrammingLanguage.CSharp, ((string[])(null))); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Serializing to RDF", "\tTest serializing models to RDF", ProgrammingLanguage.CSharp, ((string[])(null))); testRunner.OnFeatureStart(featureInfo); } @@ -64,12 +64,12 @@ public virtual void ScenarioCleanup() } [NUnit.Framework.TestAttribute()] - [NUnit.Framework.DescriptionAttribute("Serialize simple model to Rdf")] + [NUnit.Framework.DescriptionAttribute("Serialize simple model to RDF")] [NUnit.Framework.CategoryAttribute("Brochure")] [NUnit.Framework.CategoryAttribute("Rdf")] public virtual void SerializeSimpleModelToRDF() { - TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Serialize simple model to Rdf", new string[] { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Serialize simple model to RDF", new string[] { "Brochure", "Rdf"}); #line 6 diff --git a/src/Nancy.Rdf/Contexts/JsonLdContextModule.cs b/src/Nancy.Rdf/Contexts/JsonLdContextModule.cs index 225f895..d50693a 100644 --- a/src/Nancy.Rdf/Contexts/JsonLdContextModule.cs +++ b/src/Nancy.Rdf/Contexts/JsonLdContextModule.cs @@ -24,7 +24,7 @@ public JsonLdContextModule(IContextPathMapper pathProvider, IContextProvider pro foreach (var path in pathProvider.Contexts) { - Get[path.Path] = ServeContextOf(path.ModelType); + Get(path.Path, ServeContextOf(path.ModelType)); } } diff --git a/src/Nancy.Rdf/Installer.cs b/src/Nancy.Rdf/Installer.cs index 31869e0..fa07731 100644 --- a/src/Nancy.Rdf/Installer.cs +++ b/src/Nancy.Rdf/Installer.cs @@ -12,7 +12,7 @@ public class Installer : Registrations /// /// Initializes a new instance of the class. /// - public Installer() + public Installer(ITypeCatalog typeCatalog) : base(typeCatalog) { RegisterWithDefault(typeof(DictionaryNamespaceManager)); RegisterWithDefault(typeof(DefaultContextPathMapper)); diff --git a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs index 186c731..245f280 100644 --- a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs @@ -1,8 +1,8 @@ -using System; -using System.IO; +using System.IO; using System.Reflection; using JsonLD.Entities; using Nancy.ModelBinding; +using Nancy.Responses.Negotiation; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -25,7 +25,7 @@ public JsonldBodyDeserializer(IEntitySerializer serializer) : base(RdfSerializat /// /// Deserialize the request body to a model /// - public override object Deserialize(string contentType, Stream body, BindingContext context) + public override object Deserialize(MediaRange contentType, Stream body, BindingContext context) { body.Position = 0; using (var bodyReader = new StreamReader(body)) diff --git a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs index 7433a0c..086920c 100644 --- a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs @@ -2,6 +2,7 @@ using System.Reflection; using JsonLD.Entities; using Nancy.ModelBinding; +using Nancy.Responses.Negotiation; using VDS.RDF; using VDS.RDF.Parsing; using VDS.RDF.Writing; @@ -33,7 +34,7 @@ public abstract class NonJsonLdRdfBodyDeserializer : RdfBodyDeserializer /// /// Deserialize the request body to a model /// - public override object Deserialize(string contentType, Stream body, BindingContext context) + public override object Deserialize(MediaRange contentType, Stream body, BindingContext context) { var deserialize = DeserializeNquadsMethod.MakeGenericMethod(context.DestinationType); diff --git a/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs index d16336b..cad235c 100644 --- a/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs @@ -30,14 +30,14 @@ protected RdfBodyDeserializer(RdfSerialization serialization, IEntitySerializer /// Determines whether this instance can deserialize the specified content type. /// /// true for any of - public bool CanDeserialize(string contentType, BindingContext context) + public bool CanDeserialize(MediaRange contentType, BindingContext context) { - return new MediaRange(contentType).Matches(_serialization.MediaType); + return contentType.Matches(_serialization.MediaType); } /// /// Deserialize the request body to a model /// - public abstract object Deserialize(string contentType, Stream body, BindingContext context); + public abstract object Deserialize(MediaRange contentType, Stream body, BindingContext context); } } diff --git a/src/Nancy.Rdf/Nancy.Rdf.csproj b/src/Nancy.Rdf/Nancy.Rdf.csproj index 8256485..b32b066 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.csproj +++ b/src/Nancy.Rdf/Nancy.Rdf.csproj @@ -1,5 +1,5 @@  - + Debug @@ -12,8 +12,9 @@ Nancy.Rdf Nancy.Rdf .NETFramework - v4.0 + v4.5.2 512 + true @@ -25,6 +26,7 @@ 4 bin\Debug\Nancy.Rdf.xml Nancy.Rdf.ruleset + false pdbonly @@ -36,6 +38,7 @@ bin\Release\Nancy.Rdf.xml true Nancy.Rdf.ruleset + false @@ -98,41 +101,32 @@ - - - - ..\..\packages\dotNetRDF\lib\net40\dotNetRDF.dll - True - True - - - - - - + - <__paket__Fody_targets>portable-net+sl+win+wpa+wp\Fody + <__paket__GitVersionTask_targets>portable-net+sl+win+wpa+wp\GitVersionTask - + - <__paket__GitVersionTask_targets>portable-net+sl+win+wpa+wp\GitVersionTask + <__paket__Fody_targets>portable-net+sl+win+wpa+wp\Fody - + - - ..\..\packages\HtmlAgilityPack\lib\Net40\HtmlAgilityPack.dll + + ..\..\packages\dotNetRDF\lib\net40\dotNetRDF.dll True True - + + + ..\..\packages\HtmlAgilityPack\lib\Net45\HtmlAgilityPack.dll @@ -143,13 +137,10 @@ - - - - + - - ..\..\packages\JsonLD.Entities\lib\net40\JsonLD.Entities.dll + + ..\..\packages\json-ld.net\lib\net40-client\json-ld.net.dll True True @@ -157,10 +148,10 @@ - + - - ..\..\packages\json-ld.net\lib\net40-client\json-ld.net.dll + + ..\..\packages\JsonLd.Entities\lib\net40\JsonLD.Entities.dll True True @@ -168,7 +159,7 @@ - + ..\..\packages\Nancy\lib\net40\Nancy.dll @@ -179,16 +170,7 @@ - - - - ..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll - True - True - - - - + ..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll @@ -199,7 +181,7 @@ - + ..\..\packages\NullGuard.Fody\Lib\portable-net4+sl5+wpa81+wp8+win8+MonoAndroid16+MonoTouch40\NullGuard.dll @@ -210,7 +192,7 @@ - + ..\..\packages\Rdf.Vocabularies\lib\portable-net4+sl5+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\Rdf.Vocabularies.dll @@ -234,7 +216,7 @@ - + ..\..\packages\VDS.Common\lib\net40-client\VDS.Common.dll diff --git a/src/Nancy.Rdf/Responses/JsonLdSerializer.cs b/src/Nancy.Rdf/Responses/JsonLdSerializer.cs index 1d9b21d..e1348ad 100644 --- a/src/Nancy.Rdf/Responses/JsonLdSerializer.cs +++ b/src/Nancy.Rdf/Responses/JsonLdSerializer.cs @@ -44,23 +44,23 @@ public IEnumerable Extensions /// /// Whether the serializer can serialize the content type /// - /// Content type to serialize + /// Content type to serialize /// /// True if supported, false otherwise /// - public bool CanSerialize(string contentType) + public bool CanSerialize(MediaRange mediaRange) { - return JsonLdSerialization.MediaType.Equals(contentType, StringComparison.InvariantCultureIgnoreCase); + return JsonLdSerialization.MediaType.Equals(mediaRange, StringComparison.InvariantCultureIgnoreCase); } /// /// Serializes the specified content type. /// /// The type of the model. - /// Type of the content. + /// Type of the content. /// The model. /// The output stream. - public void Serialize(string contentType, TModel model, Stream outputStream) + public void Serialize(MediaRange mediaRange, TModel model, Stream outputStream) { WrappedModel? wrappedModel = model as WrappedModel?; var actualModel = wrappedModel == null ? model : wrappedModel.Value.Model; @@ -74,8 +74,6 @@ public void Serialize(string contentType, TModel model, Stream outputStr serialized.AddBaseToContext(wrappedModel.Value.BaseUrl); } - var mediaRange = new MediaRange(contentType); - if (mediaRange.Parameters["profile"]?.Trim('"') == JsonLdProfiles.Expanded) { serialized = JsonLdProcessor.Expand(serialized); diff --git a/src/Nancy.Rdf/Responses/RdfSerializer.cs b/src/Nancy.Rdf/Responses/RdfSerializer.cs index 5c1a30f..e9a75bc 100644 --- a/src/Nancy.Rdf/Responses/RdfSerializer.cs +++ b/src/Nancy.Rdf/Responses/RdfSerializer.cs @@ -6,6 +6,7 @@ using JsonLD.Core; using JsonLD.Entities; using Nancy.IO; +using Nancy.Responses.Negotiation; using VDS.RDF; namespace Nancy.Rdf.Responses @@ -39,13 +40,13 @@ public IEnumerable Extensions } /// - public virtual bool CanSerialize(string contentType) + public virtual bool CanSerialize(MediaRange contentType) { return _serialization.MediaType.Equals(contentType, StringComparison.InvariantCultureIgnoreCase); } /// - public void Serialize(string contentType, TModel model, Stream outputStream) + public void Serialize(MediaRange contentType, TModel model, Stream outputStream) { WrappedModel? wrappedModel = model as WrappedModel?; var actualModel = wrappedModel == null ? model : wrappedModel.Value.Model; diff --git a/src/Nancy.Rdf/app.config b/src/Nancy.Rdf/app.config index f072f57..94ee5d2 100644 --- a/src/Nancy.Rdf/app.config +++ b/src/Nancy.Rdf/app.config @@ -1,3 +1,14 @@ - + - + + + True + + + + + True + + + + From 97ef245e9e12e9d7bd40a9f545c111024fa9c551 Mon Sep 17 00:00:00 2001 From: tpluscode Date: Wed, 16 Nov 2016 21:01:08 +0100 Subject: [PATCH 06/11] fix paket deps --- paket.dependencies | 6 +-- paket.lock | 22 ++++++---- .../Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj | 26 +++++++++++- src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj | 41 +++++++++++++++++-- src/Nancy.Rdf/Nancy.Rdf.csproj | 24 ++++++++++- 5 files changed, 102 insertions(+), 17 deletions(-) diff --git a/paket.dependencies b/paket.dependencies index 56ff3fd..4744540 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -8,7 +8,7 @@ nuget Nancy prerelease nuget newtonsoft.json nuget dotNetRDF nuget json-ld.net -nuget Nancy +nuget Nancy >= 2 prerelease nuget GitVersionTask nuget HtmlAgilityPack nuget OpenCover @@ -19,10 +19,10 @@ nuget StyleCop.Analyzers nuget GitLink nuget JsonLd.Entities prerelease nuget Nullguard.Fody -nuget Nancy.Testing prerelease +nuget Nancy.Testing >= 2 prerelease nuget FluentAssertions nuget JetbrainsAnnotations.Fody -nuget Nancy.Owin prerelease +nuget Nancy.Owin >= 2 prerelease nuget Microsoft.Owin.Host.SystemWeb nuget Microsoft.Owin.Hosting nuget Rdf.Vocabularies \ No newline at end of file diff --git a/paket.lock b/paket.lock index e9c014e..3b86958 100644 --- a/paket.lock +++ b/paket.lock @@ -3,7 +3,7 @@ CONTENT: NONE FRAMEWORK: NET452 NUGET remote: https://www.nuget.org/api/v2 - CsQuery (1.3.4) + AngleSharp (0.9.9) dotNetRDF (1.0.12) HtmlAgilityPack (>= 1.4.9) Newtonsoft.Json (>= 8.0.3) @@ -20,6 +20,10 @@ NUGET json-ld.net (>= 1.0.5) json-ld.net (1.0.5) Newtonsoft.Json (>= 6.0.4) + Microsoft.DotNet.PlatformAbstractions (1.1) + Microsoft.Extensions.DependencyModel (1.1) + Microsoft.DotNet.PlatformAbstractions (>= 1.1) + Newtonsoft.Json (>= 9.0.1) Microsoft.Owin (3.0.1) Owin (>= 1.0) Microsoft.Owin.Host.SystemWeb (3.0.1) @@ -28,13 +32,17 @@ NUGET Microsoft.Owin.Hosting (3.0.1) Microsoft.Owin (>= 3.0.1) Owin (>= 1.0) - Nancy (1.4.3) - Nancy.Owin (1.4.1) - Nancy (>= 1.4.1) + Nancy (2.0.0-barneyrubble) + Microsoft.Extensions.DependencyModel (>= 1.0) + Nancy.Authentication.Forms (2.0.0-barneyrubble) + Nancy (>= 2.0.0-barneyrubble) + Nancy.Owin (2.0.0-barneyrubble) + Nancy (>= 2.0.0-barneyrubble) Owin (>= 1.0) - Nancy.Testing (1.4.1) - CsQuery (>= 1.3.3) - Nancy (>= 1.4.1) + Nancy.Testing (2.0.0-barneyrubble) + AngleSharp (>= 0.9.5) + Nancy (>= 2.0.0-barneyrubble) + Nancy.Authentication.Forms (>= 2.0.0-barneyrubble) Newtonsoft.Json (9.0.1) NullGuard.Fody (1.4.6) Fody (>= 1.29.2) diff --git a/src/Example/Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj b/src/Example/Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj index 5d73273..fa0f0be 100644 --- a/src/Example/Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj +++ b/src/Example/Nancy.Rdf.Sample/Nancy.Rdf.Sample.csproj @@ -139,6 +139,28 @@ + + + + + ..\..\..\packages\Microsoft.DotNet.PlatformAbstractions\lib\net451\Microsoft.DotNet.PlatformAbstractions.dll + True + True + + + + + + + + + ..\..\..\packages\Microsoft.Extensions.DependencyModel\lib\net451\Microsoft.Extensions.DependencyModel.dll + True + True + + + + @@ -176,7 +198,7 @@ - ..\..\..\packages\Nancy\lib\net40\Nancy.dll + ..\..\..\packages\Nancy\lib\net452\Nancy.dll True True @@ -187,7 +209,7 @@ - ..\..\..\packages\Nancy.Owin\lib\net40\Nancy.Owin.dll + ..\..\..\packages\Nancy.Owin\lib\net452\Nancy.Owin.dll True True diff --git a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj index 3b93b08..ca1c757 100644 --- a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj +++ b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj @@ -119,8 +119,8 @@ - - ..\..\packages\CsQuery\lib\net40\CsQuery.dll + + ..\..\packages\AngleSharp\lib\net45\AngleSharp.dll True True @@ -209,11 +209,44 @@ + + + + + ..\..\packages\Microsoft.DotNet.PlatformAbstractions\lib\net451\Microsoft.DotNet.PlatformAbstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.DependencyModel\lib\net451\Microsoft.Extensions.DependencyModel.dll + True + True + + + + - ..\..\packages\Nancy\lib\net40\Nancy.dll + ..\..\packages\Nancy\lib\net452\Nancy.dll + True + True + + + + + + + + + ..\..\packages\Nancy.Authentication.Forms\lib\net452\Nancy.Authentication.Forms.dll True True @@ -224,7 +257,7 @@ - ..\..\packages\Nancy.Testing\lib\net40\Nancy.Testing.dll + ..\..\packages\Nancy.Testing\lib\net452\Nancy.Testing.dll True True diff --git a/src/Nancy.Rdf/Nancy.Rdf.csproj b/src/Nancy.Rdf/Nancy.Rdf.csproj index b32b066..22422c0 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.csproj +++ b/src/Nancy.Rdf/Nancy.Rdf.csproj @@ -158,11 +158,33 @@ + + + + + ..\..\packages\Microsoft.DotNet.PlatformAbstractions\lib\net451\Microsoft.DotNet.PlatformAbstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.DependencyModel\lib\net451\Microsoft.Extensions.DependencyModel.dll + True + True + + + + - ..\..\packages\Nancy\lib\net40\Nancy.dll + ..\..\packages\Nancy\lib\net452\Nancy.dll True True From c2bff3c06a59f2539de447ee08eb11fb39d75b22 Mon Sep 17 00:00:00 2001 From: tpluscode Date: Wed, 16 Nov 2016 21:38:47 +0100 Subject: [PATCH 07/11] ruleset adjustments --- .../Bindings/JsonLdSerializationSteps.cs | 2 +- .../Bindings/ModelSerializingSteps.cs | 2 +- .../Bindings/RdfSerializationSteps.cs | 2 +- .../Bindings/SerializationContext.cs | 25 +- src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj | 6 +- .../RdfResponseProcessorTests.cs | 12 +- src/Nancy.Rdf/Contexts/ContextPathMap.cs | 5 +- .../Contexts/DefaultContextPathMapper.cs | 2 +- src/Nancy.Rdf/Contexts/IContextPathMapper.cs | 2 +- src/Nancy.Rdf/DictionaryNamespaceManager.cs | 2 +- src/Nancy.Rdf/Installer.cs | 3 +- src/Nancy.Rdf/JsonLdProfiles.cs | 2 +- .../ModelBinding/JsonldBodyDeserializer.cs | 3 +- .../NonJsonLdRdfBodyDeserializer.cs | 3 +- .../ModelBinding/TurtleBodyDeserializer.cs | 2 +- src/Nancy.Rdf/NamespaceMap.cs | 3 +- src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset | 236 ++++++++++++++++++ src/Nancy.Rdf/Nancy.Rdf.csproj | 6 +- src/Nancy.Rdf/Nancy.Rdf.ruleset | 10 +- src/Nancy.Rdf/RdfResponses.cs | 4 +- src/Nancy.Rdf/RdfSerialization.cs | 3 +- src/Nancy.Rdf/Responses/WrappedModel.cs | 2 +- src/Nancy.Rdf/UriExtensions.cs | 2 +- 23 files changed, 303 insertions(+), 36 deletions(-) create mode 100644 src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset diff --git a/src/Nancy.Rdf.Tests/Bindings/JsonLdSerializationSteps.cs b/src/Nancy.Rdf.Tests/Bindings/JsonLdSerializationSteps.cs index 7fc10e9..2c30e08 100644 --- a/src/Nancy.Rdf.Tests/Bindings/JsonLdSerializationSteps.cs +++ b/src/Nancy.Rdf.Tests/Bindings/JsonLdSerializationSteps.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using FakeItEasy; using Nancy.Rdf.Contexts; using Nancy.Rdf.Responses; diff --git a/src/Nancy.Rdf.Tests/Bindings/ModelSerializingSteps.cs b/src/Nancy.Rdf.Tests/Bindings/ModelSerializingSteps.cs index a7f484e..bb803ae 100644 --- a/src/Nancy.Rdf.Tests/Bindings/ModelSerializingSteps.cs +++ b/src/Nancy.Rdf.Tests/Bindings/ModelSerializingSteps.cs @@ -1,4 +1,4 @@ -using FakeItEasy; +using FakeItEasy; using Newtonsoft.Json.Linq; using NUnit.Framework; using TechTalk.SpecFlow; diff --git a/src/Nancy.Rdf.Tests/Bindings/RdfSerializationSteps.cs b/src/Nancy.Rdf.Tests/Bindings/RdfSerializationSteps.cs index 3d1f6de..cfc89fe 100644 --- a/src/Nancy.Rdf.Tests/Bindings/RdfSerializationSteps.cs +++ b/src/Nancy.Rdf.Tests/Bindings/RdfSerializationSteps.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using FakeItEasy; using JsonLD.Entities; using Nancy.Rdf.Responses; diff --git a/src/Nancy.Rdf.Tests/Bindings/SerializationContext.cs b/src/Nancy.Rdf.Tests/Bindings/SerializationContext.cs index b6259f6..d8e8412 100644 --- a/src/Nancy.Rdf.Tests/Bindings/SerializationContext.cs +++ b/src/Nancy.Rdf.Tests/Bindings/SerializationContext.cs @@ -1,13 +1,14 @@ -using System.IO; +using System; +using System.IO; using FakeItEasy; using JsonLD.Entities; namespace Nancy.Rdf.Tests.Bindings { - public class SerializationContext + public class SerializationContext : IDisposable { - private readonly Stream _outputStream = new MemoryStream(); private readonly IEntitySerializer _serializer = A.Fake(); + private Stream _outputStream = new MemoryStream(); public Stream OutputStream { @@ -22,5 +23,23 @@ public IEntitySerializer Serializer public dynamic Result { get; set; } public string AcceptHeader { get; set; } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + if (_outputStream != null) + { + _outputStream.Dispose(); + _outputStream = null; + } + } + } } } diff --git a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj index ca1c757..dacb7e9 100644 --- a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj +++ b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj @@ -25,6 +25,8 @@ prompt 4 false + ..\Nancy.RDF\Nancy.Rdf.Tests.ruleset + true pdbonly @@ -53,10 +55,10 @@ - - + + diff --git a/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs b/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs index 6c17824..6667214 100644 --- a/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs +++ b/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs @@ -17,14 +17,14 @@ public class RdfResponseProcessorTests static RdfResponseProcessorTests() { + var path = new Url("http://example.com/api/test") + { + BasePath = "api" + }; + NancyContext = new NancyContext { - Request = new Request( - "GET", - new Url("http://example.com/api/test") - { - BasePath = "api" - }) + Request = new Request("GET", path) }; } diff --git a/src/Nancy.Rdf/Contexts/ContextPathMap.cs b/src/Nancy.Rdf/Contexts/ContextPathMap.cs index dcfeb1f..ffd3eb1 100644 --- a/src/Nancy.Rdf/Contexts/ContextPathMap.cs +++ b/src/Nancy.Rdf/Contexts/ContextPathMap.cs @@ -13,7 +13,8 @@ public struct ContextPathMap /// /// The path. /// Type of the model. - public ContextPathMap(string path, Type modelType) : this() + public ContextPathMap(string path, Type modelType) + : this() { Path = path; ModelType = modelType; @@ -56,7 +57,7 @@ public bool Equals(ContextPathMap other) /// /// Checks equality /// - public override bool Equals(object obj) + public override bool Equals([AllowNull] object obj) { if (ReferenceEquals(null, obj)) { diff --git a/src/Nancy.Rdf/Contexts/DefaultContextPathMapper.cs b/src/Nancy.Rdf/Contexts/DefaultContextPathMapper.cs index 9acc5e3..3518779 100644 --- a/src/Nancy.Rdf/Contexts/DefaultContextPathMapper.cs +++ b/src/Nancy.Rdf/Contexts/DefaultContextPathMapper.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; namespace Nancy.Rdf.Contexts { diff --git a/src/Nancy.Rdf/Contexts/IContextPathMapper.cs b/src/Nancy.Rdf/Contexts/IContextPathMapper.cs index a761d34..53e374c 100644 --- a/src/Nancy.Rdf/Contexts/IContextPathMapper.cs +++ b/src/Nancy.Rdf/Contexts/IContextPathMapper.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; namespace Nancy.Rdf.Contexts { diff --git a/src/Nancy.Rdf/DictionaryNamespaceManager.cs b/src/Nancy.Rdf/DictionaryNamespaceManager.cs index 9ea847d..e30e862 100644 --- a/src/Nancy.Rdf/DictionaryNamespaceManager.cs +++ b/src/Nancy.Rdf/DictionaryNamespaceManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; diff --git a/src/Nancy.Rdf/Installer.cs b/src/Nancy.Rdf/Installer.cs index fa07731..e2a158c 100644 --- a/src/Nancy.Rdf/Installer.cs +++ b/src/Nancy.Rdf/Installer.cs @@ -12,7 +12,8 @@ public class Installer : Registrations /// /// Initializes a new instance of the class. /// - public Installer(ITypeCatalog typeCatalog) : base(typeCatalog) + public Installer(ITypeCatalog typeCatalog) + : base(typeCatalog) { RegisterWithDefault(typeof(DictionaryNamespaceManager)); RegisterWithDefault(typeof(DefaultContextPathMapper)); diff --git a/src/Nancy.Rdf/JsonLdProfiles.cs b/src/Nancy.Rdf/JsonLdProfiles.cs index ee93961..d125592 100644 --- a/src/Nancy.Rdf/JsonLdProfiles.cs +++ b/src/Nancy.Rdf/JsonLdProfiles.cs @@ -1,4 +1,4 @@ -namespace Nancy.Rdf +namespace Nancy.Rdf { /// /// Predefined JSON-LD ACCEPT header profiles diff --git a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs index 245f280..f214149 100644 --- a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs @@ -18,7 +18,8 @@ public class JsonldBodyDeserializer : RdfBodyDeserializer /// /// Initializes a new instance of the class. /// - public JsonldBodyDeserializer(IEntitySerializer serializer) : base(RdfSerialization.JsonLd, serializer) + public JsonldBodyDeserializer(IEntitySerializer serializer) + : base(RdfSerialization.JsonLd, serializer) { } diff --git a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs index 086920c..c168aa5 100644 --- a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs @@ -26,7 +26,8 @@ public abstract class NonJsonLdRdfBodyDeserializer : RdfBodyDeserializer protected NonJsonLdRdfBodyDeserializer( RdfSerialization serialization, IEntitySerializer serializer, - IRdfReader reader) : base(serialization, serializer) + IRdfReader reader) + : base(serialization, serializer) { _reader = reader; } diff --git a/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs index 58f1344..22dc16c 100644 --- a/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs @@ -1,4 +1,4 @@ -using JsonLD.Entities; +using JsonLD.Entities; using VDS.RDF.Parsing; namespace Nancy.Rdf.ModelBinding diff --git a/src/Nancy.Rdf/NamespaceMap.cs b/src/Nancy.Rdf/NamespaceMap.cs index d2eeaad..de3d452 100644 --- a/src/Nancy.Rdf/NamespaceMap.cs +++ b/src/Nancy.Rdf/NamespaceMap.cs @@ -10,7 +10,8 @@ public struct NamespaceMap /// /// Initializes a new instance of the struct. /// - public NamespaceMap(string prefix, Uri ns) : this() + public NamespaceMap(string prefix, Uri ns) + : this() { Namespace = ns; Prefix = prefix; diff --git a/src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset b/src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset new file mode 100644 index 0000000..9a55420 --- /dev/null +++ b/src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset @@ -0,0 +1,236 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Nancy.Rdf/Nancy.Rdf.csproj b/src/Nancy.Rdf/Nancy.Rdf.csproj index 22422c0..6fc7389 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.csproj +++ b/src/Nancy.Rdf/Nancy.Rdf.csproj @@ -27,6 +27,7 @@ bin\Debug\Nancy.Rdf.xml Nancy.Rdf.ruleset false + true pdbonly @@ -37,7 +38,8 @@ 4 bin\Release\Nancy.Rdf.xml true - Nancy.Rdf.ruleset + + false @@ -95,7 +97,7 @@ - + diff --git a/src/Nancy.Rdf/Nancy.Rdf.ruleset b/src/Nancy.Rdf/Nancy.Rdf.ruleset index 0baeacb..317f0a4 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.ruleset +++ b/src/Nancy.Rdf/Nancy.Rdf.ruleset @@ -121,7 +121,7 @@ - + @@ -169,6 +169,7 @@ + @@ -190,7 +191,7 @@ - + @@ -199,11 +200,11 @@ - + - + @@ -233,6 +234,5 @@ - \ No newline at end of file diff --git a/src/Nancy.Rdf/RdfResponses.cs b/src/Nancy.Rdf/RdfResponses.cs index 72e1efc..3b2bd7e 100644 --- a/src/Nancy.Rdf/RdfResponses.cs +++ b/src/Nancy.Rdf/RdfResponses.cs @@ -1,5 +1,4 @@ using Nancy.Bootstrapper; -using Nancy.Rdf.Responses; namespace Nancy.Rdf { @@ -8,6 +7,9 @@ namespace Nancy.Rdf /// public static class RdfResponses { + /// + /// The key used to store default RDF serialization in Nancy's context + /// internal const string FallbackSerializationKey = "__nrfs"; /// diff --git a/src/Nancy.Rdf/RdfSerialization.cs b/src/Nancy.Rdf/RdfSerialization.cs index a7e69ce..8c96b44 100644 --- a/src/Nancy.Rdf/RdfSerialization.cs +++ b/src/Nancy.Rdf/RdfSerialization.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using NullGuard; namespace Nancy.Rdf { @@ -123,7 +124,7 @@ public bool Equals(RdfSerialization other) } [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Operator or built-in override")] - public override bool Equals(object obj) + public override bool Equals([AllowNull] object obj) { if (ReferenceEquals(null, obj)) { diff --git a/src/Nancy.Rdf/Responses/WrappedModel.cs b/src/Nancy.Rdf/Responses/WrappedModel.cs index 5054ba4..0dd1f22 100644 --- a/src/Nancy.Rdf/Responses/WrappedModel.cs +++ b/src/Nancy.Rdf/Responses/WrappedModel.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Nancy.Rdf.Responses { diff --git a/src/Nancy.Rdf/UriExtensions.cs b/src/Nancy.Rdf/UriExtensions.cs index 0eec8b2..929450a 100644 --- a/src/Nancy.Rdf/UriExtensions.cs +++ b/src/Nancy.Rdf/UriExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Nancy.Rdf { From 54cf44fa33a734a45adf85127a63039bc8196501 Mon Sep 17 00:00:00 2001 From: tpluscode Date: Sun, 20 Nov 2016 17:06:28 +0100 Subject: [PATCH 08/11] add ruleset from gist --- Nancy.Rdf.sln.DotSettings | 2 + paket.dependencies | 5 +- paket.lock | 3 + .../Bindings/AcceptHeaderCoercionSteps.cs | 14 +- .../Bindings/ContentNegotiationSteps.cs | 18 +- src/Nancy.Rdf.Tests/Bindings/GraphSetup.cs | 6 +- .../Bindings/JsonLdSerializationSteps.cs | 18 +- .../Bindings/ModelSerializingSteps.cs | 10 +- src/Nancy.Rdf.Tests/Bindings/RdfGraphSteps.cs | 14 +- .../Bindings/RdfSerializationSteps.cs | 24 +- .../Bindings/SerializationContext.cs | 16 +- .../CompressingSerializerTests.cs | 38 +-- src/Nancy.Rdf.Tests/ContextModuleTests.cs | 18 +- src/Nancy.Rdf.Tests/JsonLdSerializerTests.cs | 24 +- src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj | 2 + .../Serializing/RdfSerializerTests.cs | 38 +-- src/Nancy.Rdf/Contexts/ContextPathMap.cs | 10 +- .../Contexts/DefaultContextPathMapper.cs | 10 +- src/Nancy.Rdf/Contexts/JsonLdContextModule.cs | 10 +- src/Nancy.Rdf/DictionaryNamespaceManager.cs | 12 +- src/Nancy.Rdf/Installer.cs | 6 +- .../ModelBinding/JsonldBodyDeserializer.cs | 2 +- .../NonJsonLdRdfBodyDeserializer.cs | 8 +- .../ModelBinding/RdfBodyDeserializer.cs | 8 +- src/Nancy.Rdf/NamespaceMap.cs | 4 +- src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset | 236 ----------------- src/Nancy.Rdf/Nancy.Rdf.csproj | 3 +- src/Nancy.Rdf/Nancy.Rdf.ruleset | 238 ------------------ src/Nancy.Rdf/RdfSerialization.cs | 20 +- .../Responses/CompressingSerializer.cs | 10 +- src/Nancy.Rdf/Responses/JsonLdSerializer.cs | 14 +- .../Responses/RdfResponseProcessor.cs | 20 +- src/Nancy.Rdf/Responses/RdfSerializer.cs | 32 +-- src/Nancy.Rdf/Responses/WrappedModel.cs | 4 +- src/Nancy.Rdf/paket.template | 1 + 35 files changed, 216 insertions(+), 682 deletions(-) delete mode 100644 src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset delete mode 100644 src/Nancy.Rdf/Nancy.Rdf.ruleset diff --git a/Nancy.Rdf.sln.DotSettings b/Nancy.Rdf.sln.DotSettings index 0953e63..e7f7408 100644 --- a/Nancy.Rdf.sln.DotSettings +++ b/Nancy.Rdf.sln.DotSettings @@ -1,3 +1,5 @@  + DO_NOT_SHOW + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <data><IncludeFilters /><ExcludeFilters><Filter ModuleMask="*.Tests" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /></ExcludeFilters></data> <data /> \ No newline at end of file diff --git a/paket.dependencies b/paket.dependencies index 4744540..44e1bf1 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -4,7 +4,6 @@ content: none redirects: on framework: net452 -nuget Nancy prerelease nuget newtonsoft.json nuget dotNetRDF nuget json-ld.net @@ -25,4 +24,6 @@ nuget JetbrainsAnnotations.Fody nuget Nancy.Owin >= 2 prerelease nuget Microsoft.Owin.Host.SystemWeb nuget Microsoft.Owin.Hosting -nuget Rdf.Vocabularies \ No newline at end of file +nuget Rdf.Vocabularies + +gist tpluscode/a285267d2543466fc35c3a168c846f9f \ No newline at end of file diff --git a/paket.lock b/paket.lock index 3b86958..6dffde4 100644 --- a/paket.lock +++ b/paket.lock @@ -53,3 +53,6 @@ NUGET SpecFlow (2.1) StyleCop.Analyzers (1.0) VDS.Common (1.6.4) +GIST + remote: tpluscode/a285267d2543466fc35c3a168c846f9f + FULLPROJECT (1625e92556df16d60d7b04f2c01c8b77212afd6f) \ No newline at end of file diff --git a/src/Nancy.Rdf.Tests/Bindings/AcceptHeaderCoercionSteps.cs b/src/Nancy.Rdf.Tests/Bindings/AcceptHeaderCoercionSteps.cs index 23024ed..d48e073 100644 --- a/src/Nancy.Rdf.Tests/Bindings/AcceptHeaderCoercionSteps.cs +++ b/src/Nancy.Rdf.Tests/Bindings/AcceptHeaderCoercionSteps.cs @@ -11,37 +11,37 @@ namespace Nancy.Rdf.Tests.Bindings [Binding] public class AcceptHeaderCoercionSteps { - private CoerceAcceptHeaders _convention; - private IEnumerable> _coercedAcceptHeaders; + private CoerceAcceptHeaders convention; + private IEnumerable> coercedAcceptHeaders; [Given(@"default convention")] public void GivenDefaultConvention() { - _convention = AcceptHeaderConventions.CoerceBlankAcceptHeader(); + this.convention = AcceptHeaderConventions.CoerceBlankAcceptHeader(); } [Given(@"convention set to return json-ld")] public void GivenConventionSetToReturn() { - _convention = AcceptHeaderConventions.CoerceBlankAcceptHeader(RdfSerialization.JsonLd); + this.convention = AcceptHeaderConventions.CoerceBlankAcceptHeader(RdfSerialization.JsonLd); } [When(@"invoke the convention with empty header collection")] public void WhenInvokeTheConvention() { - _coercedAcceptHeaders = _convention(new Tuple[0], new NancyContext()); + this.coercedAcceptHeaders = this.convention(new Tuple[0], new NancyContext()); } [When(@"invoke the convention with non-empty header collection")] public void WhenInvokeTheConventionWithExistingHeader() { - _coercedAcceptHeaders = _convention(new[] { Tuple.Create("text/html", 0.9m) }, new NancyContext()); + this.coercedAcceptHeaders = this.convention(new[] { Tuple.Create("text/html", 0.9m) }, new NancyContext()); } [Then(@"Accept header should be '(.*)', '(.*)'")] public void ThenAcceptHeaderShouldBe(string mediaType, decimal weight) { - Assert.That(_coercedAcceptHeaders.Single(), Is.EqualTo(Tuple.Create(mediaType, weight))); + Assert.That(this.coercedAcceptHeaders.Single(), Is.EqualTo(Tuple.Create(mediaType, weight))); } } } diff --git a/src/Nancy.Rdf.Tests/Bindings/ContentNegotiationSteps.cs b/src/Nancy.Rdf.Tests/Bindings/ContentNegotiationSteps.cs index fb74581..011500d 100644 --- a/src/Nancy.Rdf.Tests/Bindings/ContentNegotiationSteps.cs +++ b/src/Nancy.Rdf.Tests/Bindings/ContentNegotiationSteps.cs @@ -11,34 +11,34 @@ namespace Nancy.Rdf.Tests.Bindings [Binding] public class ContentNegotiationSteps { - private readonly ISerializer _serializer; - private MediaRange _mediaRange; - private Response _response; + private readonly ISerializer serializer; + private MediaRange mediaRange; + private Response response; public ContentNegotiationSteps() { - _serializer = A.Fake(); - A.CallTo(() => _serializer.CanSerialize(A._)).Returns(true); + this.serializer = A.Fake(); + A.CallTo(() => this.serializer.CanSerialize(A._)).Returns(true); } [Given(@"requested media range '(.*)'")] public void GivenRequestedMediaRange(string mediaRange) { - _mediaRange = new MediaRange(mediaRange); + this.mediaRange = new MediaRange(mediaRange); } [When(@"processing model"), Scope(Tag = "Rdf")] public void WhenProcessingRdfModel() { - var processor = new RdfResponseProcessorTestable(new[] { _serializer }); + var processor = new RdfResponseProcessorTestable(new[] { this.serializer }); - _response = processor.Process(_mediaRange, new object(), new NancyContext()); + this.response = processor.Process(this.mediaRange, new object(), new NancyContext()); } [Then(@"response should have status '(.*)'")] public void ThenResponseShouldHaveStatus(string expectedStatusCode) { - Assert.That(_response.StatusCode, Is.EqualTo(Enum.Parse(typeof(HttpStatusCode), expectedStatusCode))); + Assert.That(this.response.StatusCode, Is.EqualTo(Enum.Parse(typeof(HttpStatusCode), expectedStatusCode))); } private class RdfResponseProcessorTestable : RdfResponseProcessor diff --git a/src/Nancy.Rdf.Tests/Bindings/GraphSetup.cs b/src/Nancy.Rdf.Tests/Bindings/GraphSetup.cs index 693f439..6774de2 100644 --- a/src/Nancy.Rdf.Tests/Bindings/GraphSetup.cs +++ b/src/Nancy.Rdf.Tests/Bindings/GraphSetup.cs @@ -7,17 +7,17 @@ namespace Nancy.Rdf.Tests.Bindings [Binding] public class GraphSetup { - private readonly IObjectContainer _container; + private readonly IObjectContainer container; public GraphSetup(IObjectContainer container) { - _container = container; + this.container = container; } [BeforeScenario] public void InitializeGraph() { - _container.RegisterInstanceAs(new Graph()); + this.container.RegisterInstanceAs(new Graph()); } } } diff --git a/src/Nancy.Rdf.Tests/Bindings/JsonLdSerializationSteps.cs b/src/Nancy.Rdf.Tests/Bindings/JsonLdSerializationSteps.cs index 2c30e08..83e349e 100644 --- a/src/Nancy.Rdf.Tests/Bindings/JsonLdSerializationSteps.cs +++ b/src/Nancy.Rdf.Tests/Bindings/JsonLdSerializationSteps.cs @@ -11,27 +11,27 @@ namespace Nancy.Rdf.Tests.Bindings [Binding, Scope(Tag = "JsonLd")] public class JsonLdSerializationSteps { - private readonly ISerializer _serializer; - private readonly SerializationContext _context; + private readonly ISerializer serializer; + private readonly SerializationContext context; public JsonLdSerializationSteps(SerializationContext context) { - _context = context; - _serializer = new JsonLdSerializer(_context.Serializer, A.Dummy()); + this.context = context; + this.serializer = new JsonLdSerializer(this.context.Serializer, A.Dummy()); } [When(@"model is serialized"), Scope(Tag = "JsonLd")] public void WhenModelIsSerializedTo() { - var contentType = _context.AcceptHeader ?? RdfSerialization.JsonLd.MediaType; - _serializer.Serialize(contentType, new object(), _context.OutputStream); + var contentType = this.context.AcceptHeader ?? RdfSerialization.JsonLd.MediaType; + this.serializer.Serialize(contentType, new object(), this.context.OutputStream); - _context.OutputStream.Seek(0, SeekOrigin.Begin); - using (var streamReader = new StreamReader(_context.OutputStream)) + this.context.OutputStream.Seek(0, SeekOrigin.Begin); + using (var streamReader = new StreamReader(this.context.OutputStream)) { using (var jsonTextReader = new JsonTextReader(streamReader)) { - _context.Result = JToken.ReadFrom(jsonTextReader); + this.context.Result = JToken.ReadFrom(jsonTextReader); } } } diff --git a/src/Nancy.Rdf.Tests/Bindings/ModelSerializingSteps.cs b/src/Nancy.Rdf.Tests/Bindings/ModelSerializingSteps.cs index bb803ae..9389863 100644 --- a/src/Nancy.Rdf.Tests/Bindings/ModelSerializingSteps.cs +++ b/src/Nancy.Rdf.Tests/Bindings/ModelSerializingSteps.cs @@ -8,30 +8,30 @@ namespace Nancy.Rdf.Tests.Bindings [Binding] public class ModelSerializingSteps { - private readonly SerializationContext _context; + private readonly SerializationContext context; protected ModelSerializingSteps(SerializationContext context) { - _context = context; + this.context = context; } [Given(@"A serialized model:")] public void GivenASerializedModel(string json) { - A.CallTo(() => _context.Serializer.Serialize(A.Ignored, null)).Returns(JObject.Parse(json)); + A.CallTo(() => this.context.Serializer.Serialize(A.Ignored, null)).Returns(JObject.Parse(json)); } [Given(@"accepted media type '(.*)'")] public void GivenAcceptedMediaType(string mediaType) { - _context.AcceptHeader = mediaType; + this.context.AcceptHeader = mediaType; } [Then(@"output stream should equal")] public void ThenOutputStreamShouldEqual(string expectedBody) { var expected = JToken.Parse(expectedBody); - Assert.That(JToken.DeepEquals(_context.Result, expected)); + Assert.That(JToken.DeepEquals(this.context.Result, expected)); } } } diff --git a/src/Nancy.Rdf.Tests/Bindings/RdfGraphSteps.cs b/src/Nancy.Rdf.Tests/Bindings/RdfGraphSteps.cs index a836e23..63f6d28 100644 --- a/src/Nancy.Rdf.Tests/Bindings/RdfGraphSteps.cs +++ b/src/Nancy.Rdf.Tests/Bindings/RdfGraphSteps.cs @@ -11,23 +11,23 @@ namespace Nancy.Rdf.Tests.Bindings [Binding] public class RdfGraphSteps { - private readonly IGraph _graph; - private readonly ISparqlQueryProcessor _queryProcessor; - private readonly SparqlQueryParser _parser = new SparqlQueryParser(); + private readonly IGraph graph; + private readonly ISparqlQueryProcessor queryProcessor; + private readonly SparqlQueryParser parser = new SparqlQueryParser(); public RdfGraphSteps(IGraph graph) { - _graph = graph; - _queryProcessor = new LeviathanQueryProcessor(new InMemoryDataset(_graph)); + this.graph = graph; + this.queryProcessor = new LeviathanQueryProcessor(new InMemoryDataset(this.graph)); } [Then(@"graph should match:")] public void ThenGraphShouldMatch(string askQuery) { - var query = _parser.ParseFromString(askQuery); + var query = this.parser.ParseFromString(askQuery); Assert.That(query.QueryType, Is.EqualTo(SparqlQueryType.Ask), "Query must be ASK"); - _queryProcessor.ProcessQuery(query); + this.queryProcessor.ProcessQuery(query); } } } diff --git a/src/Nancy.Rdf.Tests/Bindings/RdfSerializationSteps.cs b/src/Nancy.Rdf.Tests/Bindings/RdfSerializationSteps.cs index cfc89fe..a15b2fd 100644 --- a/src/Nancy.Rdf.Tests/Bindings/RdfSerializationSteps.cs +++ b/src/Nancy.Rdf.Tests/Bindings/RdfSerializationSteps.cs @@ -10,57 +10,57 @@ namespace Nancy.Rdf.Tests.Bindings [Binding] public class RdfSerializationSteps { - private readonly SerializationContext _context; - private readonly RdfSerializerTestable _serializer; + private readonly SerializationContext context; + private readonly RdfSerializerTestable serializer; public RdfSerializationSteps(SerializationContext context, IGraph graph) { - _context = context; + this.context = context; - _serializer = new RdfSerializerTestable(_context.Serializer, new TestWriter(graph), A.Dummy()); + this.serializer = new RdfSerializerTestable(this.context.Serializer, new TestWriter(graph), A.Dummy()); } [When(@"model is serialized"), Scope(Tag = "Rdf")] public void WhenModelIsSerialized() { - _serializer.Serialize(RdfSerialization.Turtle.MediaType, new object(), _context.OutputStream); + this.serializer.Serialize(RdfSerialization.Turtle.MediaType, new object(), this.context.OutputStream); } private class RdfSerializerTestable : CompressingSerializer { - private readonly IRdfWriter _writer; + private readonly IRdfWriter writer; public RdfSerializerTestable(IEntitySerializer entitySerializer, IRdfWriter writer, INamespaceManager mapper) : base(RdfSerialization.Turtle, entitySerializer, mapper) { - _writer = writer; + this.writer = writer; } protected override IRdfWriter CreateWriter() { - return _writer; + return this.writer; } } private class TestWriter : IRdfWriter { - private readonly IGraph _graph; + private readonly IGraph graph; public TestWriter(IGraph graph) { - _graph = graph; + this.graph = graph; } public event RdfWriterWarning Warning; public void Save(IGraph g, string filename) { - _graph.Assert(g.Triples); + this.graph.Assert(g.Triples); } public void Save(IGraph g, TextWriter output) { - _graph.Assert(g.Triples); + this.graph.Assert(g.Triples); } } } diff --git a/src/Nancy.Rdf.Tests/Bindings/SerializationContext.cs b/src/Nancy.Rdf.Tests/Bindings/SerializationContext.cs index d8e8412..6307fae 100644 --- a/src/Nancy.Rdf.Tests/Bindings/SerializationContext.cs +++ b/src/Nancy.Rdf.Tests/Bindings/SerializationContext.cs @@ -7,17 +7,17 @@ namespace Nancy.Rdf.Tests.Bindings { public class SerializationContext : IDisposable { - private readonly IEntitySerializer _serializer = A.Fake(); - private Stream _outputStream = new MemoryStream(); + private readonly IEntitySerializer serializer = A.Fake(); + private Stream outputStream = new MemoryStream(); public Stream OutputStream { - get { return _outputStream; } + get { return this.outputStream; } } public IEntitySerializer Serializer { - get { return _serializer; } + get { return this.serializer; } } public dynamic Result { get; set; } @@ -26,7 +26,7 @@ public IEntitySerializer Serializer public void Dispose() { - Dispose(true); + this.Dispose(true); GC.SuppressFinalize(this); } @@ -34,10 +34,10 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - if (_outputStream != null) + if (this.outputStream != null) { - _outputStream.Dispose(); - _outputStream = null; + this.outputStream.Dispose(); + this.outputStream = null; } } } diff --git a/src/Nancy.Rdf.Tests/CompressingSerializerTests.cs b/src/Nancy.Rdf.Tests/CompressingSerializerTests.cs index 88aff56..f599e0c 100644 --- a/src/Nancy.Rdf.Tests/CompressingSerializerTests.cs +++ b/src/Nancy.Rdf.Tests/CompressingSerializerTests.cs @@ -12,17 +12,17 @@ namespace Nancy.Rdf.Tests [TestFixture] public class CompressingSerializerTests { - private CompressingSerializer _serializer; - private WriterSpy _writer; - private INamespaceManager _mapper; + private CompressingSerializer serializer; + private WriterSpy writer; + private INamespaceManager mapper; [SetUp] public void Setup() { var entitySerialier = A.Fake(); - _writer = new WriterSpy(); - _mapper = A.Fake(); - _serializer = new CompressingSerializerTestable(entitySerialier, _writer, _mapper); + this.writer = new WriterSpy(); + this.mapper = A.Fake(); + this.serializer = new CompressingSerializerTestable(entitySerialier, this.writer, this.mapper); } [Test] @@ -34,15 +34,15 @@ public void Serialized_graph_should_use_namespaces_if_given() new NamespaceMap("ex", new Uri("http://example.com")), new NamespaceMap("lol", new Uri("http://lol.com")) }; - A.CallTo(() => _mapper.GetEnumerator()).Returns(prefixes.GetEnumerator()); + A.CallTo(() => this.mapper.GetEnumerator()).Returns(prefixes.GetEnumerator()); // when - _serializer.Serialize(RdfSerialization.Turtle.MediaType, new object(), new MemoryStream()); + this.serializer.Serialize(RdfSerialization.Turtle.MediaType, new object(), new MemoryStream()); // then - Assert.That(_writer.Prefixes.Prefixes, Has.Count.EqualTo(2)); - Assert.That(_writer.Prefixes.HasNamespace("ex")); - Assert.That(_writer.Prefixes.HasNamespace("lol")); + Assert.That(this.writer.Prefixes.Prefixes, Has.Count.EqualTo(2)); + Assert.That(this.writer.Prefixes.HasNamespace("ex")); + Assert.That(this.writer.Prefixes.HasNamespace("lol")); } [Test] @@ -50,13 +50,13 @@ public void Serialized_graph_should_use_base_uri_if_given() { // given var baseUri = new Uri("http://example.org/base"); - A.CallTo(() => _mapper.BaseUri).Returns(baseUri); + A.CallTo(() => this.mapper.BaseUri).Returns(baseUri); // when - _serializer.Serialize(RdfSerialization.Turtle.MediaType, new object(), new MemoryStream()); + this.serializer.Serialize(RdfSerialization.Turtle.MediaType, new object(), new MemoryStream()); // then - Assert.That(_writer.BaseUri, Is.EqualTo(baseUri)); + Assert.That(this.writer.BaseUri, Is.EqualTo(baseUri)); } private class WriterSpy : IRdfWriter @@ -74,24 +74,24 @@ public void Save(IGraph g, string filename) public void Save(IGraph g, TextWriter output) { - Prefixes = g.NamespaceMap; - BaseUri = g.BaseUri; + this.Prefixes = g.NamespaceMap; + this.BaseUri = g.BaseUri; } } private class CompressingSerializerTestable : CompressingSerializer { - private readonly IRdfWriter _writer; + private readonly IRdfWriter writer; public CompressingSerializerTestable(IEntitySerializer entitySerializer, IRdfWriter writer, INamespaceManager mapper) : base(RdfSerialization.Turtle, entitySerializer, mapper) { - _writer = writer; + this.writer = writer; } protected override IRdfWriter CreateWriter() { - return _writer; + return this.writer; } } } diff --git a/src/Nancy.Rdf.Tests/ContextModuleTests.cs b/src/Nancy.Rdf.Tests/ContextModuleTests.cs index 8303ed1..c073ac5 100644 --- a/src/Nancy.Rdf.Tests/ContextModuleTests.cs +++ b/src/Nancy.Rdf.Tests/ContextModuleTests.cs @@ -12,19 +12,19 @@ namespace Nancy.Rdf.Tests { public class ContextModuleTests { - private Browser _browser; - private IContextPathMapper _mapper; + private Browser browser; + private IContextPathMapper mapper; [SetUp] public void Setup() { - _mapper = A.Fake(); - A.CallTo(() => _mapper.BasePath).Returns("context"); - A.CallTo(() => _mapper.Contexts).Returns(new[] { new ContextPathMap("staticString", typeof(Model)) }); + this.mapper = A.Fake(); + A.CallTo(() => this.mapper.BasePath).Returns("context"); + A.CallTo(() => this.mapper.Contexts).Returns(new[] { new ContextPathMap("staticString", typeof(Model)) }); - _browser = new Browser( + this.browser = new Browser( with => with.Module() - .Dependency(_mapper) + .Dependency(this.mapper) .Dependency(A.Dummy()) .Dependency(A.Dummy())); } @@ -37,7 +37,7 @@ public async void Should_serve_type_jsonld_context_by_default() string expected = string.Format("{{'@context': {0} }}", context); // when - var response = await _browser.Get("/context/staticString"); + var response = await this.browser.Get("/context/staticString"); // then response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -48,7 +48,7 @@ public async void Should_serve_type_jsonld_context_by_default() public async void Should_not_serve_jsonld_context_in_other_format() { // when - var response = await _browser.Get("/context/staticString", with => with.Accept(new MediaRange(RdfSerialization.Turtle.MediaType))); + var response = await this.browser.Get("/context/staticString", with => with.Accept(new MediaRange(RdfSerialization.Turtle.MediaType))); // then response.StatusCode.Should().Be(HttpStatusCode.NotAcceptable); diff --git a/src/Nancy.Rdf.Tests/JsonLdSerializerTests.cs b/src/Nancy.Rdf.Tests/JsonLdSerializerTests.cs index b89e899..cd8f283 100644 --- a/src/Nancy.Rdf.Tests/JsonLdSerializerTests.cs +++ b/src/Nancy.Rdf.Tests/JsonLdSerializerTests.cs @@ -18,16 +18,16 @@ public class JsonLdSerializerTests private static readonly JObject ModelWithContext = JObject.Parse("{ '@context': { 'ex': 'http://example.com' } }"); private static readonly JObject ModelWithoutContext = JObject.Parse("{ 'some': 'model' }"); - private JsonLdSerializer _serializer; - private IEntitySerializer _entitySerializer; - private IContextPathMapper _pathMapper; + private JsonLdSerializer serializer; + private IEntitySerializer entitySerializer; + private IContextPathMapper pathMapper; [SetUp] public void Setup() { - _entitySerializer = A.Fake(); - _pathMapper = A.Fake(); - _serializer = new JsonLdSerializer(_entitySerializer, _pathMapper); + this.entitySerializer = A.Fake(); + this.pathMapper = A.Fake(); + this.serializer = new JsonLdSerializer(this.entitySerializer, this.pathMapper); } [Test] @@ -36,13 +36,13 @@ public void Should_replace_context_when_available() // given const string siteBase = "http://example.com/"; const string expectedUri = "http://example.com/contexts/model"; - A.CallTo(() => _pathMapper.Contexts).Returns(new[] { new ContextPathMap("model", typeof(object)) }); - A.CallTo(() => _pathMapper.BasePath).Returns("contexts"); - A.CallTo(() => _entitySerializer.Serialize(A.Ignored, null)).Returns(ModelWithContext); + A.CallTo(() => this.pathMapper.Contexts).Returns(new[] { new ContextPathMap("model", typeof(object)) }); + A.CallTo(() => this.pathMapper.BasePath).Returns("contexts"); + A.CallTo(() => this.entitySerializer.Serialize(A.Ignored, null)).Returns(ModelWithContext); var outStream = new MemoryStream(); // when - _serializer.Serialize("content/type", new WrappedModel(new object(), siteBase), outStream); + this.serializer.Serialize("content/type", new WrappedModel(new object(), siteBase), outStream); // then outStream.Seek(0, SeekOrigin.Begin); @@ -60,10 +60,10 @@ public void Should_add_site_base_as_base_to_context(string siteBase, JObject mod { // given var outStream = new MemoryStream(); - A.CallTo(() => _entitySerializer.Serialize(A.Ignored, null)).Returns(model); + A.CallTo(() => this.entitySerializer.Serialize(A.Ignored, null)).Returns(model); // when - _serializer.Serialize("content/type", new WrappedModel(new object(), siteBase), outStream); + this.serializer.Serialize("content/type", new WrappedModel(new object(), siteBase), outStream); // then outStream.Seek(0, SeekOrigin.Begin); diff --git a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj index dacb7e9..f369b9b 100644 --- a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj +++ b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj @@ -36,6 +36,8 @@ prompt 4 false + ..\..\paket-files\tpluscode\a285267d2543466fc35c3a168c846f9f\UnitTests.ruleset + true diff --git a/src/Nancy.Rdf.Tests/Serializing/RdfSerializerTests.cs b/src/Nancy.Rdf.Tests/Serializing/RdfSerializerTests.cs index ff995d5..b02d749 100644 --- a/src/Nancy.Rdf.Tests/Serializing/RdfSerializerTests.cs +++ b/src/Nancy.Rdf.Tests/Serializing/RdfSerializerTests.cs @@ -15,22 +15,22 @@ namespace Nancy.Rdf.Tests.Serializing [TestFixture] public class RdfSerializerTests { - private RdfSerializerTestable _serializer; - private IEntitySerializer _entitySerializer; - private INodeFactory _nodeFactory = new NodeFactory(); + private RdfSerializerTestable serializer; + private IEntitySerializer entitySerializer; + private INodeFactory nodeFactory = new NodeFactory(); [SetUp] public void Setup() { - _entitySerializer = A.Fake(); - _serializer = new RdfSerializerTestable(_entitySerializer); + this.entitySerializer = A.Fake(); + this.serializer = new RdfSerializerTestable(this.entitySerializer); } [Test] public void Should_serialize_bool_with_proper_format() { // given - A.CallTo(() => _entitySerializer.Serialize(A._, A._)) + A.CallTo(() => this.entitySerializer.Serialize(A._, A._)) .Returns(JObject.Parse(@"{ '@context': { @@ -43,10 +43,10 @@ public void Should_serialize_bool_with_proper_format() }")); // when - _serializer.Serialize("text/turtle", new object(), new MemoryStream()); + this.serializer.Serialize("text/turtle", new object(), new MemoryStream()); // then - Assert.That(_serializer.Triples.Any(triple => + Assert.That(this.serializer.Triples.Any(triple => { var valueMatches = ((LiteralNode)triple.Object).Value == "true"; var dataTypeMatches = ((LiteralNode)triple.Object).DataType == new Uri(Xsd.boolean); @@ -59,7 +59,7 @@ public void Should_serialize_bool_with_proper_format() public void Should_serialize_datetime_with_proper_format() { // given - A.CallTo(() => _entitySerializer.Serialize(A._, A._)) + A.CallTo(() => this.entitySerializer.Serialize(A._, A._)) .Returns(JObject.Parse(@"{ '@context': { @@ -72,10 +72,10 @@ public void Should_serialize_datetime_with_proper_format() }")); // when - _serializer.Serialize("text/turtle", new object(), new MemoryStream()); + this.serializer.Serialize("text/turtle", new object(), new MemoryStream()); // then - Assert.That(_serializer.Triples.Any(triple => + Assert.That(this.serializer.Triples.Any(triple => { var valueMatches = ((LiteralNode)triple.Object).Value == "2016-03-21T00:00:00"; var dataTypeMatches = ((LiteralNode)triple.Object).DataType == new Uri(Xsd.dateTime); @@ -88,20 +88,20 @@ public void Should_serialize_datetime_with_proper_format() public void Should_serialize_correct_relative_URIs_according_to_base() { // given - A.CallTo(() => _entitySerializer.Serialize(A._, A._)) + A.CallTo(() => this.entitySerializer.Serialize(A._, A._)) .Returns(JObject.Parse(@"{ '@id': 'some/id', 'http://example.com/property': { '@id': 'some/relative/path' } }")); // when - _serializer.Serialize("text/turtle", new WrappedModel(new object(), "http://example.api/site"), new MemoryStream()); + this.serializer.Serialize("text/turtle", new WrappedModel(new object(), "http://example.api/site"), new MemoryStream()); // then - Assert.That(_serializer.Triples.Contains(new Triple( - _nodeFactory.CreateUriNode(new Uri("http://example.api/site/some/id")), - _nodeFactory.CreateUriNode(new Uri("http://example.com/property")), - _nodeFactory.CreateUriNode(new Uri("http://example.api/site/some/relative/path"))))); + Assert.That(this.serializer.Triples.Contains(new Triple( + this.nodeFactory.CreateUriNode(new Uri("http://example.api/site/some/id")), + this.nodeFactory.CreateUriNode(new Uri("http://example.com/property")), + this.nodeFactory.CreateUriNode(new Uri("http://example.api/site/some/relative/path"))))); } private class RdfSerializerTestable : RdfSerializer @@ -109,14 +109,14 @@ private class RdfSerializerTestable : RdfSerializer public RdfSerializerTestable(IEntitySerializer entitySerializer) : base(RdfSerialization.Turtle, entitySerializer) { - Triples = new List(); + this.Triples = new List(); } public IList Triples { get; set; } protected override void WriteRdf(StreamWriter writer, IEnumerable triples) { - Triples = triples.ToList(); + this.Triples = triples.ToList(); } } } diff --git a/src/Nancy.Rdf/Contexts/ContextPathMap.cs b/src/Nancy.Rdf/Contexts/ContextPathMap.cs index ffd3eb1..df406bd 100644 --- a/src/Nancy.Rdf/Contexts/ContextPathMap.cs +++ b/src/Nancy.Rdf/Contexts/ContextPathMap.cs @@ -16,8 +16,8 @@ public struct ContextPathMap public ContextPathMap(string path, Type modelType) : this() { - Path = path; - ModelType = modelType; + this.Path = path; + this.ModelType = modelType; } /// @@ -51,7 +51,7 @@ public ContextPathMap(string path, Type modelType) /// public bool Equals(ContextPathMap other) { - return string.Equals(Path, other.Path) && ModelType == other.ModelType; + return string.Equals(this.Path, other.Path) && this.ModelType == other.ModelType; } /// @@ -64,7 +64,7 @@ public override bool Equals([AllowNull] object obj) return false; } - return obj is ContextPathMap && Equals((ContextPathMap)obj); + return obj is ContextPathMap && this.Equals((ContextPathMap)obj); } /// @@ -74,7 +74,7 @@ public override int GetHashCode() { unchecked { - return ((Path != null ? Path.GetHashCode() : 0) * 397) ^ (ModelType != null ? ModelType.GetHashCode() : 0); + return ((this.Path != null ? this.Path.GetHashCode() : 0) * 397) ^ (this.ModelType != null ? this.ModelType.GetHashCode() : 0); } } } diff --git a/src/Nancy.Rdf/Contexts/DefaultContextPathMapper.cs b/src/Nancy.Rdf/Contexts/DefaultContextPathMapper.cs index 3518779..e5cb3e9 100644 --- a/src/Nancy.Rdf/Contexts/DefaultContextPathMapper.cs +++ b/src/Nancy.Rdf/Contexts/DefaultContextPathMapper.cs @@ -8,14 +8,14 @@ namespace Nancy.Rdf.Contexts public class DefaultContextPathMapper : IContextPathMapper { private const string DefaultContextPath = "_contexts"; - private readonly IList _contexts = new List(); + private readonly IList contexts = new List(); /// /// Initializes a new instance of the class. /// public DefaultContextPathMapper() { - BasePath = DefaultContextPath; + this.BasePath = DefaultContextPath; } /// @@ -28,7 +28,7 @@ public DefaultContextPathMapper() /// public IEnumerable Contexts { - get { return _contexts; } + get { return this.contexts; } } /// @@ -37,7 +37,7 @@ public IEnumerable Contexts /// model type protected void ServeContextOf() { - ServeContextOf(typeof(T).Name); + this.ServeContextOf(typeof(T).Name); } /// @@ -47,7 +47,7 @@ protected void ServeContextOf() /// The path to server the @context at. protected void ServeContextOf(string path) { - _contexts.Add(new ContextPathMap(path, typeof(T))); + this.contexts.Add(new ContextPathMap(path, typeof(T))); } } } diff --git a/src/Nancy.Rdf/Contexts/JsonLdContextModule.cs b/src/Nancy.Rdf/Contexts/JsonLdContextModule.cs index d50693a..49a1f97 100644 --- a/src/Nancy.Rdf/Contexts/JsonLdContextModule.cs +++ b/src/Nancy.Rdf/Contexts/JsonLdContextModule.cs @@ -10,7 +10,7 @@ namespace Nancy.Rdf.Contexts /// public class JsonLdContextModule : NancyModule { - private readonly ContextResolver _resolver; + private readonly ContextResolver resolver; /// /// Initializes a new instance of the class. @@ -20,11 +20,11 @@ public class JsonLdContextModule : NancyModule public JsonLdContextModule(IContextPathMapper pathProvider, IContextProvider provider) : base(pathProvider.BasePath) { - _resolver = new ContextResolver(provider); + this.resolver = new ContextResolver(provider); foreach (var path in pathProvider.Contexts) { - Get(path.Path, ServeContextOf(path.ModelType)); + this.Get(path.Path, this.ServeContextOf(path.ModelType)); } } @@ -41,10 +41,10 @@ public JsonLdContextModule() { var context = new JObject { - { JsonLdKeywords.Context, _resolver.GetContext(modelType) } + { JsonLdKeywords.Context, this.resolver.GetContext(modelType) } }; var response = new TextResponse(context.ToString(), RdfSerialization.JsonLd.MediaType); - return Negotiate.WithAllowedMediaRange(RdfSerialization.JsonLd.MediaType) + return this.Negotiate.WithAllowedMediaRange(RdfSerialization.JsonLd.MediaType) .WithMediaRangeResponse(RdfSerialization.JsonLd.MediaType, response); }; } diff --git a/src/Nancy.Rdf/DictionaryNamespaceManager.cs b/src/Nancy.Rdf/DictionaryNamespaceManager.cs index e30e862..308e6d4 100644 --- a/src/Nancy.Rdf/DictionaryNamespaceManager.cs +++ b/src/Nancy.Rdf/DictionaryNamespaceManager.cs @@ -11,14 +11,14 @@ namespace Nancy.Rdf /// internal class DictionaryNamespaceManager : INamespaceManager { - private readonly IDictionary _namespaces; + private readonly IDictionary namespaces; /// /// Initializes a new instance of the class. /// public DictionaryNamespaceManager() { - _namespaces = new Dictionary(); + this.namespaces = new Dictionary(); } /// @@ -27,25 +27,25 @@ public DictionaryNamespaceManager() /// public IEnumerator GetEnumerator() { - return _namespaces.Select(p => new NamespaceMap(p.Key, p.Value)).GetEnumerator(); + return this.namespaces.Select(p => new NamespaceMap(p.Key, p.Value)).GetEnumerator(); } /// IEnumerator IEnumerable.GetEnumerator() { - return GetEnumerator(); + return this.GetEnumerator(); } /// public void AddNamespace(string prefix, Uri ns) { - _namespaces.Add(prefix, ns); + this.namespaces.Add(prefix, ns); } /// public void SetBaseUri([AllowNull] Uri baseUri) { - BaseUri = baseUri; + this.BaseUri = baseUri; } } } diff --git a/src/Nancy.Rdf/Installer.cs b/src/Nancy.Rdf/Installer.cs index e2a158c..316b621 100644 --- a/src/Nancy.Rdf/Installer.cs +++ b/src/Nancy.Rdf/Installer.cs @@ -15,9 +15,9 @@ public class Installer : Registrations public Installer(ITypeCatalog typeCatalog) : base(typeCatalog) { - RegisterWithDefault(typeof(DictionaryNamespaceManager)); - RegisterWithDefault(typeof(DefaultContextPathMapper)); - Register(typeof(EntitySerializer)); + this.RegisterWithDefault(typeof(DictionaryNamespaceManager)); + this.RegisterWithDefault(typeof(DefaultContextPathMapper)); + this.Register(typeof(EntitySerializer)); } } } diff --git a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs index f214149..67e7d97 100644 --- a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs @@ -33,7 +33,7 @@ public override object Deserialize(MediaRange contentType, Stream body, BindingC { var deserialize = DeserializeJsonLdMethod.MakeGenericMethod(context.DestinationType); - return deserialize.Invoke(Serializer, new object[] { JToken.ReadFrom(new JsonTextReader(bodyReader)) }); + return deserialize.Invoke(this.Serializer, new object[] { JToken.ReadFrom(new JsonTextReader(bodyReader)) }); } } } diff --git a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs index c168aa5..77cecfc 100644 --- a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs @@ -18,7 +18,7 @@ public abstract class NonJsonLdRdfBodyDeserializer : RdfBodyDeserializer private static readonly MethodInfo DeserializeNquadsMethod = typeof(IEntitySerializer).GetMethod("Deserialize", new[] { typeof(string) }); private static readonly IRdfWriter RdfWriter = new NTriplesWriter(NTriplesSyntax.Rdf11); - private readonly IRdfReader _reader; + private readonly IRdfReader reader; /// /// Initializes a new instance of the class. @@ -29,7 +29,7 @@ public abstract class NonJsonLdRdfBodyDeserializer : RdfBodyDeserializer IRdfReader reader) : base(serialization, serializer) { - _reader = reader; + this.reader = reader; } /// @@ -39,7 +39,7 @@ public override object Deserialize(MediaRange contentType, Stream body, BindingC { var deserialize = DeserializeNquadsMethod.MakeGenericMethod(context.DestinationType); - return deserialize.Invoke(Serializer, new object[] { GetNquads(body) }); + return deserialize.Invoke(this.Serializer, new object[] { this.GetNquads(body) }); } /// @@ -52,7 +52,7 @@ protected virtual string GetNquads(Stream body) using (var streamReader = new StreamReader(body)) { - _reader.Load(g, streamReader); + this.reader.Load(g, streamReader); } using (var stringWriter = new StringWriter()) diff --git a/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs index cad235c..5315169 100644 --- a/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs @@ -10,15 +10,15 @@ namespace Nancy.Rdf.ModelBinding /// public abstract class RdfBodyDeserializer : IBodyDeserializer { - private readonly RdfSerialization _serialization; + private readonly RdfSerialization serialization; /// /// Initializes a new instance of the class. /// protected RdfBodyDeserializer(RdfSerialization serialization, IEntitySerializer serializer) { - _serialization = serialization; - Serializer = serializer; + this.serialization = serialization; + this.Serializer = serializer; } /// @@ -32,7 +32,7 @@ protected RdfBodyDeserializer(RdfSerialization serialization, IEntitySerializer /// true for any of public bool CanDeserialize(MediaRange contentType, BindingContext context) { - return contentType.Matches(_serialization.MediaType); + return contentType.Matches(this.serialization.MediaType); } /// diff --git a/src/Nancy.Rdf/NamespaceMap.cs b/src/Nancy.Rdf/NamespaceMap.cs index de3d452..cc0ff6c 100644 --- a/src/Nancy.Rdf/NamespaceMap.cs +++ b/src/Nancy.Rdf/NamespaceMap.cs @@ -13,8 +13,8 @@ public struct NamespaceMap public NamespaceMap(string prefix, Uri ns) : this() { - Namespace = ns; - Prefix = prefix; + this.Namespace = ns; + this.Prefix = prefix; } /// diff --git a/src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset b/src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset deleted file mode 100644 index 9a55420..0000000 --- a/src/Nancy.Rdf/Nancy.Rdf.Tests.ruleset +++ /dev/null @@ -1,236 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Nancy.Rdf/Nancy.Rdf.csproj b/src/Nancy.Rdf/Nancy.Rdf.csproj index 6fc7389..3fd25cb 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.csproj +++ b/src/Nancy.Rdf/Nancy.Rdf.csproj @@ -38,8 +38,7 @@ 4 bin\Release\Nancy.Rdf.xml true - - + ..\..\paket-files\tpluscode\a285267d2543466fc35c3a168c846f9f\Library.ruleset false diff --git a/src/Nancy.Rdf/Nancy.Rdf.ruleset b/src/Nancy.Rdf/Nancy.Rdf.ruleset deleted file mode 100644 index 317f0a4..0000000 --- a/src/Nancy.Rdf/Nancy.Rdf.ruleset +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Nancy.Rdf/RdfSerialization.cs b/src/Nancy.Rdf/RdfSerialization.cs index 8c96b44..c053eee 100644 --- a/src/Nancy.Rdf/RdfSerialization.cs +++ b/src/Nancy.Rdf/RdfSerialization.cs @@ -9,13 +9,13 @@ namespace Nancy.Rdf /// public struct RdfSerialization { - private readonly string _mediaType; - private readonly string _extension; + private readonly string mediaType; + private readonly string extension; private RdfSerialization(string mediaType, string extension) { - _mediaType = mediaType; - _extension = extension; + this.mediaType = mediaType; + this.extension = extension; } /// @@ -93,7 +93,7 @@ public static RdfSerialization NTriples /// public string MediaType { - get { return _mediaType; } + get { return this.mediaType; } } /// @@ -101,7 +101,7 @@ public string MediaType /// public string Extension { - get { return _extension; } + get { return this.extension; } } #pragma warning disable 1591 @@ -120,7 +120,7 @@ public string Extension [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Operator or built-in override")] public bool Equals(RdfSerialization other) { - return string.Equals(_mediaType, other._mediaType) && string.Equals(_extension, other._extension); + return string.Equals(this.mediaType, other.mediaType) && string.Equals(this.extension, other.extension); } [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Operator or built-in override")] @@ -131,7 +131,7 @@ public override bool Equals([AllowNull] object obj) return false; } - return obj is RdfSerialization && Equals((RdfSerialization)obj); + return obj is RdfSerialization && this.Equals((RdfSerialization)obj); } [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Operator or built-in override")] @@ -139,7 +139,7 @@ public override int GetHashCode() { unchecked { - return (_mediaType.GetHashCode() * 397) ^ _extension.GetHashCode(); + return (this.mediaType.GetHashCode() * 397) ^ this.extension.GetHashCode(); } } #pragma warning restore @@ -149,7 +149,7 @@ public override int GetHashCode() /// public override string ToString() { - return MediaType; + return this.MediaType; } } } diff --git a/src/Nancy.Rdf/Responses/CompressingSerializer.cs b/src/Nancy.Rdf/Responses/CompressingSerializer.cs index b3fbe44..8bdaef4 100644 --- a/src/Nancy.Rdf/Responses/CompressingSerializer.cs +++ b/src/Nancy.Rdf/Responses/CompressingSerializer.cs @@ -10,7 +10,7 @@ namespace Nancy.Rdf.Responses /// public abstract class CompressingSerializer : RdfSerializer { - private readonly INamespaceManager _namespaces; + private readonly INamespaceManager namespaces; /// /// Initializes a new instance of the class. @@ -21,7 +21,7 @@ public abstract class CompressingSerializer : RdfSerializer protected CompressingSerializer(RdfSerialization rdfSerialization, IEntitySerializer entitySerializer, INamespaceManager namespaces) : base(rdfSerialization, entitySerializer) { - _namespaces = namespaces; + this.namespaces = namespaces; } /// @@ -29,14 +29,14 @@ protected CompressingSerializer(RdfSerialization rdfSerialization, IEntitySerial /// protected override void WriteRdf(StreamWriter writer, IEnumerable triples) { - var graph = new Graph(true) { BaseUri = _namespaces.BaseUri }; - foreach (var ns in _namespaces) + var graph = new Graph(true) { BaseUri = this.namespaces.BaseUri }; + foreach (var ns in this.namespaces) { graph.NamespaceMap.AddNamespace(ns.Prefix, ns.Namespace); } graph.Assert(triples); - graph.SaveToStream(writer, CreateWriter()); + graph.SaveToStream(writer, this.CreateWriter()); } /// diff --git a/src/Nancy.Rdf/Responses/JsonLdSerializer.cs b/src/Nancy.Rdf/Responses/JsonLdSerializer.cs index e1348ad..63ddd4c 100644 --- a/src/Nancy.Rdf/Responses/JsonLdSerializer.cs +++ b/src/Nancy.Rdf/Responses/JsonLdSerializer.cs @@ -18,16 +18,16 @@ namespace Nancy.Rdf.Responses public class JsonLdSerializer : IRdfSerializer { private static readonly RdfSerialization JsonLdSerialization = RdfSerialization.JsonLd; - private readonly IEntitySerializer _serializer; - private readonly IContextPathMapper _contextPathMapper; + private readonly IEntitySerializer serializer; + private readonly IContextPathMapper contextPathMapper; /// /// Initializes a new instance of the class. /// public JsonLdSerializer(IEntitySerializer serializer, IContextPathMapper contextPathMapper) { - _serializer = serializer; - _contextPathMapper = contextPathMapper; + this.serializer = serializer; + this.contextPathMapper = contextPathMapper; } /// @@ -67,7 +67,7 @@ public void Serialize(MediaRange mediaRange, TModel model, Stream output using (var writer = new StreamWriter(new UnclosableStreamWrapper(outputStream))) { - JToken serialized = _serializer.Serialize(actualModel); + JToken serialized = this.serializer.Serialize(actualModel); if (wrappedModel.HasValue) { @@ -82,12 +82,12 @@ public void Serialize(MediaRange mediaRange, TModel model, Stream output { if (serialized[JsonLdKeywords.Context] != null) { - var contextMap = _contextPathMapper.Contexts.FirstOrDefault(map => map.ModelType == actualModel.GetType()); + var contextMap = this.contextPathMapper.Contexts.FirstOrDefault(map => map.ModelType == actualModel.GetType()); if (contextMap != default(ContextPathMap) && wrappedModel != null) { var newContext = wrappedModel.Value.BaseUrl - .Append(_contextPathMapper.BasePath) + .Append(this.contextPathMapper.BasePath) .Append(contextMap.Path); serialized[JsonLdKeywords.Context] = newContext; } diff --git a/src/Nancy.Rdf/Responses/RdfResponseProcessor.cs b/src/Nancy.Rdf/Responses/RdfResponseProcessor.cs index bc3dcf9..40bac8d 100644 --- a/src/Nancy.Rdf/Responses/RdfResponseProcessor.cs +++ b/src/Nancy.Rdf/Responses/RdfResponseProcessor.cs @@ -10,8 +10,8 @@ namespace Nancy.Rdf.Responses /// public abstract class RdfResponseProcessor : IResponseProcessor { - private readonly RdfSerialization _serialization; - private readonly ISerializer _serializer; + private readonly RdfSerialization serialization; + private readonly ISerializer serializer; /// /// Initializes a new instance of the class. @@ -20,8 +20,8 @@ public abstract class RdfResponseProcessor : IResponseProcessor /// The serializers. protected RdfResponseProcessor(RdfSerialization serialization, IEnumerable serializers) { - _serialization = serialization; - _serializer = serializers.Cast().FirstOrDefault(s => s.CanSerialize(serialization.MediaType)); + this.serialization = serialization; + this.serializer = serializers.Cast().FirstOrDefault(s => s.CanSerialize(serialization.MediaType)); } /// @@ -31,7 +31,7 @@ protected RdfResponseProcessor(RdfSerialization serialization, IEnumerable { var wrappedModel = new WrappedModel(model, context.Request.Url.SiteBase); - _serializer.Serialize(requestedMediaRange, wrappedModel, stream); + this.serializer.Serialize(requestedMediaRange, wrappedModel, stream); }, StatusCode = HttpStatusCode.OK, - ContentType = _serialization.MediaType + ContentType = this.serialization.MediaType }; } diff --git a/src/Nancy.Rdf/Responses/RdfSerializer.cs b/src/Nancy.Rdf/Responses/RdfSerializer.cs index e9a75bc..5cb1313 100644 --- a/src/Nancy.Rdf/Responses/RdfSerializer.cs +++ b/src/Nancy.Rdf/Responses/RdfSerializer.cs @@ -16,9 +16,9 @@ namespace Nancy.Rdf.Responses /// public abstract class RdfSerializer : IRdfSerializer { - private readonly RdfSerialization _serialization; - private readonly INodeFactory _nodeFactory; - private readonly IEntitySerializer _entitySerializer; + private readonly RdfSerialization serialization; + private readonly INodeFactory nodeFactory; + private readonly IEntitySerializer entitySerializer; /// /// Initializes a new instance of the class. @@ -27,22 +27,22 @@ public abstract class RdfSerializer : IRdfSerializer /// The entity serializer. protected RdfSerializer(RdfSerialization serialization, IEntitySerializer entitySerializer) { - _serialization = serialization; - _entitySerializer = entitySerializer; + this.serialization = serialization; + this.entitySerializer = entitySerializer; - _nodeFactory = new NodeFactory(); + this.nodeFactory = new NodeFactory(); } /// public IEnumerable Extensions { - get { yield return _serialization.Extension; } + get { yield return this.serialization.Extension; } } /// public virtual bool CanSerialize(MediaRange contentType) { - return _serialization.MediaType.Equals(contentType, StringComparison.InvariantCultureIgnoreCase); + return this.serialization.MediaType.Equals(contentType, StringComparison.InvariantCultureIgnoreCase); } /// @@ -53,7 +53,7 @@ public void Serialize(MediaRange contentType, TModel model, Stream outpu using (var writer = new StreamWriter(new UnclosableStreamWrapper(outputStream))) { - var javascriptObject = _entitySerializer.Serialize(actualModel); + var javascriptObject = this.entitySerializer.Serialize(actualModel); if (wrappedModel != null) { javascriptObject.AddBaseToContext(wrappedModel.Value.BaseUrl); @@ -61,7 +61,7 @@ public void Serialize(MediaRange contentType, TModel model, Stream outpu var rdf = (RDFDataset)JsonLdProcessor.ToRDF(javascriptObject); - WriteRdf(writer, rdf.GetQuads("@default").Select(ToTriple)); + this.WriteRdf(writer, rdf.GetQuads("@default").Select(this.ToTriple)); } } @@ -74,25 +74,25 @@ private INode CreateNode(RDFDataset.Node node) { if (node.IsIRI()) { - return _nodeFactory.CreateUriNode(new Uri(node.GetValue())); + return this.nodeFactory.CreateUriNode(new Uri(node.GetValue())); } if (node.IsBlankNode()) { - return _nodeFactory.CreateBlankNode(node.GetValue()); + return this.nodeFactory.CreateBlankNode(node.GetValue()); } var literal = node.GetValue(); var datatype = new Uri(node.GetDatatype()); - return _nodeFactory.CreateLiteralNode(literal, datatype); + return this.nodeFactory.CreateLiteralNode(literal, datatype); } private Triple ToTriple(RDFDataset.Quad triple) { - var subj = CreateNode(triple.GetSubject()); - var pred = CreateNode(triple.GetPredicate()); - var obj = CreateNode(triple.GetObject()); + var subj = this.CreateNode(triple.GetSubject()); + var pred = this.CreateNode(triple.GetPredicate()); + var obj = this.CreateNode(triple.GetObject()); return new Triple(subj, pred, obj); } diff --git a/src/Nancy.Rdf/Responses/WrappedModel.cs b/src/Nancy.Rdf/Responses/WrappedModel.cs index 0dd1f22..d396b0e 100644 --- a/src/Nancy.Rdf/Responses/WrappedModel.cs +++ b/src/Nancy.Rdf/Responses/WrappedModel.cs @@ -12,8 +12,8 @@ public struct WrappedModel /// public WrappedModel(object model, string siteBase) { - Model = model; - BaseUrl = new Uri(siteBase, UriKind.Absolute); + this.Model = model; + this.BaseUrl = new Uri(siteBase, UriKind.Absolute); } /// diff --git a/src/Nancy.Rdf/paket.template b/src/Nancy.Rdf/paket.template index 185668a..5e1334c 100644 --- a/src/Nancy.Rdf/paket.template +++ b/src/Nancy.Rdf/paket.template @@ -4,6 +4,7 @@ excludeddependencies GitVersionTask dependencies JsonLD.Entities >= LOCKEDVERSION + Nancy >= LOCKEDVERSION projectUrl http://github.org/wikibus/Nancy.RDF description From 820a5cc285f6075f369806f3cb97d8e564faa83e Mon Sep 17 00:00:00 2001 From: tpluscode Date: Sun, 27 Nov 2016 18:01:26 +0100 Subject: [PATCH 09/11] added nullguard which fixes #5 --- src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj | 6 ++++-- src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs | 13 +++++++++++++ src/Nancy.Rdf/Nancy.Rdf.csproj | 7 ++++--- src/Nancy.Rdf/Responses/RdfResponseProcessor.cs | 5 +++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj index f369b9b..1b25945 100644 --- a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj +++ b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj @@ -25,7 +25,8 @@ prompt 4 false - ..\Nancy.RDF\Nancy.Rdf.Tests.ruleset + + true @@ -36,7 +37,8 @@ prompt 4 false - ..\..\paket-files\tpluscode\a285267d2543466fc35c3a168c846f9f\UnitTests.ruleset + + true diff --git a/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs b/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs index 6667214..fb1f9bb 100644 --- a/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs +++ b/src/Nancy.Rdf.Tests/RdfResponseProcessorTests.cs @@ -134,6 +134,19 @@ public void Should_pass_actual_requested() A._)).MustHaveHappened(); } + [Test] + public void CanProcess_Should_not_match_model_is_null() + { + // given + var processor = new RdfResponseProcessorTestable(new ISerializer[0]); + + // when + var match = processor.CanProcess(new MediaRange(RdfSerialization.RdfXml.MediaType), null, new NancyContext()); + + // then + Assert.That(match.ModelResult, Is.EqualTo(MatchResult.NoMatch)); + } + private class RdfResponseProcessorTestable : RdfResponseProcessor { public RdfResponseProcessorTestable(IEnumerable serializers) diff --git a/src/Nancy.Rdf/Nancy.Rdf.csproj b/src/Nancy.Rdf/Nancy.Rdf.csproj index 3fd25cb..e419141 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.csproj +++ b/src/Nancy.Rdf/Nancy.Rdf.csproj @@ -25,7 +25,8 @@ prompt 4 bin\Debug\Nancy.Rdf.xml - Nancy.Rdf.ruleset + + false true @@ -38,7 +39,8 @@ 4 bin\Release\Nancy.Rdf.xml true - ..\..\paket-files\tpluscode\a285267d2543466fc35c3a168c846f9f\Library.ruleset + + false @@ -96,7 +98,6 @@ - diff --git a/src/Nancy.Rdf/Responses/RdfResponseProcessor.cs b/src/Nancy.Rdf/Responses/RdfResponseProcessor.cs index 40bac8d..5dc19a7 100644 --- a/src/Nancy.Rdf/Responses/RdfResponseProcessor.cs +++ b/src/Nancy.Rdf/Responses/RdfResponseProcessor.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Nancy.Responses.Negotiation; +using NullGuard; namespace Nancy.Rdf.Responses { @@ -38,11 +39,11 @@ protected RdfResponseProcessor(RdfSerialization serialization, IEnumerable /// Determines whether the given and be processed in /// - public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context) + public ProcessorMatch CanProcess(MediaRange requestedMediaRange, [AllowNull] dynamic model, NancyContext context) { var match = new ProcessorMatch { - ModelResult = MatchResult.DontCare + ModelResult = model == null ? MatchResult.NoMatch : MatchResult.DontCare }; if (this.serializer != null) From 4a28f4a1909f5c189018d6d637d8dd00f07840fc Mon Sep 17 00:00:00 2001 From: tpluscode Date: Thu, 1 Dec 2016 20:23:34 +0100 Subject: [PATCH 10/11] update and use code analysis files --- paket.dependencies | 1 + paket.lock | 5 ++- src/Example/Nancy.Rdf.Sample/Web.config | 38 ++++++++++------------ src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj | 3 +- src/Nancy.Rdf/Nancy.Rdf.csproj | 3 +- src/Nancy.Rdf/app.config | 14 ++++---- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/paket.dependencies b/paket.dependencies index 44e1bf1..eaf160a 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -26,4 +26,5 @@ nuget Microsoft.Owin.Host.SystemWeb nuget Microsoft.Owin.Hosting nuget Rdf.Vocabularies +group code-analysis gist tpluscode/a285267d2543466fc35c3a168c846f9f \ No newline at end of file diff --git a/paket.lock b/paket.lock index 6dffde4..b5ce8f7 100644 --- a/paket.lock +++ b/paket.lock @@ -53,6 +53,9 @@ NUGET SpecFlow (2.1) StyleCop.Analyzers (1.0) VDS.Common (1.6.4) + +GROUP code-analysis + GIST remote: tpluscode/a285267d2543466fc35c3a168c846f9f - FULLPROJECT (1625e92556df16d60d7b04f2c01c8b77212afd6f) \ No newline at end of file + FULLPROJECT (c9b7a831e53e929f2ecce09b14a61e28007b669f) \ No newline at end of file diff --git a/src/Example/Nancy.Rdf.Sample/Web.config b/src/Example/Nancy.Rdf.Sample/Web.config index 20e400c..fa702b4 100644 --- a/src/Example/Nancy.Rdf.Sample/Web.config +++ b/src/Example/Nancy.Rdf.Sample/Web.config @@ -1,4 +1,4 @@ - + - - + + - - + + - - - - True - - - - - True - - - - - - \ No newline at end of file + + + + True + + + + + True + + + + \ No newline at end of file diff --git a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj index 1b25945..ffd9e36 100644 --- a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj +++ b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj @@ -37,8 +37,7 @@ prompt 4 false - - + ..\..\paket-files\tpluscode\a285267d2543466fc35c3a168c846f9f\UnitTests.ruleset true diff --git a/src/Nancy.Rdf/Nancy.Rdf.csproj b/src/Nancy.Rdf/Nancy.Rdf.csproj index e419141..0da9e98 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.csproj +++ b/src/Nancy.Rdf/Nancy.Rdf.csproj @@ -39,8 +39,7 @@ 4 bin\Release\Nancy.Rdf.xml true - - + ..\..\paket-files\tpluscode\a285267d2543466fc35c3a168c846f9f\Library.ruleset false diff --git a/src/Nancy.Rdf/app.config b/src/Nancy.Rdf/app.config index 94ee5d2..0d67cc4 100644 --- a/src/Nancy.Rdf/app.config +++ b/src/Nancy.Rdf/app.config @@ -1,14 +1,14 @@ - + - + True - - + + True - - + + - + From 37ec97effd8abc436a8904b440a63049581a85e9 Mon Sep 17 00:00:00 2001 From: tpluscode Date: Fri, 2 Dec 2016 21:24:54 +0100 Subject: [PATCH 11/11] simplify rdf deserializer hierarchy --- Nancy.Rdf.sln | 2 +- .../JsonldBodyDeserializerTests.cs | 47 +++++++++++ .../NonJsonLdRdfBodyDeserializerTests.cs | 76 ++++++++++++++++++ .../ModelBinding/RdfModelBinderTests.cs | 79 ------------------- src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj | 3 +- src/Nancy.Rdf/ModelBinding/IRdfConverter.cs | 17 ++++ .../ModelBinding/JsonldBodyDeserializer.cs | 2 +- .../NonJsonLdRdfBodyDeserializer.cs | 65 +++++++++------ .../ModelBinding/Notation3BodyDeserializer.cs | 19 ----- .../ModelBinding/NtriplesBodyDeserializer.cs | 33 -------- .../ModelBinding/RdfBodyDeserializer.cs | 11 +-- src/Nancy.Rdf/ModelBinding/RdfConverter.cs | 38 +++++++++ .../ModelBinding/RdfXmlBodyDeserializer.cs | 19 ----- .../ModelBinding/TurtleBodyDeserializer.cs | 19 ----- src/Nancy.Rdf/Nancy.Rdf.csproj | 6 +- 15 files changed, 229 insertions(+), 207 deletions(-) create mode 100644 src/Nancy.Rdf.Tests/ModelBinding/JsonldBodyDeserializerTests.cs create mode 100644 src/Nancy.Rdf.Tests/ModelBinding/NonJsonLdRdfBodyDeserializerTests.cs delete mode 100644 src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs create mode 100644 src/Nancy.Rdf/ModelBinding/IRdfConverter.cs delete mode 100644 src/Nancy.Rdf/ModelBinding/Notation3BodyDeserializer.cs delete mode 100644 src/Nancy.Rdf/ModelBinding/NtriplesBodyDeserializer.cs create mode 100644 src/Nancy.Rdf/ModelBinding/RdfConverter.cs delete mode 100644 src/Nancy.Rdf/ModelBinding/RdfXmlBodyDeserializer.cs delete mode 100644 src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs diff --git a/Nancy.Rdf.sln b/Nancy.Rdf.sln index 9024235..859eb19 100644 --- a/Nancy.Rdf.sln +++ b/Nancy.Rdf.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.Rdf", "src\Nancy.Rdf\Nancy.Rdf.csproj", "{D789D63C-821B-410B-A953-DFEBCBFC9D40}" EndProject diff --git a/src/Nancy.Rdf.Tests/ModelBinding/JsonldBodyDeserializerTests.cs b/src/Nancy.Rdf.Tests/ModelBinding/JsonldBodyDeserializerTests.cs new file mode 100644 index 0000000..5566e4e --- /dev/null +++ b/src/Nancy.Rdf.Tests/ModelBinding/JsonldBodyDeserializerTests.cs @@ -0,0 +1,47 @@ +using System.IO; +using System.Text; +using FakeItEasy; +using FluentAssertions; +using JsonLD.Entities; +using Nancy.ModelBinding; +using Nancy.Rdf.ModelBinding; +using Newtonsoft.Json.Linq; +using NUnit.Framework; + +namespace Nancy.Rdf.Tests.ModelBinding +{ + public class JsonldBodyDeserializerTests + { + [Test] + public void Should_support_jsonld() + { + // given + var entitySerializer = A.Fake(); + var deserializer = new JsonldBodyDeserializer(entitySerializer); + + // then + deserializer.CanDeserialize(RdfSerialization.JsonLd.MediaType, new BindingContext()) + .Should().BeTrue(); + } + + [Test] + public void Deserialize_should_deserialize_JSONLD_proper_type_using_entity_serializer() + { + // given + var entitySerializer = A.Fake(); + var binder = new JsonldBodyDeserializer(entitySerializer); + var bindingContext = new BindingContext { DestinationType = typeof(TestModel) }; + var body = new MemoryStream(Encoding.UTF8.GetBytes("{}")); + + // when + binder.Deserialize(RdfSerialization.JsonLd.MediaType, body, bindingContext); + + // then + A.CallTo(() => entitySerializer.Deserialize(A._)).MustHaveHappened(); + } + + private class TestModel + { + } + } +} \ No newline at end of file diff --git a/src/Nancy.Rdf.Tests/ModelBinding/NonJsonLdRdfBodyDeserializerTests.cs b/src/Nancy.Rdf.Tests/ModelBinding/NonJsonLdRdfBodyDeserializerTests.cs new file mode 100644 index 0000000..683cde4 --- /dev/null +++ b/src/Nancy.Rdf.Tests/ModelBinding/NonJsonLdRdfBodyDeserializerTests.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using FakeItEasy; +using FluentAssertions; +using JsonLD.Entities; +using Nancy.ModelBinding; +using Nancy.Rdf.ModelBinding; +using Nancy.Rdf.Responses; +using NUnit.Framework; +using VDS.RDF; +using VDS.RDF.Parsing; + +namespace Nancy.Rdf.Tests.ModelBinding +{ + public class NonJsonLdRdfBodyDeserializerTests + { + private readonly BindingContext bindingContext = new BindingContext { DestinationType = typeof(TestModel) }; + + [TestCaseSource(nameof(NonJsonLdSerializations))] + public void Should_support_serialization(RdfSerialization serialization) + { + // given + var deserializer = new NonJsonLdRdfBodyDeserializer(A.Fake()); + + // when + deserializer.CanDeserialize(serialization.MediaType, new BindingContext()); + } + + [Test] + public void Deserialize_should_deserialize_directly_from_ntriples() + { + // given + var entitySerializer = A.Fake(); + var binder = new NonJsonLdRdfBodyDeserializer(entitySerializer); + const string bodyString = "some nquads"; + var body = new MemoryStream(Encoding.UTF8.GetBytes(bodyString)); + + // when + binder.Deserialize(RdfSerialization.NTriples.MediaType, body, this.bindingContext); + + // then + A.CallTo(() => entitySerializer.Deserialize(bodyString)).MustHaveHappened(); + } + + [Test, Sequential] + public void Deserialize_should_convert_to_ntriples( + [ValueSource(nameof(NonJsonLdSerializations))] RdfSerialization serialization, + [Values(typeof(Notation3Parser), typeof(TurtleParser), typeof(RdfXmlParser))] Type serializerType) + { + // given + var converter = A.Fake(); + var deserializer = new NonJsonLdRdfBodyDeserializer(A.Fake(), converter); + var body = new MemoryStream(); + + // when + deserializer.Deserialize(serialization.MediaType, body, this.bindingContext); + + // then + A.CallTo(() => converter.ConvertToNtriples(body, A.That.Matches(rr => rr.GetType() == serializerType))).MustHaveHappened(); + } + + public IEnumerable NonJsonLdSerializations() + { + yield return RdfSerialization.Notation3; + yield return RdfSerialization.Turtle; + yield return RdfSerialization.RdfXml; + } + + private class TestModel + { + } + } +} \ No newline at end of file diff --git a/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs b/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs deleted file mode 100644 index d68e2c4..0000000 --- a/src/Nancy.Rdf.Tests/ModelBinding/RdfModelBinderTests.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System.IO; -using System.Text; -using FakeItEasy; -using FluentAssertions; -using JsonLD.Entities; -using Nancy.ModelBinding; -using Nancy.Rdf.ModelBinding; -using Nancy.Responses.Negotiation; -using Newtonsoft.Json.Linq; -using NUnit.Framework; - -namespace Nancy.Rdf.Tests.ModelBinding -{ - public class RdfModelBinderTests - { - [Test] - public void CanDeserialize_should_return_true_supported_media_type() - { - // given - var binder = new RdfBodyDeserializerTestable(A.Fake()); - - // when - var canDeserialize = binder.CanDeserialize(RdfSerialization.NTriples.MediaType, new BindingContext()); - - // then - canDeserialize.Should().BeTrue(); - } - - [Test] - public void Deserialize_should_deserialize_JSONLD_proper_type_using_entity_serializer() - { - // given - var entitySerializer = A.Fake(); - var binder = new JsonldBodyDeserializer(entitySerializer); - var bindingContext = new BindingContext { DestinationType = typeof(TestModel) }; - var body = new MemoryStream(Encoding.UTF8.GetBytes("{}")); - - // when - binder.Deserialize(RdfSerialization.JsonLd.MediaType, body, bindingContext); - - // then - A.CallTo(() => entitySerializer.Deserialize(A._)).MustHaveHappened(); - } - - [Test] - public void Deserialize_should_deserialize_directly_from_ntriples() - { - // given - var entitySerializer = A.Fake(); - var binder = new NtriplesBodyDeserializer(entitySerializer); - var bindingContext = new BindingContext { DestinationType = typeof(TestModel) }; - const string bodyString = "some nquads"; - var body = new MemoryStream(Encoding.UTF8.GetBytes(bodyString)); - - // when - binder.Deserialize(RdfSerialization.NTriples.MediaType, body, bindingContext); - - // then - A.CallTo(() => entitySerializer.Deserialize(bodyString)).MustHaveHappened(); - } - - private class RdfBodyDeserializerTestable : RdfBodyDeserializer - { - public RdfBodyDeserializerTestable(IEntitySerializer entitySerializer) - : base(RdfSerialization.NTriples, entitySerializer) - { - } - - public override object Deserialize(MediaRange contentType, Stream body, BindingContext context) - { - throw new System.NotImplementedException(); - } - } - - private class TestModel - { - } - } -} diff --git a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj index ffd9e36..29ffff1 100644 --- a/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj +++ b/src/Nancy.Rdf.Tests/Nancy.Rdf.Tests.csproj @@ -65,7 +65,8 @@ - + + diff --git a/src/Nancy.Rdf/ModelBinding/IRdfConverter.cs b/src/Nancy.Rdf/ModelBinding/IRdfConverter.cs new file mode 100644 index 0000000..6de4d53 --- /dev/null +++ b/src/Nancy.Rdf/ModelBinding/IRdfConverter.cs @@ -0,0 +1,17 @@ +using System.IO; +using VDS.RDF; + +namespace Nancy.Rdf.ModelBinding +{ + /// + /// Converts RDF serializations to n-triples + /// + public interface IRdfConverter + { + /// + /// Converts to nquads. + /// + /// input rdf serialized as n-triples + string ConvertToNtriples(Stream rdf, IRdfReader reader); + } +} \ No newline at end of file diff --git a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs index 67e7d97..184f640 100644 --- a/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/JsonldBodyDeserializer.cs @@ -19,7 +19,7 @@ public class JsonldBodyDeserializer : RdfBodyDeserializer /// Initializes a new instance of the class. /// public JsonldBodyDeserializer(IEntitySerializer serializer) - : base(RdfSerialization.JsonLd, serializer) + : base(serializer, RdfSerialization.JsonLd) { } diff --git a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs index 77cecfc..41d59ee 100644 --- a/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/NonJsonLdRdfBodyDeserializer.cs @@ -1,4 +1,6 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Reflection; using JsonLD.Entities; using Nancy.ModelBinding; @@ -6,60 +8,71 @@ using VDS.RDF; using VDS.RDF.Parsing; using VDS.RDF.Writing; -using StringWriter = System.IO.StringWriter; namespace Nancy.Rdf.ModelBinding { /// - /// Converts body, first converting it to NQuads + /// Deserializers request body, first converting it to n-triples /// - public abstract class NonJsonLdRdfBodyDeserializer : RdfBodyDeserializer + public class NonJsonLdRdfBodyDeserializer : RdfBodyDeserializer { private static readonly MethodInfo DeserializeNquadsMethod = typeof(IEntitySerializer).GetMethod("Deserialize", new[] { typeof(string) }); - private static readonly IRdfWriter RdfWriter = new NTriplesWriter(NTriplesSyntax.Rdf11); - private readonly IRdfReader reader; + private readonly IDictionary readers; + private readonly IRdfConverter converter; /// /// Initializes a new instance of the class. /// - protected NonJsonLdRdfBodyDeserializer( - RdfSerialization serialization, - IEntitySerializer serializer, - IRdfReader reader) - : base(serialization, serializer) + public NonJsonLdRdfBodyDeserializer(IEntitySerializer serializer) + : this(serializer, new RdfConverter()) { - this.reader = reader; } /// - /// Deserialize the request body to a model + /// Initializes a new instance of the class. /// - public override object Deserialize(MediaRange contentType, Stream body, BindingContext context) + public NonJsonLdRdfBodyDeserializer( + IEntitySerializer serializer, + IRdfConverter converter) + : this(serializer, RdfSerialization.RdfXml, RdfSerialization.NTriples, RdfSerialization.Notation3, RdfSerialization.Turtle) { - var deserialize = DeserializeNquadsMethod.MakeGenericMethod(context.DestinationType); + this.converter = converter; + } - return deserialize.Invoke(this.Serializer, new object[] { this.GetNquads(body) }); + private NonJsonLdRdfBodyDeserializer(IEntitySerializer serializer, params RdfSerialization[] serializations) + : base(serializer, serializations) + { + this.readers = new Dictionary + { + { RdfSerialization.Notation3, new Notation3Parser() }, + { RdfSerialization.RdfXml, new RdfXmlParser() }, + { RdfSerialization.Turtle, new TurtleParser() } + }; } /// - /// Converts body to N-Triples + /// Deserialize the request body to a model /// - protected virtual string GetNquads(Stream body) + public override object Deserialize(MediaRange contentType, Stream body, BindingContext context) { - // todo: implement actual parsers for json-ld.net so that it's not necessary to parse and write to ntriples - IGraph g = new Graph(); + var deserialize = DeserializeNquadsMethod.MakeGenericMethod(context.DestinationType); + string nquads; - using (var streamReader = new StreamReader(body)) + if (contentType.Matches(RdfSerialization.NTriples.MediaType)) { - this.reader.Load(g, streamReader); + using (var bodyReader = new StreamReader(body)) + { + nquads = bodyReader.ReadToEnd(); + } } - - using (var stringWriter = new StringWriter()) + else { - RdfWriter.Save(g, stringWriter); - return stringWriter.ToString(); + var reader = this.readers.First(r => contentType.Matches(r.Key.MediaType)).Value; + nquads = this.converter.ConvertToNtriples(body, reader); } + + return deserialize.Invoke(this.Serializer, new object[] { nquads }); } } } diff --git a/src/Nancy.Rdf/ModelBinding/Notation3BodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/Notation3BodyDeserializer.cs deleted file mode 100644 index b0c2db5..0000000 --- a/src/Nancy.Rdf/ModelBinding/Notation3BodyDeserializer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using JsonLD.Entities; -using VDS.RDF.Parsing; - -namespace Nancy.Rdf.ModelBinding -{ - /// - /// Deserializes N3 request body to model - /// - public class Notation3BodyDeserializer : NonJsonLdRdfBodyDeserializer - { - /// - /// Initializes a new instance of the class. - /// - public Notation3BodyDeserializer(IEntitySerializer serializer) - : base(RdfSerialization.Notation3, serializer, new Notation3Parser()) - { - } - } -} diff --git a/src/Nancy.Rdf/ModelBinding/NtriplesBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/NtriplesBodyDeserializer.cs deleted file mode 100644 index 664ccc5..0000000 --- a/src/Nancy.Rdf/ModelBinding/NtriplesBodyDeserializer.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.IO; -using JsonLD.Entities; -using VDS.RDF.Parsing; - -namespace Nancy.Rdf.ModelBinding -{ - /// - /// Deserializes N-Triples request body to model - /// - public class NtriplesBodyDeserializer : NonJsonLdRdfBodyDeserializer - { - /// - /// Initializes a new instance of the class. - /// - /// The serializer. - public NtriplesBodyDeserializer(IEntitySerializer serializer) - : base(RdfSerialization.NTriples, serializer, new NTriplesParser()) - { - } - - /// - /// Reads the into NQuads. - /// - protected override string GetNquads(Stream body) - { - body.Position = 0; - using (var bodyReader = new StreamReader(body)) - { - return bodyReader.ReadToEnd(); - } - } - } -} diff --git a/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs index 5315169..8204e66 100644 --- a/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs +++ b/src/Nancy.Rdf/ModelBinding/RdfBodyDeserializer.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Linq; using JsonLD.Entities; using Nancy.ModelBinding; using Nancy.Responses.Negotiation; @@ -10,21 +11,21 @@ namespace Nancy.Rdf.ModelBinding /// public abstract class RdfBodyDeserializer : IBodyDeserializer { - private readonly RdfSerialization serialization; + private readonly MediaRange[] serializations; /// /// Initializes a new instance of the class. /// - protected RdfBodyDeserializer(RdfSerialization serialization, IEntitySerializer serializer) + protected RdfBodyDeserializer(IEntitySerializer serializer, params RdfSerialization[] serializations) { - this.serialization = serialization; + this.serializations = serializations.Select(s => new MediaRange(s.MediaType)).ToArray(); this.Serializer = serializer; } /// /// Gets the serializer. /// - public IEntitySerializer Serializer { get; } + protected IEntitySerializer Serializer { get; } /// /// Determines whether this instance can deserialize the specified content type. @@ -32,7 +33,7 @@ protected RdfBodyDeserializer(RdfSerialization serialization, IEntitySerializer /// true for any of public bool CanDeserialize(MediaRange contentType, BindingContext context) { - return contentType.Matches(this.serialization.MediaType); + return this.serializations.Any(contentType.Matches); } /// diff --git a/src/Nancy.Rdf/ModelBinding/RdfConverter.cs b/src/Nancy.Rdf/ModelBinding/RdfConverter.cs new file mode 100644 index 0000000..754c6ae --- /dev/null +++ b/src/Nancy.Rdf/ModelBinding/RdfConverter.cs @@ -0,0 +1,38 @@ +using System.IO; +using VDS.RDF; +using VDS.RDF.Parsing; +using VDS.RDF.Writing; +using StringWriter = System.IO.StringWriter; + +namespace Nancy.Rdf.ModelBinding +{ + /// + /// Converts RDF serializations to n-triples + /// + /// + public class RdfConverter : IRdfConverter + { + private static readonly NTriplesWriter NTriplesWriter = new NTriplesWriter(NTriplesSyntax.Rdf11); + + /// + /// Converts to nquads. + /// + /// input rdf serialized as n-triples + public string ConvertToNtriples(Stream rdf, IRdfReader reader) + { + // todo: implement actual parsers for json-ld.net so that it's not necessary to parse and write to ntriples + IGraph g = new Graph(); + + using (var streamReader = new StreamReader(rdf)) + { + reader.Load(g, streamReader); + } + + using (var stringWriter = new StringWriter()) + { + NTriplesWriter.Save(g, stringWriter); + return stringWriter.ToString(); + } + } + } +} \ No newline at end of file diff --git a/src/Nancy.Rdf/ModelBinding/RdfXmlBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/RdfXmlBodyDeserializer.cs deleted file mode 100644 index 91ac7e9..0000000 --- a/src/Nancy.Rdf/ModelBinding/RdfXmlBodyDeserializer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using JsonLD.Entities; -using VDS.RDF.Parsing; - -namespace Nancy.Rdf.ModelBinding -{ - /// - /// Deserializes RDF/XML request body to model - /// - public class RdfXmlBodyDeserializer : NonJsonLdRdfBodyDeserializer - { - /// - /// Initializes a new instance of the class. - /// - public RdfXmlBodyDeserializer(IEntitySerializer serializer) - : base(RdfSerialization.RdfXml, serializer, new RdfXmlParser()) - { - } - } -} diff --git a/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs b/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs deleted file mode 100644 index 22dc16c..0000000 --- a/src/Nancy.Rdf/ModelBinding/TurtleBodyDeserializer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using JsonLD.Entities; -using VDS.RDF.Parsing; - -namespace Nancy.Rdf.ModelBinding -{ - /// - /// Deserializes Turtle request body to model - /// - public class TurtleBodyDeserializer : NonJsonLdRdfBodyDeserializer - { - /// - /// Initializes a new instance of the class. - /// - public TurtleBodyDeserializer(IEntitySerializer serializer) - : base(RdfSerialization.Turtle, serializer, new TurtleParser()) - { - } - } -} diff --git a/src/Nancy.Rdf/Nancy.Rdf.csproj b/src/Nancy.Rdf/Nancy.Rdf.csproj index 0da9e98..8162734 100644 --- a/src/Nancy.Rdf/Nancy.Rdf.csproj +++ b/src/Nancy.Rdf/Nancy.Rdf.csproj @@ -62,13 +62,11 @@ + - - - - +