Ejemplo n.º 1
0
            public async Task IF_registration_contains_forbidden_string_SHOULD_fail()
            {
                _visibleTemplateDeviceRegistration.Platform = RuntimePlatform.UWP;

                foreach (var forbiddenString in ReservedStrings.Uwp)
                {
                    //Arrange
                    _visibleTemplateDeviceRegistration.Templates.First().DataProperties.Add(forbiddenString);

                    //Act
                    var result = await Sut.UpdateDeviceRegistrationAsync(_visibleTemplateDeviceRegistration, MockNotificationHub.Object);

                    //Assert
                    result.VerifyResponseError(PushErrors.ReservedString(forbiddenString), MockAnalyticsService);

                    //Cleanup
                    _visibleTemplateDeviceRegistration.Templates.First().DataProperties.Remove(forbiddenString);
                }
            }
Ejemplo n.º 2
0
        public static bool IsNotValid(this IDeviceRegistration deviceRegistration, object sender, IAnalyticsService analyticsService, out Error error)
        {
            if (deviceRegistration == null)
            {
                error = PushErrors.InvalidDeviceRegistration;
                analyticsService.TraceError(sender, error);
                return(true);
            }

            //if (deviceRegistration.Templates.Count == 0)
            //{
            //    error = analyticsService.TraceError(sender, PushErrors.NoTemplateProvidedOnRegistration, deviceRegistration.ToObjectDictionary());
            //    return true;
            //}

            if (string.IsNullOrEmpty(deviceRegistration.PushNotificationServiceHandle))
            {
                error = PushErrors.InvalidPnsHandle;
                analyticsService.TraceError(sender, error, deviceRegistration.ToObjectDictionary());
                return(true);
            }

            if (deviceRegistration.Platform == null || string.IsNullOrEmpty(deviceRegistration.Platform.Value) ||
                deviceRegistration.Platform.Value != RuntimePlatform.iOS.Value &&
                deviceRegistration.Platform.Value != RuntimePlatform.Android.Value &&
                deviceRegistration.Platform.Value != RuntimePlatform.UWP.Value)
            {
                error = PushErrors.InvalidPlatform;
                analyticsService.TraceError(sender, error, deviceRegistration.ToObjectDictionary());
                return(true);
            }

            if (string.IsNullOrEmpty(deviceRegistration.DeviceIdentifier))
            {
                error = PushErrors.MissingDeviceIdentifier;
                analyticsService.TraceError(sender, error, deviceRegistration.ToObjectDictionary());
                return(true);
            }

            if (string.IsNullOrEmpty(deviceRegistration.UserId))
            {
                error = PushErrors.MissingUserId;
                analyticsService.TraceError(sender, error, deviceRegistration.ToObjectDictionary());
                return(true);
            }

            foreach (var template in deviceRegistration.Templates)
            {
                foreach (var templateDataProperty in template.DataProperties)
                {
                    var reservedStrings = ReservedStrings.GetForPlatform(deviceRegistration.Platform);
                    if (reservedStrings.Contains(templateDataProperty))
                    {
                        error = PushErrors.ReservedString(templateDataProperty);
                        analyticsService.TraceError(sender, error, deviceRegistration.ToObjectDictionary());
                        return(true);
                    }
                }
            }

            error = Error.None;
            return(false);
        }