From 23fc948424ef1763392b168d631cff06fc1431d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Mon, 17 Oct 2022 23:54:38 +0200 Subject: [PATCH] adds methods to set, delete and refresh representative image of an album --- .../Piwigo.Client.Tests/AlbumApiTests.cs | 46 ++++++++++++++++++- PiwigoDotnet/Piwigo.Client/AlbumApi.cs | 12 +++++ PiwigoDotnet/Piwigo.Client/IAlbumApi.cs | 4 ++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.cs b/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.cs index f5e5de5..a897527 100644 --- a/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.cs +++ b/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.cs @@ -14,12 +14,46 @@ public class AlbumApiTests : ApiTestsBase _albumApi = new AlbumApi(Context, new NullLogger()); } + [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 => { diff --git a/PiwigoDotnet/Piwigo.Client/AlbumApi.cs b/PiwigoDotnet/Piwigo.Client/AlbumApi.cs index 6443a95..059b8f4 100644 --- a/PiwigoDotnet/Piwigo.Client/AlbumApi.cs +++ b/PiwigoDotnet/Piwigo.Client/AlbumApi.cs @@ -21,6 +21,18 @@ public class AlbumApi : IAlbumApi await _context.PostAsync(_logger, "pwg.categories.deleteRepresentative", formParams, cancellationToken); } + public async Task RefreshRepresentativeAsync(int albumId, CancellationToken cancellationToken = default) + { + var formParams = new Dictionary { { "category_id", albumId.ToString() } }; + await _context.PostAsync(_logger, "pwg.categories.refreshRepresentative", formParams, cancellationToken); + } + + public async Task SetRepresentativeAsync(int albumId, int imageId, CancellationToken cancellationToken = default) + { + var formParams = new Dictionary { { "category_id", albumId.ToString() }, { "image_id", imageId.ToString() } }; + await _context.PostAsync(_logger, "pwg.categories.setRepresentative", formParams, cancellationToken); + } + public async Task CalculateOrphansAsync(int albumId, CancellationToken cancellationToken = default) { var formParams = new Dictionary { { "category_id", albumId.ToString() } }; diff --git a/PiwigoDotnet/Piwigo.Client/IAlbumApi.cs b/PiwigoDotnet/Piwigo.Client/IAlbumApi.cs index 19a06dc..e392ba8 100644 --- a/PiwigoDotnet/Piwigo.Client/IAlbumApi.cs +++ b/PiwigoDotnet/Piwigo.Client/IAlbumApi.cs @@ -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 AddAsync(string name, int? parentId = null, string? comment = null, bool? visible = null, CategoryStatus? status = null, bool? commentable = null, CategoryPosition? position = null, CancellationToken cancellationToken = default);