diff --git a/starsky/starskytest/FakeMocks/FakeIFileHashSubPathStorage.cs b/starsky/starskytest/FakeMocks/FakeIFileHashSubPathStorage.cs new file mode 100644 index 000000000..6552fbd12 --- /dev/null +++ b/starsky/starskytest/FakeMocks/FakeIFileHashSubPathStorage.cs @@ -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 +{ + /// + /// 1. FullFileName + /// 2. FileHash + /// 3. IsSuccess + /// + private readonly List<(string, string, bool)> _storage = storage; + + public Task> GetHashCodeAsync(string fullFileName, int timeoutInMilliseconds = 30000) + { + var result = _storage.FirstOrDefault(p => p.Item1 == fullFileName); + return Task.FromResult(new KeyValuePair(result.Item2, result.Item3)); + } +} diff --git a/starsky/starskytest/starsky.foundation.thumbnailgeneration/GenerationFactory/ThumbnailServiceTests.cs b/starsky/starskytest/starsky.foundation.thumbnailgeneration/GenerationFactory/ThumbnailServiceTests.cs index 080bfbc88..10a7f1d79 100644 --- a/starsky/starskytest/starsky.foundation.thumbnailgeneration/GenerationFactory/ThumbnailServiceTests.cs +++ b/starsky/starskytest/starsky.foundation.thumbnailgeneration/GenerationFactory/ThumbnailServiceTests.cs @@ -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() {