public async Task IF_location_returned_is_invalid_SHOULD_error()
            {
                //Arrange
                var result1 = new TaskCompletionSource <IGpsLocation>();
                var result2 = new TaskCompletionSource <Exception>();

                //Act
                var disposable = Sut.Connect(_requirements)
                                 .Subscribe(next =>
                {
                    result1.SetResult(next);
                }, ex =>
                {
                    result2.SetResult(ex);
                });

                //Assert
                MockProxy.Where_GetCurrentLocationAsync_returns(new Location(0, 2));
                _testScheduler.AdvanceBy(1000);
                var first = await result1.Task;

                Assert.That(first.Latitude, Is.EqualTo(0));

                MockProxy.Where_GetCurrentLocationAsync_returns(new Location(0, 2222, DateTimeOffset.Now));
                _testScheduler.AdvanceBy(1000);
                var second = await result2.Task;

                Assert.That(second.ToError(), Is.EqualTo(GeolocationErrors.InvalidLongitude));
                MockAnalyticsService.VerifyTrace(GeolocationErrors.InvalidLongitude.ToString(), LogSeverity.Error);
                disposable.Dispose();
            }
Пример #2
0
            public async Task SHOULD_trace()
            {
                //Act
                await Sut.UpdateDeviceRegistrationAsync(_dataOnlyDeviceRegistration, MockNotificationHub.Object);

                //Assert
                MockAnalyticsService.VerifyTrace("Push notification registration updated");
            }
        public async Task SHOULD_trace_success()
        {
            //Act
            await Sut.DeregisterUserDeviceAsync("myUserId", "myDeviceId", MockNotificationHub.Object);

            //Assert
            MockAnalyticsService.VerifyTrace("Templates cleared for push notifications registration");
        }
        public async Task SHOULD_log()
        {
            //Act
            Sut.NotifyAppStarting();
            await Task.Delay(10);

            //Assert
            MockAnalyticsService.VerifyTrace("App Starting. Notifying handlers: 2");
        }
Пример #5
0
            public async Task SHOULD_track_operation()
            {
                //Act
                var result = await Sut.UpdateDeviceRegistrationAsync(_dataOnlyDeviceRegistration, MockNotificationHub.Object);

                //Assert
                MockAnalyticsService.VerifyTrace("Register device for push notifications");
                MockAnalyticsService.VerifyTraceProperty(nameof(DeviceRegistration), _dataOnlyDeviceRegistration);
            }
        public async Task WHEN_saving_new_handle_SHOULD_log_analytics()
        {
            //Act
            await Sut.UpdatePushNotificationServiceHandleAsync("new Handle");

            //Assert
            MockAnalyticsService.VerifyTrace("PnsHandle saved", LogSeverity.Information);
            MockAnalyticsService.VerifyTraceProperty("PnsHandle", "new Handle");
        }
        public async Task SHOULD_trace_success()
        {
            //Act
            await Sut.FromAddressAsync(_addressString);

            //Assert
            MockAnalyticsService.VerifyTrace("GPS cooridnates found from address");
            MockAnalyticsService.VerifyTraceProperty("Address", _addressString);
        }
Пример #8
0
        public async Task SHOULD_extract_command_and_log_with_analytics()
        {
            //Act
            await Sut.HandleAsync <TestCommand>(MockResolverContext.Object, CancellationToken.None);

            //Assert
            MockAnalyticsService.VerifyTrace("TestCommand received");
            MockAnalyticsService.VerifyTraceProperty("TestCommand", _command);
        }
        public async Task SHOULD_load_and_return_handle_from_secure_storage()
        {
            //Act
            var result = await Sut.GetPushNotificationServiceHandleAsync();

            //Assert
            Assert.AreEqual("stored handle", result);
            MockAnalyticsService.VerifyTrace("PnsHandle loaded");
            MockAnalyticsService.VerifyTraceProperty("PnsHandle", "stored handle");
        }
            public async Task SHOULD_track_operation()
            {
                //Act
                await Sut.LoadRegistrationForUserDeviceAsync("myUserId", "myDeviceId", MockNotificationHub.Object);

                //Assert
                MockAnalyticsService.VerifyTrace("Load push notification registration for user device");
                MockAnalyticsService.VerifyTraceProperty("UserId", "myUserId");
                MockAnalyticsService.VerifyTraceProperty("DeviceIdentifier", "myDeviceId");
            }
