-
Notifications
You must be signed in to change notification settings - Fork 2
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 #745 from dlcs/feature/implementDefaultDeliveryCha…
…nnels Implementing default delivery channel matching
- Loading branch information
Showing
32 changed files
with
1,061 additions
and
395 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/protagonist/API.Tests/Features/DeliveryChannels/DefaultDeliveryChannelRepositoryTests.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,102 @@ | ||
using System; | ||
using System.Linq; | ||
using API.Features.DeliveryChannels; | ||
using API.Tests.Integration.Infrastructure; | ||
using DLCS.Core.Caching; | ||
using DLCS.Model.DeliveryChannels; | ||
using DLCS.Model.Policies; | ||
using DLCS.Repository; | ||
using LazyCache.Mocks; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.Extensions.Options; | ||
using Test.Helpers.Integration; | ||
|
||
namespace API.Tests.Features.DeliveryChannels; | ||
|
||
[Trait("Category", "Database")] | ||
[Collection(CollectionDefinitions.DatabaseCollection.CollectionName)] | ||
public class DefaultDeliveryChannelRepositoryTests | ||
{ | ||
private readonly DlcsContext dbContext; | ||
private readonly DefaultDeliveryChannelRepository sut; | ||
|
||
public DefaultDeliveryChannelRepositoryTests(DlcsDatabaseFixture dbFixture) | ||
{ | ||
dbContext = dbFixture.DbContext; | ||
sut = new DefaultDeliveryChannelRepository(new MockCachingService(), new NullLogger<DefaultDeliveryChannelRepository>(), | ||
Options.Create(new CacheSettings()), dbFixture.DbContext); | ||
|
||
dbFixture.CleanUp(); | ||
|
||
var newPolicy = dbContext.DeliveryChannelPolicies.Add(new DeliveryChannelPolicy() | ||
{ | ||
Created = DateTime.UtcNow, | ||
Modified = DateTime.UtcNow, | ||
DisplayName = "test policy - space specific", | ||
PolicyData = null, | ||
Name = "space-specific-image", | ||
Channel = "iiif-img", | ||
Customer = 2, | ||
Id = 260 | ||
}); | ||
|
||
dbContext.DefaultDeliveryChannels.Add(new DefaultDeliveryChannel | ||
{ | ||
Space = 2, | ||
Customer = 2, | ||
DeliveryChannelPolicyId = newPolicy.Entity.Id, | ||
MediaType = "image/tiff" | ||
}); | ||
|
||
dbContext.DefaultDeliveryChannels.Add(new DefaultDeliveryChannel | ||
{ | ||
Space = 0, | ||
Customer = 2, | ||
DeliveryChannelPolicyId = 1, | ||
MediaType = "image/*" | ||
}); | ||
|
||
dbContext.SaveChanges(); | ||
} | ||
|
||
[Fact] | ||
public void MatchedDeliveryChannels_ReturnsAllDeliveryChannelPolicies_WhenCalled() | ||
{ | ||
// Arrange and Act | ||
var matches = sut.MatchedDeliveryChannels("image/tiff", 1, 2); | ||
|
||
// Assert | ||
matches.Count.Should().Be(1); | ||
matches.Count(x => x.Channel == "iiif-img").Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void MatchedDeliveryChannels_ShouldNotMatchAnything_WhenCalledWithInvalidMediaType() | ||
{ | ||
// Arrange and Act | ||
var matches = sut.MatchedDeliveryChannels("notValid/tiff", 1, 2); | ||
|
||
// Assert | ||
matches.Count.Should().Be(0); | ||
} | ||
|
||
[Fact] | ||
public void MatchDeliveryChannelPolicyForChannel_MatchesDeliveryChannel_WhenMatchAvailable() | ||
{ | ||
// Arrange and Act | ||
var matches = sut.MatchDeliveryChannelPolicyForChannel("image/tiff", 1, 2, "iiif-img"); | ||
|
||
// Assert | ||
matches.Should().NotBeNull(); | ||
} | ||
|
||
[Fact] | ||
public void MatchDeliveryChannelPolicyForChannel_ThrowsException_WhenNotMatched() | ||
{ | ||
// Arrange and Act | ||
Action action = () => sut.MatchDeliveryChannelPolicyForChannel("notMatched/tiff", 1, 2, "iiif-img"); | ||
|
||
// Assert | ||
action.Should().ThrowExactly<InvalidOperationException>(); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/protagonist/API.Tests/Features/DeliveryChannels/DeliveryChannelPoliciesTests.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,78 @@ | ||
using System; | ||
using API.Features.DeliveryChannels; | ||
using API.Tests.Integration.Infrastructure; | ||
using DLCS.Core.Caching; | ||
using DLCS.Model.Policies; | ||
using DLCS.Repository; | ||
using LazyCache.Mocks; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.Extensions.Options; | ||
using Test.Helpers.Integration; | ||
|
||
namespace API.Tests.Features.DeliveryChannels; | ||
|
||
[Trait("Category", "Database")] | ||
[Collection(CollectionDefinitions.DatabaseCollection.CollectionName)] | ||
public class DeliveryChannelPoliciesTests | ||
{ | ||
private readonly DlcsContext dbContext; | ||
private readonly DeliveryChannelPolicyRepository sut; | ||
|
||
public DeliveryChannelPoliciesTests(DlcsDatabaseFixture dbFixture) | ||
{ | ||
dbContext = dbFixture.DbContext; | ||
sut = new DeliveryChannelPolicyRepository(new MockCachingService() ,new NullLogger<DeliveryChannelPolicyRepository>(), Options.Create(new CacheSettings()), dbFixture.DbContext); | ||
|
||
dbFixture.CleanUp(); | ||
|
||
dbContext.DeliveryChannelPolicies.Add(new DeliveryChannelPolicy() | ||
{ | ||
Created = DateTime.UtcNow, | ||
Modified = DateTime.UtcNow, | ||
DisplayName = "test policy - space specific", | ||
PolicyData = null, | ||
Name = "space-specific-image", | ||
Channel = "iiif-img", | ||
Customer = 2, | ||
Id = 260 | ||
}); | ||
|
||
dbContext.SaveChanges(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("space-specific-image")] | ||
[InlineData("channel/space-specific-image")] | ||
[InlineData("https://dlcs.api/customers/2/deliveryChannelPolicies/iiif-img/space-specific-image")] | ||
public void RetrieveDeliveryChannelPolicy_RetrievesACustomerSpecificPolicy(string policy) | ||
{ | ||
// Arrange and Act | ||
var deliveryChannelPolicy = sut.RetrieveDeliveryChannelPolicy(2, "iiif-img", policy); | ||
|
||
// Assert | ||
deliveryChannelPolicy.Channel.Should().Be("iiif-img"); | ||
deliveryChannelPolicy.Customer.Should().Be(2); | ||
} | ||
|
||
[Fact] | ||
public void RetrieveDeliveryChannelPolicy_RetrievesADefaultPolicy() | ||
{ | ||
// Arrange and Act | ||
var policy = sut.RetrieveDeliveryChannelPolicy(2, "iiif-img", "default"); | ||
|
||
// Assert | ||
policy.Channel.Should().Be("iiif-img"); | ||
policy.Customer.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void RetrieveDeliveryChannelPolicy_RetrieveNonExistentPolicy() | ||
{ | ||
// Arrange and Act | ||
Action action = () => sut.RetrieveDeliveryChannelPolicy(2, "notAChannel", "notAPolicy"); | ||
|
||
// Assert | ||
action.Should() | ||
.Throw<InvalidOperationException>(); | ||
} | ||
} |
Oops, something went wrong.