Inheritance: INotifyPropertyChanged
        public void ShouldThrowIfRegisterIsCalledBeforeAuthenticated()
        {
            var handler = new ServiceHandler(FakeUri);
            var model = new RegisterUserModel();

            Assert.That(() => handler.RegisterNewUser(model), Throws.InvalidOperationException);
        }
Beispiel #2
0
        public void Register(string username, string email, string confirmEmail, string password, string confirmpassword, Dictionary<string, bool> roles)
        {
            Guard.VerifyStringIsNotNullOrEmpty(username, nameof(username));
            Guard.VerifyStringIsNotNullOrEmpty(email, nameof(email));
            Guard.VerifyStringIsNotNullOrEmpty(confirmEmail, nameof(confirmEmail));
            Guard.VerifyStringIsNotNullOrEmpty(password, nameof(password));
            Guard.VerifyStringIsNotNullOrEmpty(confirmpassword, nameof(confirmpassword));
            Guard.VerifyObjectNotNull(roles, nameof(roles));

            var isValid = VerifyNewUserCreds(username, email, confirmEmail, password, confirmpassword);

            if (isValid)
            {
                var registerUserModel = new RegisterUserModel
                {
                    BindingModel = new RegisterBindingModel
                    {
                        UserName = username,
                        Email = email,
                        Password = password,
                        ConfirmPassword = confirmpassword
                    },
                    Roles = new Roles(roles)
                };

                RegisterUser(registerUserModel);
            }
        }
        public void RegisterNewUser(RegisterUserModel model)
        {
            Guard.VerifyObjectNotNull(model, nameof(model));

            if (string.IsNullOrEmpty(_authToken))
            { throw new InvalidOperationException("You need to authenticate with LoginAs() first."); }

            //create user
            var response = CreateUser(model);
            if (!response.IsSuccessStatusCode)
            { throw new Exception(response.StatusCode + Environment.NewLine + response.ReasonPhrase);}

            var userId = response.Content.ReadAsAsync<UserDto>().Result.Id;

            //assign roles
            AssignRoles(userId, model.Roles);
        }
 private HttpResponseMessage CreateUser(RegisterUserModel model)
 {
     return _client.PostAsync("account/register", model.BindingModel, new JsonMediaTypeFormatter()).Result;
 }
Beispiel #5
0
 private void RegisterUser(RegisterUserModel newUserModel)
 {
     _serviceHandler.RegisterNewUser(newUserModel);
 }