adds methods to set, delete and refresh representative image of an album
This commit is contained in:
parent
f862a9794f
commit
23fc948424
@ -14,12 +14,46 @@ public class AlbumApiTests : ApiTestsBase
|
||||
_albumApi = new AlbumApi(Context, new NullLogger<AlbumApi>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteRepresentative_should_call_api()
|
||||
{
|
||||
SetOkResult();
|
||||
await _albumApi.DeleteRepresentativeAsync(1);
|
||||
|
||||
CorrectMethodShouldGetCalled("pwg.categories.deleteRepresentative");
|
||||
CorrectParamShouldGetSent("category_id", "1");
|
||||
}
|
||||
|
||||
|
||||
[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");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Delete_should_remove_album()
|
||||
{
|
||||
SetJsonResult(@"{stat: ""ok"", result: null }");
|
||||
|
||||
SetOkResult();
|
||||
await _albumApi.DeleteAsync(1, "apiToken");
|
||||
|
||||
CorrectMethodShouldGetCalled("pwg.categories.delete");
|
||||
CorrectParamShouldGetSent("category_id", "1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -35,6 +69,9 @@ public class AlbumApiTests : ApiTestsBase
|
||||
}");
|
||||
var response = await _albumApi.CalculateOrphansAsync(1);
|
||||
|
||||
CorrectMethodShouldGetCalled("pwg.categories.calculateOrphans");
|
||||
CorrectParamShouldGetSent("category_id", "1");
|
||||
|
||||
response.Should().NotBeNull();
|
||||
response.AssociatedOutsideCount.Should().Be(1);
|
||||
response.BecomingOrphanCount.Should().Be(2);
|
||||
@ -56,6 +93,9 @@ public class AlbumApiTests : ApiTestsBase
|
||||
SetJsonResult(serverResponse);
|
||||
var response = await _albumApi.AddAsync("UnittestMain2", null, "comment", true, CategoryStatus.Public, true, CategoryPosition.Last);
|
||||
|
||||
CorrectMethodShouldGetCalled("pwg.categories.add");
|
||||
CorrectParamShouldGetSent("name", "UnittestMain2");
|
||||
|
||||
response.Should().BeGreaterOrEqualTo(1);
|
||||
}
|
||||
|
||||
@ -78,6 +118,8 @@ public class AlbumApiTests : ApiTestsBase
|
||||
SetJsonResult(serverResponse);
|
||||
var response = await _albumApi.GetAllAsync();
|
||||
|
||||
CorrectMethodShouldGetCalled("pwg.categories.getList");
|
||||
|
||||
response.Should().HaveCount(3);
|
||||
response.Should().SatisfyRespectively(c =>
|
||||
{
|
||||
|
@ -21,6 +21,18 @@ public class AlbumApi : IAlbumApi
|
||||
await _context.PostAsync<PiwigoResponse>(_logger, "pwg.categories.deleteRepresentative", formParams, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task RefreshRepresentativeAsync(int albumId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var formParams = new Dictionary<string, string> { { "category_id", albumId.ToString() } };
|
||||
await _context.PostAsync<PiwigoResponse>(_logger, "pwg.categories.refreshRepresentative", formParams, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task SetRepresentativeAsync(int albumId, int imageId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var formParams = new Dictionary<string, string> { { "category_id", albumId.ToString() }, { "image_id", imageId.ToString() } };
|
||||
await _context.PostAsync<PiwigoResponse>(_logger, "pwg.categories.setRepresentative", formParams, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<AlbumOrphans> CalculateOrphansAsync(int albumId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var formParams = new Dictionary<string, string> { { "category_id", albumId.ToString() } };
|
||||
|
@ -10,6 +10,10 @@ public interface IAlbumApi
|
||||
|
||||
Task DeleteRepresentativeAsync(int albumId, CancellationToken cancellationToken = default);
|
||||
|
||||
Task RefreshRepresentativeAsync(int albumId, CancellationToken cancellationToken = default);
|
||||
|
||||
Task SetRepresentativeAsync(int albumId, int imageId, CancellationToken cancellationToken = default);
|
||||
|
||||
Task<int> AddAsync(string name, int? parentId = null, string? comment = null, bool? visible = null, CategoryStatus? status = null, bool? commentable = null,
|
||||
CategoryPosition? position = null, CancellationToken cancellationToken = default);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user