From af11605cb67e480a604c5cc7a3b7f7eefe98867a Mon Sep 17 00:00:00 2001 From: Donald Gray Date: Thu, 12 May 2022 11:48:10 +0100 Subject: [PATCH] Add imageService3 serialisation tests --- .../ImageService3SerialiserTests.cs | 38 +++++++++++++++++++ .../IIIF/ImageApi/Service/ImageService3.cs | 9 +---- .../ServiceReferenceConverter.cs | 3 +- src/IIIF/IIIF/Serialisation/SizeConverter.cs | 3 +- .../IIIF/Serialisation/TargetConverter.cs | 1 - 5 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 src/IIIF/IIIF.Tests/Serialisation/ImageService3SerialiserTests.cs diff --git a/src/IIIF/IIIF.Tests/Serialisation/ImageService3SerialiserTests.cs b/src/IIIF/IIIF.Tests/Serialisation/ImageService3SerialiserTests.cs new file mode 100644 index 0000000..004c6e7 --- /dev/null +++ b/src/IIIF/IIIF.Tests/Serialisation/ImageService3SerialiserTests.cs @@ -0,0 +1,38 @@ +using FluentAssertions; +using IIIF.ImageApi.Service; +using IIIF.Serialisation; +using Xunit; + +namespace IIIF.Tests.Serialisation +{ + public class ImageService3SerialiserTests + { + [Fact] + public void WriteJson_OutputsExpected_IfNoProfileOrProfileDescription() + { + // Arrange + var imageService = new ImageService3 { Id = "foo" }; + const string expected = "{\n \"id\": \"foo\",\n \"type\": \"ImageService3\"\n}"; + + // Act + var result = imageService.AsJson().Replace("\r\n", "\n"); + + // Assert + result.Should().Be(expected); + } + + [Fact] + public void WriteJson_OutputsExpected_ProfileOnly() + { + // Arrange + var imageService = new ImageService3 { Id = "foo", Profile = "bar" }; + const string expected = "{\n \"id\": \"foo\",\n \"type\": \"ImageService3\",\n \"profile\": \"bar\"\n}"; + + // Act + var result = imageService.AsJson().Replace("\r\n", "\n"); + + // Assert + result.Should().Be(expected); + } + } +} \ No newline at end of file diff --git a/src/IIIF/IIIF/ImageApi/Service/ImageService3.cs b/src/IIIF/IIIF/ImageApi/Service/ImageService3.cs index b4e8010..7bd473f 100644 --- a/src/IIIF/IIIF/ImageApi/Service/ImageService3.cs +++ b/src/IIIF/IIIF/ImageApi/Service/ImageService3.cs @@ -9,15 +9,10 @@ public class ImageService3 : ResourceBase public const string Image3Context = "http://iiif.io/api/image/3/context.json"; public const string ImageProtocol = "http://iiif.io/api/image"; - public ImageService3() - { - Context = Image3Context; - } - public override string Type => nameof(ImageService3); - [JsonProperty(Order = 3)] - public string Protocol => ImageProtocol; + [JsonProperty(Order = 10)] + public string Protocol { get; set; } [JsonProperty(Order = 11)] public int Width { get; set; } diff --git a/src/IIIF/IIIF/Serialisation/ServiceReferenceConverter.cs b/src/IIIF/IIIF/Serialisation/ServiceReferenceConverter.cs index 36a0e31..f03bda4 100644 --- a/src/IIIF/IIIF/Serialisation/ServiceReferenceConverter.cs +++ b/src/IIIF/IIIF/Serialisation/ServiceReferenceConverter.cs @@ -1,5 +1,4 @@ -using IIIF.Presentation.V2.Serialisation; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace IIIF.Serialisation { diff --git a/src/IIIF/IIIF/Serialisation/SizeConverter.cs b/src/IIIF/IIIF/Serialisation/SizeConverter.cs index abf5a2c..fcda0c1 100644 --- a/src/IIIF/IIIF/Serialisation/SizeConverter.cs +++ b/src/IIIF/IIIF/Serialisation/SizeConverter.cs @@ -1,5 +1,4 @@ -using IIIF.Presentation.V2.Serialisation; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace IIIF.Serialisation { diff --git a/src/IIIF/IIIF/Serialisation/TargetConverter.cs b/src/IIIF/IIIF/Serialisation/TargetConverter.cs index 8489503..067431d 100644 --- a/src/IIIF/IIIF/Serialisation/TargetConverter.cs +++ b/src/IIIF/IIIF/Serialisation/TargetConverter.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using IIIF.Presentation.V3; using IIIF.Utils; using Newtonsoft.Json;