From 9d37d5d93add965f32e0751273ef022fff091057 Mon Sep 17 00:00:00 2001 From: Miguel Serra Date: Mon, 13 Nov 2023 11:33:44 +0000 Subject: [PATCH] Issue #54 - Event on session refresh is called several times in the page Add new RefreshEnded SessionStateKind to propagate after Session.Refresh --- .../SessionManagement/SessionServiceTestFixture.cs | 13 ++++++++++++- COMET.Web.Common/Enumerations/SessionStateKind.cs | 7 ++++++- .../Services/SessionManagement/SessionService.cs | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/COMET.Web.Common.Tests/Services/SessionManagement/SessionServiceTestFixture.cs b/COMET.Web.Common.Tests/Services/SessionManagement/SessionServiceTestFixture.cs index 6ad7cdca..5820d5f1 100644 --- a/COMET.Web.Common.Tests/Services/SessionManagement/SessionServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/Services/SessionManagement/SessionServiceTestFixture.cs @@ -36,7 +36,6 @@ namespace COMET.Web.Common.Tests.Services.SessionManagement using COMET.Web.Common.Enumerations; using COMET.Web.Common.Services.SessionManagement; - using Moq; using NUnit.Framework; @@ -305,5 +304,17 @@ public void VerifyDeleteThings() Assert.DoesNotThrow(() => this.sessionService.DeleteThing(this.iteration, element.Clone(false))); } + + [Test] + public void VerifyRefreshEndedCalled() + { + var onSessionRefreshedCalled = false; + void SetRefreshEndedCalled() { onSessionRefreshedCalled = true; } + CDPMessageBus.Current.Listen().Where(x => x == SessionStateKind.RefreshEnded) + .Subscribe(_ => { SetRefreshEndedCalled(); }); + this.sessionService.RefreshSession(); + + Assert.That(onSessionRefreshedCalled, Is.True); + } } } diff --git a/COMET.Web.Common/Enumerations/SessionStateKind.cs b/COMET.Web.Common/Enumerations/SessionStateKind.cs index 7e0bac1e..7a1bf055 100644 --- a/COMET.Web.Common/Enumerations/SessionStateKind.cs +++ b/COMET.Web.Common/Enumerations/SessionStateKind.cs @@ -43,6 +43,11 @@ public enum SessionStateKind /// /// When refresh is in progress /// - Refreshing + Refreshing, + + /// + /// When refresh is finished + /// + RefreshEnded } } diff --git a/COMET.Web.Common/Services/SessionManagement/SessionService.cs b/COMET.Web.Common/Services/SessionManagement/SessionService.cs index 34b7a22a..3a18ff1c 100644 --- a/COMET.Web.Common/Services/SessionManagement/SessionService.cs +++ b/COMET.Web.Common/Services/SessionManagement/SessionService.cs @@ -200,6 +200,8 @@ public async Task RefreshSession() await this.Session.Refresh(); + CDPMessageBus.Current.SendMessage(SessionStateKind.RefreshEnded); + Console.WriteLine($"Session refreshed in {sw.ElapsedMilliseconds} [ms]"); }