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-16 23:00:03 +02:00
|
|
|
private AlbumApi _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
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-10-16 23:00:03 +02:00
|
|
|
public async Task Add_should_create_album_and_return_id()
|
2022-10-15 00:07:59 +02:00
|
|
|
{
|
|
|
|
await LoginAsync();
|
|
|
|
|
2022-10-16 23:00:03 +02:00
|
|
|
var serverResponse = new PiwigoResponse<AlbumAdded>
|
|
|
|
{
|
|
|
|
Result = new AlbumAdded
|
|
|
|
{
|
|
|
|
Id = 1, Info = "Album added"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SetJsonResult(serverResponse);
|
|
|
|
var response = await _albumApi.AddAsync("UnittestMain2", null, "comment", true, CategoryStatus.Public, true, CategoryPosition.Last);
|
|
|
|
|
|
|
|
response.Should().BeGreaterOrEqualTo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public async Task GetAll_should_return_all_existing_albums()
|
|
|
|
{
|
|
|
|
await LoginAsync();
|
2022-10-15 00:07:59 +02:00
|
|
|
|
2022-10-16 23:00:03 +02:00
|
|
|
var serverResponse = new PiwigoResponse<AlbumList>
|
2022-10-15 00:07:59 +02:00
|
|
|
{
|
2022-10-16 23:00:03 +02:00
|
|
|
Result = new AlbumList
|
2022-10-15 00:07:59 +02:00
|
|
|
{
|
2022-10-16 23:00:03 +02:00
|
|
|
Albums = new List<Album>
|
2022-10-15 00:07:59 +02:00
|
|
|
{
|
|
|
|
new() { Id = 1, Name = "UnitTestMain" },
|
|
|
|
new() { Id = 3, Name = "UnitTestSub2", IdUpperCat = 1 },
|
|
|
|
new() { Id = 2, Name = "UnitTestSub1", IdUpperCat = 1 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
SetJsonResult(serverResponse);
|
2022-10-16 23:00:03 +02:00
|
|
|
var response = await _albumApi.GetAllAsync();
|
2022-10-15 00:07:59 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|