Пример #1
0
        public void OnNotificationReceived_ShouldSubscribeAndUnsubscribe_IfEventsProviderSupplied()
        {
            var eventsProvider = new EventsProviderMock();

            var handler = new Mock <HttpMessageHandler>();
            var client  = handler.CreateClient();

            var mocker = new AutoMocker();

            mocker.Use(client);

            var notifoMobilePush = mocker.CreateInstance <NotifoMobilePushImplementation>();

            notifoMobilePush.SetPushEventsProvider(eventsProvider);

            int invokeCount = 0;

            void EventHandler(object s, NotificationEventArgs e) => invokeCount += 1;

            notifoMobilePush.OnNotificationReceived += EventHandler;

            eventsProvider.RaiseOnNotificationReceivedEvent();
            invokeCount.Should().Be(1);

            notifoMobilePush.OnNotificationReceived -= EventHandler;

            eventsProvider.RaiseOnNotificationReceivedEvent();
            invokeCount.Should().Be(1);
        }
Пример #2
0
        public void SetEventsProvider_ShouldUnsubscribeCurrentProvider_IfNewProviderSupplied()
        {
            var eventsProviderA = new EventsProviderMock();
            var eventsProviderB = new EventsProviderMock();

            var handler = new Mock <HttpMessageHandler>();

            handler.SetupAnyRequest()
            .ReturnsResponse(HttpStatusCode.NoContent);

            var client = handler.CreateClient();

            var mocker = new AutoMocker();

            mocker.Use(client);

            var notifoMobilePush = mocker.CreateInstance <NotifoMobilePushImplementation>();

            notifoMobilePush
            .SetApiKey("test api key")
            .SetPushEventsProvider(eventsProviderA);

            int invokeOpenCount = 0;

            void EventOpenHandler(object s, NotificationEventArgs e) => invokeOpenCount += 1;

            int invokeReceivedCount = 0;

            void EventReceivedHandler(object s, NotificationEventArgs e) => invokeReceivedCount += 1;

            notifoMobilePush.OnNotificationOpened   += EventOpenHandler;
            notifoMobilePush.OnNotificationReceived += EventReceivedHandler;

            notifoMobilePush.SetPushEventsProvider(eventsProviderB);
            notifoMobilePush.OnNotificationOpened   += EventOpenHandler;
            notifoMobilePush.OnNotificationReceived += EventReceivedHandler;

            eventsProviderA.RaiseOnTokenRefreshEvent();
            eventsProviderB.RaiseOnTokenRefreshEvent();

            handler.VerifyAnyRequest(Times.Once());

            eventsProviderA.RaiseOnNotificationOpenedEvent();
            eventsProviderB.RaiseOnNotificationOpenedEvent();

            invokeOpenCount.Should().Be(1);

            eventsProviderA.RaiseOnNotificationReceivedEvent();
            eventsProviderB.RaiseOnNotificationReceivedEvent();

            invokeReceivedCount.Should().Be(1);
        }