-
Notifications
You must be signed in to change notification settings - Fork 2
/
NonJsonLdRdfBodyDeserializerTests.cs
76 lines (65 loc) · 2.66 KB
/
NonJsonLdRdfBodyDeserializerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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<IEntitySerializer>(), new RdfConverter());
// when
deserializer.CanDeserialize(serialization.MediaType, new BindingContext());
}
[Test]
public void Deserialize_should_deserialize_directly_from_ntriples()
{
// given
var entitySerializer = A.Fake<IEntitySerializer>();
var binder = new NonJsonLdRdfBodyDeserializer(entitySerializer, new RdfConverter());
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<TestModel>(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<IRdfConverter>();
var deserializer = new NonJsonLdRdfBodyDeserializer(A.Fake<IEntitySerializer>(), converter);
var body = new MemoryStream();
// when
deserializer.Deserialize(serialization.MediaType, body, this.bindingContext);
// then
A.CallTo(() => converter.ConvertToNtriples(body, A<IRdfReader>.That.Matches(rr => rr.GetType() == serializerType))).MustHaveHappened();
}
public static IEnumerable<RdfSerialization> NonJsonLdSerializations()
{
yield return RdfSerialization.Notation3;
yield return RdfSerialization.Turtle;
yield return RdfSerialization.RdfXml;
}
private class TestModel
{
}
}
}