2022-10-22 20:24:12 +02:00
|
|
|
using System.Text;
|
2022-10-21 00:23:54 +02:00
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
using Piwigo.Client.Contract;
|
|
|
|
|
|
|
|
namespace Piwigo.Client.Tests;
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
public class ImageApiTests : ApiTestsBase
|
|
|
|
{
|
|
|
|
private IImageApi _imageApi = null!;
|
|
|
|
|
|
|
|
protected override void OnSetUp()
|
|
|
|
{
|
|
|
|
base.OnSetUp();
|
|
|
|
_imageApi = new ImageApi(Context, new NullLogger<ImageApi>());
|
|
|
|
}
|
|
|
|
|
2022-10-22 20:24:12 +02:00
|
|
|
[Test]
|
|
|
|
public async Task AddChunk_should_post_base64_encoded_data()
|
|
|
|
{
|
|
|
|
SetOkResult();
|
|
|
|
|
|
|
|
var bytes = Encoding.UTF8.GetBytes("PiwigoTestString");
|
|
|
|
var expectedBase64 = Convert.ToBase64String(bytes);
|
|
|
|
|
|
|
|
await _imageApi.AddChunkAsync(bytes, "origSum", 0);
|
|
|
|
|
|
|
|
CorrectMethodShouldGetCalled("pwg.images.addChunk");
|
|
|
|
|
|
|
|
CorrectParamShouldGetSent("data", expectedBase64);
|
|
|
|
CorrectParamShouldGetSent("original_sum", "origSum");
|
|
|
|
CorrectParamShouldGetSent("type", "file");
|
|
|
|
CorrectParamShouldGetSent("position", "0");
|
|
|
|
}
|
|
|
|
|
2022-10-21 00:23:54 +02:00
|
|
|
[Test]
|
|
|
|
public async Task GetImages_should_return_expected_images()
|
|
|
|
{
|
|
|
|
await SetJsonResultFromFileAsync("ImageApi.getImages.json");
|
|
|
|
|
|
|
|
var result = await _imageApi.GetImages(7, true, new PagingInfo(0, 100, 0), ImageFilter.Empty);
|
|
|
|
|
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.getImages");
|
|
|
|
CorrectParamShouldGetSent("cat_id", "7");
|
|
|
|
CorrectParamShouldGetSent("recursive", "true");
|
|
|
|
CorrectParamShouldGetSent("per_page", "100");
|
|
|
|
CorrectParamShouldGetSent("page", "0");
|
|
|
|
|
2022-10-21 21:20:21 +02:00
|
|
|
await Verify(result);
|
2022-10-21 00:23:54 +02:00
|
|
|
}
|
|
|
|
}
|