Пример #11
0
        public async Task SHOULD_trace_success()
        {
            //Act
            await Sut.ToAddressAsync(_gpsLocation);

            //Assert
            MockAnalyticsService.VerifyTrace("Address found from GPS coordinates");
            MockAnalyticsService.VerifyTraceProperty("Address", "feature name, sub thoroughfare thoroughfare, sub locality, sub admin area, locality, admin area, postal code, country name");
            MockAnalyticsService.VerifyTraceProperty(nameof(GpsLocation), _gpsLocation);
        }
        public async Task SHOULD_track_operation()
        {
            //Act
            await Sut.SendNotificationToTargetAsync(_pushNotification, _target, MockNotificationHub.Object);

            //Assert
            MockAnalyticsService.VerifyTrace("Send push notification to device");
            MockAnalyticsService.VerifyTraceProperty(nameof(PushNotification), _pushNotification);
            MockAnalyticsService.VerifyTraceProperty(nameof(DeviceTarget), _target);
        }
        public async Task SHOULD_track_operation()
        {
            //Act
            await Sut.SendNotificationToUserAsync(_notification, _userId, MockNotificationHub.Object);

            //Assert
            MockAnalyticsService.VerifyTrace("Sending push notification to user");
            MockAnalyticsService.VerifyTraceProperty(nameof(IPushNotification), _notification);
            MockAnalyticsService.VerifyTraceProperty("UserId", _userId);
        }
        public async Task SHOULD_extract_command_and_log_with_analytics()
        {
            //Act
            await Sut.HandleAsync <TestServerPayload, TestCommand>(MockResolverContext.Object, CancellationToken.None);

            //Assert
            MockCommandHandler.Mock.Verify(x => x.HandleAsync(It.Is <TestCommand>(y => y.Name == "Piet"), It.IsAny <CancellationToken>()));
            MockAnalyticsService.VerifyTrace("TestCommand received");
            MockAnalyticsService.VerifyTraceProperty("TestCommand", _command);
        }
Пример #15
0
        public void SHOULD_log_operation_and_trace_content()
        {
            //Test
            Sut.HandleForegroundNotification(IosNotification);

            //Assert
            MockAnalyticsService.VerifyStartTrace("Foreground Push Notification");
            MockAnalyticsService.VerifyTrace("Extracting push notification");
            MockAnalyticsService.VerifyTraceProperty("Raw Notification", IosNotification);
            MockAnalyticsService.VerifyTrace("Notification processed");
        }
Пример #16
0
        public void SHOULD_log_operation_and_trace_content()
        {
            //Test
            Sut.HandleAppLaunchingAsync(Arguments);

            //Assert
            MockAnalyticsService.VerifyStartTrace("Push Notification Tapped");
            MockAnalyticsService.VerifyTrace("Extracting push notification");
            MockAnalyticsService.VerifyTraceProperty("Raw Notification", Arguments);
            MockAnalyticsService.VerifyTrace("Notification processed");
        }
Пример #17
0
        public async Task SHOULD_log_operation_and_trace_content()
        {
            //Test
            await Sut.HandleNotificationTappedAsync(AndroidIntentProperties);

            //Assert
            MockAnalyticsService.VerifyStartTrace("Push Notification Tapped");
            MockAnalyticsService.VerifyTrace("Extracting push notification");
            MockAnalyticsService.VerifyTraceProperty("Raw Notification", AndroidIntentProperties);
            MockAnalyticsService.VerifyTrace("Notification processed");
        }
            public async Task IF_last_known_location_is_null_SHOULD_trace()
            {
                //Arrange
                MockProxy.Where_GetLastKnownLocationAsync_returns(null);

                //Act
                Sut.Connect(_requirements).Subscribe(next => { }, ex => { ExceptionTaskCompletionSource.SetResult(ex); });

                //Assert
                MockAnalyticsService.VerifyTrace("Last known location is null");
            }
            public async Task IF_current_location_is_null_SHOULD_warn()
            {
                //Arrange
                MockProxy.Where_GetCurrentLocationAsync_returns(null);

                //Act
                Sut.Connect(_requirements).Subscribe(next => { }, ex => { ExceptionTaskCompletionSource.SetResult(ex); });

                //Assert
                MockAnalyticsService.VerifyTrace("Current location is null", LogSeverity.Warning);
            }
            public async Task SHOULD_Trace_connection()
            {
                //Arrange
                _requirements = new GeolocationRequirements(TimeSpan.FromMinutes(1), LocationAccuracy.Low);

                //Act
                Sut.Connect(_requirements).Subscribe(next => {  });

                //Assert
                MockAnalyticsService.VerifyTrace("New GpsLocation connection requested with accuracy Low and interval 00:01:00");
            }
        public async Task IF_no_stored_handle_exists_SHOULD_return_empty_string_and_trace()
        {
            //Arrange
            MockSecureStorageService.Where_GetAsync_returns("PnsHandle", null);

            //Act
            var result = await Sut.GetPushNotificationServiceHandleAsync();

            //Assert
            Assert.AreEqual(string.Empty, result);
            MockAnalyticsService.VerifyTrace("No PnsHandle found");
        }
            public async Task IF_location_returned_is_null_SHOULD_warn()
            {
                //Act
                var disposable = Sut.Connect(_requirements)
                                 .Subscribe(next => { });

                //Assert
                MockProxy.Where_GetCurrentLocationAsync_returns(null);
                _testScheduler.AdvanceBy(1000);
                MockAnalyticsService.VerifyTrace("Updated location is null", LogSeverity.Warning);
                disposable.Dispose();
            }
        public async Task SHOULD_trace_extracted_notification()
        {
            //Arrange
            _target = DeviceTarget.iOS("pnsHandle");

            //Act
            await Sut.SendNotificationToTargetAsync(_pushNotification, _target, MockNotificationHub.Object);

            //Assert
            MockAnalyticsService.VerifyTrace("Native push notification extracted");
            MockAnalyticsService.VerifyTraceProperty(_iosNotification.GetType().Name, _iosNotification);
        }
        public async Task IF_no_locations_found_SHOULD_Error_and_trace()
        {
            //Arrange
            MockProxy.Where_GetLocationsFromAddressAsync_returns(new List <Location>());

            //Act
            var result = await Sut.FromAddressAsync(_addressString);

            //Assert
            MockAnalyticsService.VerifyTrace("No GPS coordinates found for given address", LogSeverity.Warning);
            MockAnalyticsService.VerifyTraceProperty("Address", _addressString);
            Assert.That(result.IsError(GeolocationErrors.GpsCoordinatesNotFound));
        }
        public async Task IF_installation_does_not_exist_SHOULD_succeed_and_trace()
        {
            //Arrange
            MockNotificationHubClientProxy.Mock.Setup(x => x.InstallationExistsAsync(_installation.InstallationId))
            .ReturnsAsync(false);

            //Act
            var result = await Sut.DeregisterUserDeviceAsync("myUserId", "myDeviceId", MockNotificationHub.Object);

            //Assert
            Assert.IsTrue(result.IsSuccess);
            MockAnalyticsService.VerifyTrace("No installation exists for user device, so there is nothing to deregister", LogSeverity.Warning);
        }
        public async Task IF_value_is_different_than_previous_one_SHOULD_log_analytics()
        {
            //Arrange
            MockSecureStorageService.Where_GetAsync_returns("new Handle");

            //Act
            await Sut.UpdatePushNotificationServiceHandleAsync("even newer Handle");

            //Assert
            MockAnalyticsService.VerifyTrace("PnsHandle updated", LogSeverity.Information);
            MockAnalyticsService.VerifyTraceProperty("OldPnsHandle", "new Handle");
            MockAnalyticsService.VerifyTraceProperty("NewPnsHandle", "even newer Handle");
        }
