-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from dlcs/feature/validate_manifest_parent
Validate hierarchical manifest parent
- Loading branch information
Showing
10 changed files
with
230 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/IIIFPresentation/API.Tests/Infrastructure/Validation/PresentationValidationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using API.Converters; | ||
using API.Infrastructure.Validation; | ||
using Models.API; | ||
using Models.Database.Collections; | ||
|
||
namespace API.Tests.Infrastructure.Validation; | ||
|
||
public class PresentationValidationTests | ||
{ | ||
private readonly UrlRoots urlRoots = new() { BaseUrl = "https://api.tests" }; | ||
|
||
[Fact] | ||
public void IsUriParentInvalid_False_IfNotUri() | ||
{ | ||
// Arrange | ||
var presentation = new TestPresentation { Parent = "foo" }; | ||
var parent = new Collection { Id = "bar" }; | ||
|
||
// Assert | ||
presentation.IsUriParentInvalid(parent, urlRoots).Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void IsUriParentInvalid_False_IfUriAndMatchesParent() | ||
{ | ||
// Arrange | ||
var presentation = new TestPresentation { Parent = "https://api.tests/1/collections/parent" }; | ||
var parent = new Collection { Id = "parent", CustomerId = 1 }; | ||
|
||
// Assert | ||
presentation.IsUriParentInvalid(parent, urlRoots).Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void IsUriParentInvalid_True_IfUriAndDoesNotMatchParent() | ||
{ | ||
// Arrange | ||
var presentation = new TestPresentation { Parent = "https://api.tests/not-parent" }; | ||
var parent = new Collection { Id = "parent", CustomerId = 1 }; | ||
|
||
// Assert | ||
presentation.IsUriParentInvalid(parent, urlRoots).Should().BeTrue(); | ||
} | ||
} | ||
|
||
public class TestPresentation : IPresentation | ||
{ | ||
public string? Slug { get; set; } | ||
public string? Parent { get; set; } | ||
public DateTime Created { get; set; } | ||
public DateTime Modified { get; set; } | ||
public string? CreatedBy { get; set; } | ||
public string? ModifiedBy { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.