Skip to content

Commit

Permalink
#1833 mock implementation and test
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Jan 20, 2025
1 parent 7f2ce7c commit 8edc884
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions starsky/starskytest/FakeMocks/FakeIFileHashSubPathStorage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using starsky.foundation.storage.Interfaces;

namespace starskytest.FakeMocks;

public class FakeIFileHashSubPathStorage(List<(string, string, bool)> storage)
: IFileHashSubPathStorage
{
/// <summary>
/// 1. FullFileName
/// 2. FileHash
/// 3. IsSuccess
/// </summary>
private readonly List<(string, string, bool)> _storage = storage;

public Task<KeyValuePair<string, bool>> GetHashCodeAsync(string fullFileName, int timeoutInMilliseconds = 30000)
{
var result = _storage.FirstOrDefault(p => p.Item1 == fullFileName);
return Task.FromResult(new KeyValuePair<string, bool>(result.Item2, result.Item3));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,25 @@ public async Task NotFound2()
Assert.IsFalse(resultModels.Success);
}

[TestMethod]
public async Task GenerateThumbnail_NotFound()
{
var storage = new FakeSelectorStorage(new FakeIStorage([],
["/not-found.jpg"], [[.. CreateAnImage.Bytes]]));

var hashService = new FakeIFileHashSubPathStorage([( "/test.jpg", "hash", false )]);
var sut = new ThumbnailService(storage,
new FakeIWebLogger(), new AppSettings(),
new UpdateStatusGeneratedThumbnailService(new FakeIThumbnailQuery()),
new FakeIVideoProcess(), hashService);

var (stream, resultModels) = await sut.GenerateThumbnail("/test.jpg",
"hash", ThumbnailImageFormat.jpg, ThumbnailSize.Large);

Assert.IsNull(stream);
Assert.IsFalse(resultModels.Success);
}

[TestMethod]
public async Task NotFoundNonExistingHash()
{
Expand Down

0 comments on commit 8edc884

Please sign in to comment.