Ejemplo n.º 1
0
        public async Task Lookup_Ok()
        {
            var phonenr = await svc.GetPhoneNrInfo("7605006125");

            Assert.True(phonenr.IsValid);
            Assert.Equal("US", phonenr.CountryCode);
            Assert.Equal("(760) 500-6125", phonenr.NationalFormat);
            Assert.Equal("+17605006125", phonenr.PhoneNr);
            Assert.Equal(PhoneNrInfo.TypeOfNumberEnum.Mobile, phonenr.TypeOfNumber);
        }
Ejemplo n.º 2
0
        public void Validate_UserProfile(UserProfile entity, ValidationResult validation)
        {
            var idIsNullMsg = $"One or more Ids in instance of type '{entity.GetType()}' is null.";

            if (string.IsNullOrWhiteSpace(entity.PrimaryEmail))
            {
                validation.Failures.Add(new ValidationFailure
                {
                    Code                     = ValidationErrorCode.EmailIsNull,
                    DebugMessage             = "Email cannot be cannot be empty",
                    EntityJsonRepresentation = GetJson(entity),
                    EntityIdInError          = entity.Id,
                });
            }

            if (!entity.PrimaryEmail.Contains("@"))
            {
                validation.Failures.Add(new ValidationFailure
                {
                    Code                     = ValidationErrorCode.Email_ValidationError,
                    DebugMessage             = "Email is not valid",
                    EntityJsonRepresentation = GetJson(entity),
                    EntityIdInError          = entity.Id,
                });
            }


            if (entity.PartnerInvitation != null && entity.PartnerInvitation.InvitationStatus != PartnerInvitationStatusTypeEnum.NotApplicable)
            {
                if (entity.PartnerInvitation.DateOfBirth == null)
                {
                    validation.Failures.Add(new ValidationFailure
                    {
                        Code                     = ValidationErrorCode.DateOfBirthIsNull,
                        DebugMessage             = "Date of birth cannot be empty",
                        EntityJsonRepresentation = GetJson(entity),
                        EntityIdInError          = entity.Id,
                    });
                }
                else
                {
                    if (entity.PartnerInvitation.DateOfBirth.Value.Kind != DateTimeKind.Unspecified)
                    {
                        validation.Failures.Add(new ValidationFailure
                        {
                            Code                     = ValidationErrorCode.DateOfBirth_ValidationError,
                            DebugMessage             = $"Partner date of birth is invalid, DateTime.Kind needs to be 'Unspecified'",
                            EntityJsonRepresentation = GetJson(entity),
                            EntityIdInError          = entity.Id,
                        });
                    }

                    if (entity.PartnerInvitation.DateOfBirth.Value.Hour != 0 || entity.PartnerInvitation.DateOfBirth.Value.Minute != 0 || entity.PartnerInvitation.DateOfBirth.Value.Second != 0)
                    {
                        validation.Failures.Add(new ValidationFailure
                        {
                            Code                     = ValidationErrorCode.DateOfBirth_ValidationError,
                            DebugMessage             = $"Partner date of birth is invalid, may only contain Year, Month and Day",
                            EntityJsonRepresentation = GetJson(entity),
                            EntityIdInError          = entity.Id,
                        });
                    }

                    var minAge = 16;
                    if (entity.PartnerInvitation.DateOfBirth > DateTime.Now.AddYears(-minAge))
                    {
                        validation.Failures.Add(new ValidationFailure
                        {
                            Code                     = ValidationErrorCode.ValidationFailure_PartnerInvitation,
                            DebugMessage             = $"Partner must be at least {minAge} years old",
                            EntityJsonRepresentation = GetJson(entity),
                            EntityIdInError          = entity.Id,
                        });
                    }
                }

                if (string.IsNullOrWhiteSpace(entity.PartnerInvitation.FirstName))
                {
                    validation.Failures.Add(new ValidationFailure
                    {
                        Code                     = ValidationErrorCode.FirstNameIsNull,
                        DebugMessage             = "FirstName cannot be empty",
                        EntityJsonRepresentation = GetJson(entity),
                        EntityIdInError          = entity.Id,
                    });
                }

                if (false == (entity.PartnerInvitation.Gender == GenderTypeEnum.Male || entity.PartnerInvitation.Gender == GenderTypeEnum.Female))
                {
                    validation.Failures.Add(new ValidationFailure
                    {
                        Code                     = ValidationErrorCode.Gender_ValidationError,
                        DebugMessage             = "Gender is invalid, must be set",
                        EntityJsonRepresentation = GetJson(entity),
                        EntityIdInError          = entity.Id,
                    });
                }

                if (entity.PartnerInvitation.InvitationStatus == PartnerInvitationStatusTypeEnum.Unknown)
                {
                    validation.Failures.Add(new ValidationFailure
                    {
                        Code                     = ValidationErrorCode.ValidationFailure_PartnerInvitation,
                        DebugMessage             = "Partner invitation status is invalid",
                        EntityJsonRepresentation = GetJson(entity),
                        EntityIdInError          = entity.Id,
                    });
                }

                if (string.IsNullOrWhiteSpace(entity.PartnerInvitation.LastName))
                {
                    validation.Failures.Add(new ValidationFailure
                    {
                        Code                     = ValidationErrorCode.LastNameIsNull,
                        DebugMessage             = "Lastname cannot be empty",
                        EntityJsonRepresentation = GetJson(entity),
                        EntityIdInError          = entity.Id,
                    });
                }

                if (string.IsNullOrWhiteSpace(entity.PartnerInvitation.MobilePhone?.UserEnteredNr))
                {
                    validation.Failures.Add(new ValidationFailure
                    {
                        Code                     = ValidationErrorCode.MobilePhoneIsNull,
                        DebugMessage             = "Mobile phone cannot be empty",
                        EntityJsonRepresentation = GetJson(entity),
                        EntityIdInError          = entity.Id,
                    });
                }

                if (false == string.IsNullOrWhiteSpace(entity.PartnerInvitation.MobilePhone?.UserEnteredNr))
                {
                    if (false == entity.PartnerInvitation.MobilePhone.IsValidated)
                    {
                        var task      = _phoneService.GetPhoneNrInfo(entity.PartnerInvitation.MobilePhone.UserEnteredNr);
                        var phoneInfo = task.Result;
                        if (false == phoneInfo.IsValid || phoneInfo.TypeOfNumber != PhoneNrInfo.TypeOfNumberEnum.Mobile)
                        {
                            validation.Failures.Add(new ValidationFailure
                            {
                                Code                     = ValidationErrorCode.MobilePhone_ValidationError,
                                DebugMessage             = $"Mobile phone nr '{entity.PartnerInvitation.MobilePhone?.UserEnteredNr}' is not valid",
                                EntityJsonRepresentation = GetJson(entity),
                                EntityIdInError          = entity.Id,
                            });
                        }
                        else
                        {
                            entity.PartnerInvitation.MobilePhone.CountryCode    = phoneInfo.CountryCode;
                            entity.PartnerInvitation.MobilePhone.IsValidated    = true;
                            entity.PartnerInvitation.MobilePhone.NationalFormat = phoneInfo.NationalFormat;
                            entity.PartnerInvitation.MobilePhone.PhoneNr        = phoneInfo.PhoneNr;
                            switch (phoneInfo.TypeOfNumber)
                            {
                            case PhoneNrInfo.TypeOfNumberEnum.Mobile:
                                entity.PartnerInvitation.MobilePhone.TypeOfNumber = Phone.TypeOfNumberEnum.Mobile;
                                break;

                            case PhoneNrInfo.TypeOfNumberEnum.Other:
                                entity.PartnerInvitation.MobilePhone.TypeOfNumber = Phone.TypeOfNumberEnum.Other;
                                break;

                            default:
                                entity.PartnerInvitation.MobilePhone.TypeOfNumber = Phone.TypeOfNumberEnum.Unknown;
                                break;
                            }
                        }
                    }
                }
            }
        }