Skip to content

Commit

Permalink
Allow canvas to have items that target itself
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldgray committed May 12, 2022
1 parent bb156aa commit 7ba7c90
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
72 changes: 69 additions & 3 deletions src/IIIF/IIIF.Tests/Presentation/V3/CanvasTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FluentAssertions;
using IIIF.Presentation.V3;
using IIIF.Presentation.V3.Annotation;
using IIIF.Presentation.V3.Content;
using IIIF.Presentation.V3.Strings;
using IIIF.Serialisation;
using Xunit;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void SerialiseTargetAsId_True_RendersIdAsTarget()
[Fact]
public void SerialiseTargetAsId_False_RendersFullCanvasAsTarget()
{
var targetIsIdOnlyCanvas = new Canvas
var targetIsFullCanvas = new Canvas
{
Id = "https://test.example.com/canvas/full",
Width = 1000,
Expand All @@ -102,7 +103,7 @@ public void SerialiseTargetAsId_False_RendersFullCanvasAsTarget()
Id = "https://test.example.com/canvas/referencing/page",
Items = new List<IAnnotation>
{
new PaintingAnnotation { Target = targetIsIdOnlyCanvas, }
new PaintingAnnotation { Target = targetIsFullCanvas, }
}
}
}
Expand All @@ -113,7 +114,7 @@ public void SerialiseTargetAsId_False_RendersFullCanvasAsTarget()
Context = "http://iiif.io/api/presentation/3/context.json",
Id = "https://test.example.com/manifest",
Label = new LanguageMap("en", "Test string"),
Items = new List<Canvas> { targetIsIdOnlyCanvas, referencingCanvas }
Items = new List<Canvas> { targetIsFullCanvas, referencingCanvas }
};

var serialisedManifest = manifest.AsJson().Replace("\r\n", "\n");
Expand Down Expand Up @@ -157,5 +158,70 @@ public void SerialiseTargetAsId_False_RendersFullCanvasAsTarget()

serialisedManifest.Should().BeEquivalentTo(expected);
}

[Fact]
public void CanSelfReferenceCanvas()
{
var canvas = new Canvas
{
Id = "https://test.example.com/canvas/target-id-only",
SerialiseTargetAsId = true
};

canvas.Items = new List<AnnotationPage>
{
new()
{
Id = "https://test.example.com/canvas/referencing/page",
Items = new List<IAnnotation>
{
new PaintingAnnotation
{
Id = "https://test.example.com/canvas/referencing/page/anno",
Target = canvas,
}
}
}
};

var manifest = new Manifest
{
Context = "http://iiif.io/api/presentation/3/context.json",
Id = "https://test.example.com/manifest",
Label = new LanguageMap("en", "Test string"),
Items = new List<Canvas> { canvas }
};

var serialisedManifest = manifest.AsJson().Replace("\r\n", "\n");

const string expected = @"{
""@context"": ""http://iiif.io/api/presentation/3/context.json"",
""id"": ""https://test.example.com/manifest"",
""type"": ""Manifest"",
""label"": {""en"":[""Test string""]},
""items"": [
{
""id"": ""https://test.example.com/canvas/target-id-only"",
""type"": ""Canvas"",
""items"": [
{
""id"": ""https://test.example.com/canvas/referencing/page"",
""type"": ""AnnotationPage"",
""items"": [
{
""id"": ""https://test.example.com/canvas/referencing/page/anno"",
""type"": ""Annotation"",
""motivation"": ""painting"",
""target"": ""https://test.example.com/canvas/target-id-only""
}
]
}
]
}
]
}";

serialisedManifest.Should().BeEquivalentTo(expected);
}
}
}
1 change: 1 addition & 0 deletions src/IIIF/IIIF/Serialisation/IIIFSerialiserX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class IIIFSerialiserX
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new PrettyIIIFContractResolver(),
Formatting = Formatting.Indented,
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
Converters = new List<JsonConverter>
{
new SizeConverter(), new StringArrayConverter(), new ServiceReferenceConverter(),
Expand Down

0 comments on commit 7ba7c90

Please sign in to comment.