using Microsoft.Extensions.Logging.Abstractions; using Piwigo.Client.Contract; namespace Piwigo.Client.Tests; [TestFixture] public class AlbumApiTests : ApiTestsBase { private AlbumApi _albumApi = null!; protected override void OnSetUp() { base.OnSetUp(); _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() { SetOkResult(); await _albumApi.DeleteAsync(1, "apiToken"); CorrectMethodShouldGetCalled("pwg.categories.delete"); CorrectParamShouldGetSent("category_id", "1"); } [Test] public async Task CalculateOrphansAsync_should_return_correct_values() { SetJsonResult(@"{ stat: ""ok"", result: [ { nb_images_associated_outside: 1, nb_images_becoming_orphan: 2, nb_images_recursive: 3 } ] }"); 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); response.RecursiveImageCount.Should().Be(3); } [Test] public async Task Add_should_create_album_and_return_id() { var serverResponse = new PiwigoResponse { Status = "ok", Result = new AlbumAdded { Id = 1, Info = "Album added" } }; 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); } [Test] public async Task GetAll_should_return_all_existing_albums() { var serverResponse = new PiwigoResponse { Status = "ok", Result = new AlbumList { Albums = new List { new() { Id = 1, Name = "UnitTestMain" }, new() { Id = 3, Name = "UnitTestSub2", IdUpperCat = 1 }, new() { Id = 2, Name = "UnitTestSub1", IdUpperCat = 1 } } } }; SetJsonResult(serverResponse); var response = await _albumApi.GetAllAsync(); CorrectMethodShouldGetCalled("pwg.categories.getList"); response.Should().HaveCount(3); response.Should().SatisfyRespectively(c => { c.Id.Should().Be(1); c.Name.Should().Be("UnitTestMain"); }, c => { c.Id.Should().Be(3); c.Name.Should().Be("UnitTestSub2"); c.IdUpperCat.Should().Be(1); }, c => { c.Id.Should().Be(2); c.Name.Should().Be("UnitTestSub1"); c.IdUpperCat.Should().Be(1); }); } }