diff --git a/sdk/Notifo.SDK.FirebasePlugin/PluginEventsProvider.cs b/sdk/Notifo.SDK.FirebasePlugin/PluginEventsProvider.cs index 828251a..49af8cd 100644 --- a/sdk/Notifo.SDK.FirebasePlugin/PluginEventsProvider.cs +++ b/sdk/Notifo.SDK.FirebasePlugin/PluginEventsProvider.cs @@ -25,6 +25,8 @@ public PluginEventsProvider() CrossFirebasePushNotification.Current.OnNotificationOpened += FirebasePushNotification_OnNotificationOpened; } + public string Token => CrossFirebasePushNotification.Current.Token; + private void FirebasePushNotification_OnTokenRefresh(object source, FirebasePushNotificationTokenEventArgs e) { var args = new TokenRefreshEventArgs(e.Token); diff --git a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.shared.cs b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.shared.cs index 779373a..87a9701 100644 --- a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.shared.cs +++ b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.shared.cs @@ -164,7 +164,12 @@ public void Register() bool notRefreshing = refreshExecutingCount == 0; if (notRefreshing) { - _ = EnsureTokenRefreshedAsync(settings.Token); + string token = + string.IsNullOrWhiteSpace(pushEventsProvider?.Token) + ? settings.Token + : pushEventsProvider.Token; + + _ = EnsureTokenRefreshedAsync(token); } } diff --git a/sdk/Notifo.SDK/PushEventProvider/IPushEventsProvider.cs b/sdk/Notifo.SDK/PushEventProvider/IPushEventsProvider.cs index 10448c2..2bd0577 100644 --- a/sdk/Notifo.SDK/PushEventProvider/IPushEventsProvider.cs +++ b/sdk/Notifo.SDK/PushEventProvider/IPushEventsProvider.cs @@ -28,5 +28,10 @@ public interface IPushEventsProvider /// Event triggered when a notification is opened. /// event EventHandler OnNotificationOpened; + + /// + /// Push notification token. + /// + public string Token { get; } } } diff --git a/tests/Notifo.SDK.UnitTests/Mocks/EventsProviderMock.cs b/tests/Notifo.SDK.UnitTests/Mocks/EventsProviderMock.cs index a370545..1796fb1 100644 --- a/tests/Notifo.SDK.UnitTests/Mocks/EventsProviderMock.cs +++ b/tests/Notifo.SDK.UnitTests/Mocks/EventsProviderMock.cs @@ -16,6 +16,7 @@ public class EventsProviderMock : IPushEventsProvider public event EventHandler OnTokenRefresh; public event EventHandler OnNotificationReceived; public event EventHandler OnNotificationOpened; + public string Token => "test token"; protected virtual void OnRefreshTokenEvent(TokenRefreshEventArgs args) => OnTokenRefresh?.Invoke(this, args); diff --git a/tests/Notifo.SDK.UnitTests/NotifoMobilePushTests.cs b/tests/Notifo.SDK.UnitTests/NotifoMobilePushTests.cs index 92d7949..49e5b83 100644 --- a/tests/Notifo.SDK.UnitTests/NotifoMobilePushTests.cs +++ b/tests/Notifo.SDK.UnitTests/NotifoMobilePushTests.cs @@ -398,8 +398,6 @@ public void Register_ShouldSetTokenRefreshedFalse_IfHttpServiceThrewException() [Fact] public void Register_ShouldNotRefreshToken_IfTokenIsEmpty() { - var eventsProvider = new EventsProviderMock(); - var handler = new Mock(); handler.SetupAnyRequest() .ReturnsResponse(HttpStatusCode.Unauthorized); @@ -408,8 +406,11 @@ public void Register_ShouldNotRefreshToken_IfTokenIsEmpty() var mocker = new AutoMocker(); mocker.Use(client); + mocker.Setup(x => x.Token).Returns(string.Empty); mocker.Setup(x => x.Token).Returns(string.Empty); + var eventsProvider = mocker.GetMock().Object; + var notifoMobilePush = mocker.CreateInstance(); notifoMobilePush .SetPushEventsProvider(eventsProvider)