Ejemplo n.º 1
0
        public async Task <IActionResult> Register(CustomerRequest request)
        {
            try
            {
                CustomerRequestValidator validator = new CustomerRequestValidator();
                var vresult = validator.Validate(request);
                if (vresult.IsValid)
                {
                    var result = await _customerService.RegisterCustomer(request);

                    if (result.CustomerID > 0)
                    {
                        return(Ok(result.CustomerID));
                    }
                    else
                    {
                        return(BadRequest(0));
                    }
                }
                else
                {
                    return(BadRequest(-1));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Un expected error");
                return(StatusCode(StatusCodes.Status500InternalServerError, -2));
            }
        }
Ejemplo n.º 2
0
        public void Validate_Email_Valid(string email)
        {
            var customerValidator = new CustomerRequestValidator();

            customerValidator.ShouldNotHaveValidationErrorFor(a => a.EmailAddress, new CustomerRequest {
                EmailAddress = email
            });
        }
Ejemplo n.º 3
0
        public void Validate_PolicyNumber_NotValid(string policynumber)
        {
            var customerValidator = new CustomerRequestValidator();

            customerValidator.ShouldHaveValidationErrorFor(a => a.PolicyReferenceNumber, new CustomerRequest {
                PolicyReferenceNumber = policynumber
            });
        }
Ejemplo n.º 4
0
        public void Validate_SurName_NotValid(string surName)
        {
            var customerValidator = new CustomerRequestValidator();

            customerValidator.ShouldHaveValidationErrorFor(a => a.SurName, new CustomerRequest {
                SurName = surName
            });
        }
Ejemplo n.º 5
0
        public void Validate_FirstName_NotValid(string firstName)
        {
            var customerValidator = new CustomerRequestValidator();

            customerValidator.ShouldHaveValidationErrorFor(a => a.FirstName, new CustomerRequest {
                FirstName = firstName
            });
        }
Ejemplo n.º 6
0
        public void Validate_DOB_NotValid([ValueSource(nameof(notValidDOBList))] DateTime notValidDOBDate)
        {
            var customerValidator = new CustomerRequestValidator();

            customerValidator.ShouldHaveValidationErrorFor(a => a.DOB, new CustomerRequest {
                DOB = notValidDOBDate
            });
        }
Ejemplo n.º 7
0
        public void Validate_Email_and_DOB_NotValid([ValueSource(nameof(customerRequestEmailDOBNotValid))] CustomerRequest customerRequestNotValid)
        {
            var customerValidator = new CustomerRequestValidator();

            customerValidator.ShouldHaveValidationErrorFor(x => x.EmailAddress, new CustomerRequest {
                EmailAddress = customerRequestNotValid.EmailAddress, DOB = customerRequestNotValid.DOB
            });
            customerValidator.ShouldHaveValidationErrorFor(x => x.DOB, new CustomerRequest {
                EmailAddress = customerRequestNotValid.EmailAddress, DOB = customerRequestNotValid.DOB
            });
        }