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()); } [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 { 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"); } [Test] public async Task Logout_should_set_IsLoggedIn_to_false() { await LoginAsync(); SetOkResult(); await _sessionApi.LogoutAsync(); Context.IsLoggedIn.Should().BeFalse(); } private async Task LoginAsync() { HttpTest?.RespondWith("{}", 200, cookies: new { pwg_id = "pwg_id" }); var sessionApi = new SessionApi(Context, new NullLogger()); await sessionApi.LoginAsync(); Context.IsLoggedIn.Should().BeTrue(); } }