2022-10-15 00:07:59 +02:00
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
using Piwigo.Client.Contract;
|
|
|
|
|
|
|
|
namespace Piwigo.Client.Tests;
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
public class SessionApiTests : ApiTestsBase
|
|
|
|
{
|
|
|
|
private SessionApi _sessionApi = null!;
|
|
|
|
|
|
|
|
protected override void OnSetUp()
|
|
|
|
{
|
|
|
|
base.OnSetUp();
|
|
|
|
_sessionApi = new SessionApi(Context, new NullLogger<SessionApi>());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public async Task Login_should_set_cookies_and_session()
|
|
|
|
{
|
|
|
|
await LoginAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public async Task GetStatus_should_return_config()
|
|
|
|
{
|
|
|
|
await LoginAsync();
|
|
|
|
var serverResponse = new PiwigoResponse<PiwigoStatus>
|
|
|
|
{
|
|
|
|
Status = "OK",
|
|
|
|
Result = new PiwigoStatus
|
|
|
|
{
|
|
|
|
Username = "admin",
|
|
|
|
Version = "12.0.0"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
SetJsonResult(serverResponse);
|
|
|
|
|
|
|
|
var status = await _sessionApi.GetStatusAsync();
|
|
|
|
|
|
|
|
status.Should().NotBeNull();
|
|
|
|
status.Username.Should().Be("admin");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public async Task Logout_should_set_IsLoggedIn_to_false()
|
|
|
|
{
|
|
|
|
await LoginAsync();
|
|
|
|
|
2022-10-16 23:53:17 +02:00
|
|
|
SetOkResult();
|
2022-10-15 00:07:59 +02:00
|
|
|
|
|
|
|
await _sessionApi.LogoutAsync();
|
|
|
|
Context.IsLoggedIn.Should().BeFalse();
|
|
|
|
}
|
2022-10-16 23:53:17 +02:00
|
|
|
|
|
|
|
private async Task LoginAsync()
|
|
|
|
{
|
|
|
|
HttpTest?.RespondWith("{}", 200, cookies: new { pwg_id = "pwg_id" });
|
|
|
|
var sessionApi = new SessionApi(Context, new NullLogger<SessionApi>());
|
|
|
|
await sessionApi.LoginAsync();
|
|
|
|
Context.IsLoggedIn.Should().BeTrue();
|
|
|
|
}
|
2022-10-15 00:07:59 +02:00
|
|
|
}
|