-
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 #836 from dlcs/feature/escapeNamedQuery
Allow escaped forward slashes to be used in named query requests
- Loading branch information
Showing
8 changed files
with
371 additions
and
163 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
41 changes: 41 additions & 0 deletions
41
src/protagonist/Orchestrator.Tests/Integration/Infrastructure/FakePdfCreator.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,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using DLCS.Model.Assets; | ||
using DLCS.Model.Assets.NamedQueries; | ||
using DLCS.Repository.NamedQueries.Models; | ||
using Orchestrator.Infrastructure.NamedQueries.Persistence; | ||
|
||
namespace Orchestrator.Tests.Integration.Infrastructure; | ||
|
||
/// <summary> | ||
/// Fake projection creator that handles configured callbacks for when ParsedNamedQuery is persisted. | ||
/// Also optional callback for when ControlFile is created during persistence. | ||
/// </summary> | ||
public class FakePdfCreator : IProjectionCreator<PdfParsedNamedQuery> | ||
{ | ||
private static readonly Dictionary<string, Func<ParsedNamedQuery, List<Asset>, bool>> Callbacks = new(); | ||
|
||
private static readonly Dictionary<string, Func<ControlFile, ControlFile>> ControlFileCallbacks = new(); | ||
|
||
public void AddCallbackFor(string pdfKey, Func<ParsedNamedQuery, List<Asset>, bool> callback) | ||
=> Callbacks.Add(pdfKey, callback); | ||
|
||
public void AddCallbackFor(string pdfKey, Func<ControlFile, ControlFile> callback) | ||
=> ControlFileCallbacks.Add(pdfKey, callback); | ||
|
||
public Task<(bool success, ControlFile controlFile)> PersistProjection(PdfParsedNamedQuery parsedNamedQuery, | ||
List<Asset> images, CancellationToken cancellationToken = default) | ||
{ | ||
if (Callbacks.TryGetValue(parsedNamedQuery.StorageKey, out var cb)) | ||
{ | ||
var controlFileCallback = ControlFileCallbacks.TryGetValue(parsedNamedQuery.StorageKey, out var cfcb) | ||
? cfcb | ||
: file => file; | ||
|
||
return Task.FromResult((cb(parsedNamedQuery, images), controlFileCallback(new ControlFile()))); | ||
} | ||
|
||
throw new Exception($"Request with key {parsedNamedQuery.StorageKey} not setup"); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/protagonist/Orchestrator.Tests/Integration/Infrastructure/FakeZipCreator.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,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using DLCS.Model.Assets; | ||
using DLCS.Model.Assets.NamedQueries; | ||
using DLCS.Repository.NamedQueries.Models; | ||
using Orchestrator.Infrastructure.NamedQueries.Persistence; | ||
|
||
namespace Orchestrator.Tests.Integration.Infrastructure; | ||
|
||
public class FakeZipCreator : IProjectionCreator<ZipParsedNamedQuery> | ||
{ | ||
private static readonly Dictionary<string, Func<ParsedNamedQuery, List<Asset>, bool>> callbacks = new(); | ||
|
||
/// <summary> | ||
/// Add a callback for when zip is to be created and persisted to S3, allows control of success/failure for | ||
/// testing | ||
/// </summary> | ||
public void AddCallbackFor(string s3Key, Func<ParsedNamedQuery, List<Asset>, bool> callback) | ||
=> callbacks.Add(s3Key, callback); | ||
|
||
public Task<(bool success, ControlFile controlFile)> PersistProjection(ZipParsedNamedQuery parsedNamedQuery, List<Asset> images, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
if (callbacks.TryGetValue(parsedNamedQuery.StorageKey, out var cb)) | ||
{ | ||
return Task.FromResult((cb(parsedNamedQuery, images), new ControlFile())); | ||
} | ||
|
||
throw new Exception($"Request with key {parsedNamedQuery.StorageKey} not setup"); | ||
} | ||
} |
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.