2022-10-15 00:07:59 +02:00
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
using Piwigo.Client.Contract;
|
|
|
|
|
|
|
|
namespace Piwigo.Client.Tests;
|
|
|
|
|
|
|
|
[TestFixture]
|
2022-10-16 23:00:03 +02:00
|
|
|
public class AlbumApiTests : ApiTestsBase
|
2022-10-15 00:07:59 +02:00
|
|
|
{
|
2022-10-21 00:23:54 +02:00
|
|
|
private IAlbumApi _albumApi = null!;
|
2022-10-15 00:07:59 +02:00
|
|
|
|
|
|
|
protected override void OnSetUp()
|
|
|
|
{
|
|
|
|
base.OnSetUp();
|
2022-10-16 23:00:03 +02:00
|
|
|
_albumApi = new AlbumApi(Context, new NullLogger<AlbumApi>());
|
2022-10-15 00:07:59 +02:00
|
|
|
}
|
|
|
|
|
2022-10-17 00:16:30 +02:00
|
|
|
[Test]
|
2022-10-17 23:54:38 +02:00
|
|
|
public async Task DeleteRepresentative_should_call_api()
|
2022-10-17 00:16:30 +02:00
|
|
|
{
|
2022-10-17 23:54:38 +02:00
|
|
|
SetOkResult();
|
|
|
|
await _albumApi.DeleteRepresentativeAsync(1);
|
|
|
|
|
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.deleteRepresentative");
|
|
|
|
CorrectParamShouldGetSent("category_id", "1");
|
|
|
|
}
|
2022-10-17 00:16:30 +02:00
|
|
|
|
2022-10-17 23:54:38 +02:00
|
|
|
[Test]
|
|
|
|
public async Task RefreshRepresentative_should_call_api()
|
|
|
|
{
|
|
|
|
SetOkResult();
|
|
|
|
await _albumApi.RefreshRepresentativeAsync(1);
|
|
|
|
|
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.refreshRepresentative");
|
|
|
|
CorrectParamShouldGetSent("category_id", "1");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public async Task SetRepresentative_should_call_api()
|
|
|
|
{
|
|
|
|
SetOkResult();
|
|
|
|
await _albumApi.SetRepresentativeAsync(1, 2);
|
|
|
|
|
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.setRepresentative");
|
|
|
|
CorrectParamShouldGetSent("category_id", "1");
|
|
|
|
CorrectParamShouldGetSent("image_id", "2");
|
|
|
|
}
|
|
|
|
|
2022-10-17 23:56:45 +02:00
|
|
|
[Test]
|
|
|
|
public async Task SetRank_should_call_api()
|
|
|
|
{
|
|
|
|
SetOkResult();
|
|
|
|
await _albumApi.SetRankAsync(1, 2);
|
|
|
|
|
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.setRank");
|
|
|
|
CorrectParamShouldGetSent("category_id", "1");
|
|
|
|
CorrectParamShouldGetSent("rank", "2");
|
|
|
|
}
|
|
|
|
|
2022-10-17 23:54:38 +02:00
|
|
|
[Test]
|
|
|
|
public async Task Delete_should_remove_album()
|
|
|
|
{
|
|
|
|
SetOkResult();
|
2022-10-17 00:16:30 +02:00
|
|
|
await _albumApi.DeleteAsync(1, "apiToken");
|
2022-10-17 23:54:38 +02:00
|
|
|
|
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.delete");
|
|
|
|
CorrectParamShouldGetSent("category_id", "1");
|
2022-10-17 00:16:30 +02:00
|
|
|
}
|
|
|
|
|
2022-10-21 21:22:53 +02:00
|
|
|
[Test]
|
|
|
|
public async Task Move_should_reassign_album()
|
|
|
|
{
|
|
|
|
SetOkResult();
|
|
|
|
await _albumApi.MoveAsync(1, 2, "apiToken");
|
|
|
|
|
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.move");
|
|
|
|
CorrectParamShouldGetSent("category_id", "1");
|
|
|
|
CorrectParamShouldGetSent("parent", "2");
|
|
|
|
CorrectParamShouldGetSent("pwg_token", "apiToken");
|
|
|
|
}
|
|
|
|
|
2022-10-21 21:29:08 +02:00
|
|
|
[Test]
|
|
|
|
public async Task SetInfoAsync_should_pass_all_infos_to_piwigo()
|
|
|
|
{
|
|
|
|
SetOkResult();
|
|
|
|
await _albumApi.SetInfoAsync(1, "albumName", "comment", AlbumStatus.Public);
|
|
|
|
|
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.setInfo");
|
|
|
|
CorrectParamShouldGetSent("category_id", "1");
|
|
|
|
CorrectParamShouldGetSent("name", "albumName");
|
|
|
|
CorrectParamShouldGetSent("comment", "comment");
|
|
|
|
CorrectParamShouldGetSent("status", "public");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 00:07:59 +02:00
|
|
|
[Test]
|
2022-10-16 23:53:17 +02:00
|
|
|
public async Task CalculateOrphansAsync_should_return_correct_values()
|
2022-10-15 00:07:59 +02:00
|
|
|
{
|
2022-10-16 23:53:17 +02:00
|
|
|
SetJsonResult(@"{
|
2022-10-17 00:16:30 +02:00
|
|
|
stat: ""ok"",
|
|
|
|
result: [ {
|
|
|
|
nb_images_associated_outside: 1,
|
|
|
|
nb_images_becoming_orphan: 2,
|
|
|
|
nb_images_recursive: 3
|
2022-10-16 23:53:17 +02:00
|
|
|
} ]
|
|
|
|
}");
|
|
|
|
var response = await _albumApi.CalculateOrphansAsync(1);
|
|
|
|
|
2022-10-17 23:54:38 +02:00
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.calculateOrphans");
|
|
|
|
CorrectParamShouldGetSent("category_id", "1");
|
|
|
|
|
2022-10-16 23:53:17 +02:00
|
|
|
response.Should().NotBeNull();
|
|
|
|
response.AssociatedOutsideCount.Should().Be(1);
|
|
|
|
response.BecomingOrphanCount.Should().Be(2);
|
|
|
|
response.RecursiveImageCount.Should().Be(3);
|
|
|
|
}
|
2022-10-15 00:07:59 +02:00
|
|
|
|
2022-10-16 23:53:17 +02:00
|
|
|
[Test]
|
|
|
|
public async Task Add_should_create_album_and_return_id()
|
|
|
|
{
|
2022-10-16 23:00:03 +02:00
|
|
|
var serverResponse = new PiwigoResponse<AlbumAdded>
|
|
|
|
{
|
2022-10-17 00:16:30 +02:00
|
|
|
Status = "ok",
|
2022-10-16 23:00:03 +02:00
|
|
|
Result = new AlbumAdded
|
|
|
|
{
|
|
|
|
Id = 1, Info = "Album added"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SetJsonResult(serverResponse);
|
2022-10-21 21:29:08 +02:00
|
|
|
var response = await _albumApi.AddAsync("UnittestMain2", null, "comment", true, AlbumStatus.Public, true, AlbumPosition.Last);
|
2022-10-16 23:00:03 +02:00
|
|
|
|
2022-10-17 23:54:38 +02:00
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.add");
|
|
|
|
CorrectParamShouldGetSent("name", "UnittestMain2");
|
|
|
|
|
2022-10-16 23:00:03 +02:00
|
|
|
response.Should().BeGreaterOrEqualTo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-10-21 21:45:08 +02:00
|
|
|
public async Task GetList_should_return_all_existing_albums()
|
2022-10-16 23:00:03 +02:00
|
|
|
{
|
2022-10-21 21:45:08 +02:00
|
|
|
await SetJsonResultFromFileAsync("AlbumApi.getList.json");
|
|
|
|
|
|
|
|
var response = await _albumApi.GetListAsync(1, true, false, ThumbnailSize.Small);
|
2022-10-15 00:07:59 +02:00
|
|
|
|
2022-10-17 23:54:38 +02:00
|
|
|
CorrectMethodShouldGetCalled("pwg.categories.getList");
|
2022-10-21 21:45:08 +02:00
|
|
|
CorrectParamShouldGetSent("cat_id", "1");
|
|
|
|
CorrectParamShouldGetSent("recursive", "true");
|
|
|
|
CorrectParamShouldGetSent("fullname", "false");
|
|
|
|
CorrectParamShouldGetSent("thumbnail_size", "small");
|
2022-10-17 23:54:38 +02:00
|
|
|
|
2022-10-21 21:20:21 +02:00
|
|
|
await Verify(response);
|
2022-10-15 00:07:59 +02:00
|
|
|
}
|
|
|
|
}
|