65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
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();
|
|
CorrectMethodShouldGetCalled("pwg.session.login");
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetStatus_should_return_config()
|
|
{
|
|
await LoginAsync();
|
|
var serverResponse = new PiwigoResponse<SessionStatus>
|
|
{
|
|
Status = "OK",
|
|
Result = new SessionStatus
|
|
{
|
|
Username = "admin",
|
|
Version = "12.0.0"
|
|
}
|
|
};
|
|
SetJsonResult(serverResponse);
|
|
|
|
var status = await _sessionApi.GetStatusAsync();
|
|
|
|
status.Should().NotBeNull();
|
|
status.Username.Should().Be("admin");
|
|
CorrectMethodShouldGetCalled("pwg.session.getStatus");
|
|
}
|
|
|
|
[Test]
|
|
public async Task Logout_should_set_IsLoggedIn_to_false()
|
|
{
|
|
await LoginAsync();
|
|
|
|
SetOkResult();
|
|
|
|
await _sessionApi.LogoutAsync();
|
|
Context.IsLoggedIn.Should().BeFalse();
|
|
CorrectMethodShouldGetCalled("pwg.session.logout");
|
|
}
|
|
|
|
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();
|
|
}
|
|
} |