Example #1
0
        public void WhenUserLoginIsNotFilledThenReturnFalse()
        {
            UserRegistrationValidator validator = new UserRegistrationValidator();

            bool result = validator.Validate(new UserDto());

            result.Should().BeFalse();
        }
Example #2
0
        public void WhenUserDtoIsEmptyThenReturnFalse()
        {
            UserRegistrationValidator validator = new UserRegistrationValidator();

            bool result = validator.Validate(null);

            result.Should().BeFalse();
        }
Example #3
0
        public void WhenAddressIsNullThenReturnFalse()
        {
            UserRegistrationValidator validator = new UserRegistrationValidator();

            bool result = validator.Validate(new UserDto()
            {
                Login = "******", Password = "******", Address = null
            });

            result.Should().BeFalse();
        }
        public ActionResult UserRegistrationForm(UserRegistrationModel model)
        {
            int    Id       = model.UserId;
            string email    = model.Email;
            string mobileno = model.MobileNumber;

            model.DobDate  = DateTime.Now.Day;
            model.DobMonth = DateTime.Now.Month;
            model.DobYear  = DateTime.Now.Year;
            FluentValidation.IValidator <UserRegistrationModel> validator = new UserRegistrationValidator();
            var validationResults = validator.Validate(model);

            foreach (var item in validationResults.Errors)
            {
                ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var result = _webClient.UploadData <int>("register", model);
                    switch (result)
                    {
                    case 1:
                        return(RedirectToAction("Login", "User", new { ShowRegMsg = true }));

                    case 2:
                        ModelState.AddModelError("", Resource.UserCreation_UserNameAlreadyRegistered);
                        break;

                    case 4:
                        ModelState.AddModelError("", Resource.PopUpLogin_wrongCredentials);
                        break;

                    case 5:
                        model.IsInvalidToken = true;
                        break;

                    default:
                        ModelState.AddModelError("", Resource.UserCreation_error);
                        break;
                    }
                }
                catch
                {
                }
                return(PartialView(model));
            }

            return(PartialView(model));
        }
        public static IView GetMainViewObject()
        {
            ILogin          login    = new LoginUser();
            IRegister       register = new RegisterUser();
            IFieldValidator userRegistrationValidator = new UserRegistrationValidator(register);

            userRegistrationValidator.InitialiseValidatorDelegates();

            IView registerView = new UserRegistrationView(register, userRegistrationValidator);
            IView loginView    = new UserLoginView(login);
            IView mainView     = new MainView(registerView, loginView);

            return(mainView);
        }
Example #6
0
        public void WhenAllFieldsAreFilledCorrectlyThenRetrunTrue()
        {
            UserRegistrationValidator validator = new UserRegistrationValidator();

            bool result = validator.Validate(new UserDto()
            {
                Login = "******", Password = "******", Address = new UserAddressDto()
                {
                    Email = "*****@*****.**"
                }
            });

            result.Should().BeTrue();
        }
Example #7
0
        public void WhenAddressEmailIsNullOrEmptyThenReturnFalse(string email)
        {
            UserRegistrationValidator validator = new UserRegistrationValidator();

            bool result = validator.Validate(new UserDto()
            {
                Login = "******", Password = "******", Address = new UserAddressDto()
                {
                    Email = email
                }
            });

            result.Should().BeFalse();
        }
        public object Post(UserRegister request)
        {
            var validator = new UserRegistrationValidator();
            var result = validator.Validate(request);

            if (!result.IsValid) {
                var ex = result.ToErrorResult().ToResponseStatus();
                var response = new UserRegisterResponse {
                    Request = request,
                    ResponseStatus = ex,
                };
                return new HttpResult(response, HttpStatusCode.BadRequest);
            }

            // Add the new user to the database
            Users.Create(request.User);

            return HttpResult.Redirect(Url.Content("~/home"));
        }