Skip to content

Commit

Permalink
#1833 add happyflow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Jan 23, 2025
1 parent 20ff308 commit 24e4dd8
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,61 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using starsky.foundation.platform.Models;
using starsky.foundation.storage.Helpers;
using starsky.foundation.storage.Services;
using starsky.foundation.storage.Storage;
using starsky.foundation.video.GetDependencies;
using starsky.foundation.writemeta.Helpers;
using starsky.foundation.writemeta.Services;
using starskytest.FakeCreateAn;
using starskytest.FakeCreateAn.CreateFakeExifToolWindows;
using starskytest.FakeMocks;

namespace starskytest.starsky.foundation.writemeta.Helpers;

[TestClass]
public sealed class ExifToolTest
{
private readonly AppSettings _appSettingsWithExifTool;
private readonly StorageHostFullPathFilesystem _hostFullPathFilesystem;

public ExifToolTest()
{
_hostFullPathFilesystem = new StorageHostFullPathFilesystem(new FakeIWebLogger());
var exifToolExeWindows = new CreateFakeExifToolWindows().ExifToolPath;
_hostFullPathFilesystem.CreateDirectory(Path.Combine(new CreateAnImage().BasePath,
"ExifToolTest"));
var exifToolExePosix = Path.Combine(new CreateAnImage().BasePath,
"ExifToolTest", "exiftool");

CreateStubFile(exifToolExePosix,
"#!/bin/bash\necho Fake Executable");

new FfMpegChmod(new FakeSelectorStorage(_hostFullPathFilesystem),
new FakeIWebLogger())
.Chmod(exifToolExePosix).ConfigureAwait(false);

var exifToolExe = new AppSettings().IsWindows ? exifToolExeWindows : exifToolExePosix;
_appSettingsWithExifTool = new AppSettings { ExifToolPath = exifToolExe };
}

[ClassCleanup]
public static void CleanUp()
{
var folder = Path.Combine(new CreateAnImage().BasePath,
"ExifToolTest");
if ( Directory.Exists(folder) )
{
Directory.Delete(folder, true);
}
}

private void CreateStubFile(string path, string content)
{
var stream = StringToStreamHelper.StringToStream(content);
_hostFullPathFilesystem.WriteStream(stream, path);
}

[TestMethod]
public async Task ExifTool_ArgumentException()
{
Expand Down Expand Up @@ -121,4 +166,29 @@ public async Task WriteTagsAndRenameThumbnailAsync_Disposed()

Assert.AreEqual(1, storage.ExceptionCount);
}

[TestMethod]
public async Task ExifTool_WriteTagsAsync_HappyFlow()
{
var storage = new FakeIStorage(["/"],
["/test.jpg"],
new List<byte[]> { CreateAnImage.Bytes.ToArray() });

var (beforeHash, _) =
await new FileHash(storage, new FakeIWebLogger()).GetHashCodeAsync("/test.jpg");

var sut = new ExifTool(storage, storage,
_appSettingsWithExifTool, new FakeIWebLogger());

// Act
var result = await sut.WriteTagsAsync("/test.jpg", "-Software=\"Qdraw 2.0\"");

// Assert
var (afterHash, _) =
await new FileHash(storage, new FakeIWebLogger()).GetHashCodeAsync("/test.jpg");

Assert.IsTrue(result);
// Does change after update
Assert.AreNotEqual(beforeHash, afterHash);
}
}

0 comments on commit 24e4dd8

Please sign in to comment.