Пример #27
0
        public async Task IF_ClaimsPrincipal_is_bogus_return_error()
        {
            //Arrange
            MockResolverContext.With_ContextData("ClaimsPrincipal", null);

            //Act
            var result = await Sut.HandleAsync <TestCommand>(MockResolverContext.Object, CancellationToken.None);

            //Assert
            Assert.IsFalse(result);
            MockResolverContext.Mock.Verify(x => x.ReportError(It.Is <IError>(y => y.Message == AuthErrors.NotAuthenticated.ToString())));
            MockAnalyticsService.VerifyTrace(AuthErrors.NotAuthenticated.ToString(), LogSeverity.Error);
        }
            public async Task IF_current_location_is_invalid_SHOULD_error()
            {
                //Arrange
                MockProxy.Where_GetLastKnownLocationAsync_returns(new Location(-212, 22, DateTimeOffset.Now));

                //Act
                Sut.Connect(_requirements).Subscribe(next => { }, ex => { ExceptionTaskCompletionSource.SetResult(ex); });
                var exception = await ExceptionTaskCompletionSource.Task;

                //Assert
                Assert.That(exception.ToError(), Is.EqualTo(GeolocationErrors.InvalidLatitude));
                MockAnalyticsService.VerifyTrace(GeolocationErrors.InvalidLatitude.ToString(), LogSeverity.Error);
            }
Пример #29
0
        public async Task IF_no_placemarks_found_SHOULD_Error_and_trace()
        {
            //Arrange
            MockProxy.Where_GetPlacemarksFromLocationAsync_returns(new List <Placemark>());

            //Act
            var result = await Sut.ToAddressAsync(_gpsLocation);

            //Assert
            MockAnalyticsService.VerifyTrace("No address found for Gps coordinates", LogSeverity.Warning);
            MockAnalyticsService.VerifyTraceProperty(nameof(GpsLocation), _gpsLocation);
            Assert.That(result.IsError(GeolocationErrors.AddressNotFound));
        }
Пример #30
0
        public async Task IF_command_handler_throws_UnauthorizedAccessException_SHOULD_log_exception_and_report_error()
        {
            //Arrange
            MockCommandHandler.Mock.Setup(x => x.HandleAsync(It.IsAny <TestCommand>(), It.IsAny <IAuthenticatedUser>(), It.IsAny <CancellationToken>()))
            .ThrowsAsync(new UnauthorizedAccessException());

            //Act
            var result = await Sut.HandleAsync <TestCommand>(MockResolverContext.Object, CancellationToken.None);

            //Asserrt
            Assert.IsFalse(result);
            MockResolverContext.Mock.Verify(x => x.ReportError(It.Is <IError>(y => y.Message == AuthErrors.NotAuthorized.ToString())));
            MockAnalyticsService.VerifyTrace(AuthErrors.NotAuthorized.ToString(), LogSeverity.Error);
        }