public void ShouldFailCreateUserAndOrganizationIfOrganizationNameNotSpecified() { var model = new UserOrganizationModel { Email = "*****@*****.**" }; // Execution this.controller.Create(model); }
public void ShouldFailCreateUserAndOrganizationWhenEmailInUse() { var model = new UserOrganizationModel { Email = user.Email }; // Execution this.controller.Create(model); }
public void ShouldFailCreateUserAndOrganizationWhenEmailNotValid() { var model = new UserOrganizationModel { Email = "BadEmailmail.com" }; // Execution this.controller.Create(model); }
public void ShouldFailCreateUserAndOrganizationWhenOrganizationNameInUse() { var model = new UserOrganizationModel { Email = "*****@*****.**", OrganizationName = organization.Name, }; // Execution this.controller.Create(model); }
public void ShouldFailCreateUserAndOrganizationIfOrganizationPhoneNotSpecified() { var model = new UserOrganizationModel { Email = "*****@*****.**", OrganizationName = "name", AdministrativeContact = "contact" }; // Execution this.controller.Create(model); }
public void ShouldFailCreateUserAndOrganizationIfUserNotAgreeWithTerms() { var model = new UserOrganizationModel { Email = "*****@*****.**", OrganizationName = "name", AdministrativeContact = "contact", AdministrativePhone = "123" }; // Execution this.controller.Create(model); }
public void UserShouldCreateNewUserAndOrganization() { var model = new UserOrganizationModel { AdministrativeContact = "contact", Email = "*****@*****.**", AdministrativePhone = "phone", IsAgreeWithTerms = true, OrganizationAddress = "address", OrganizationName = "newOrg", OrganizationPhone = "phone", Phone = "phone", TermsOfService = "Terms", Name = "name" }; // Execution this.controller.Create(model); // Assertion this.organizationService.Verify(m => m.Add(It.IsAny <Organization>())); this.userService.Verify(m => m.Add(It.IsAny <User>())); this.userService.Verify(m => m.Update(It.IsAny <User>())); }
public User SetupNewOrganisation(UserOrganizationModel model) { // Check whether email address is in a valid format try { new MailAddress(model.Email); } catch (FormatException) { throw new BaseException("Invalid email format."); } // Check whether email address already in use if (CheckWhetherEmailInUse(model.Email, string.Empty)) { throw new BaseException("Email already in use."); } // Check whether required fields are present if (string.IsNullOrEmpty(model.OrganizationName) || string.IsNullOrEmpty(model.AdministrativeContact) || string.IsNullOrEmpty(model.AdministrativePhone)) { throw new BaseException("User's email address, organization name, administrative contact and administrative phone fields are required!"); } // Check whether organisation name already in Use if (_organisations.All().Any(x => x.Name == model.OrganizationName)) { throw new BaseException("Organization name already in use."); } // Chekc whether T&C ticked if (!model.IsAgreeWithTerms) { throw new BaseException("New user should agree with terms of service."); } // Setup new organisation details var newOrganization = new Organization { Name = model.OrganizationName, AdministrativeContact = model.AdministrativeContact, AdministrativePhone = model.AdministrativePhone, IsAgreeWithTerms = model.IsAgreeWithTerms, Address = model.OrganizationAddress, Phone = model.OrganizationPhone, TermsOfService = model.TermsOfService, CreatedAt = GetDate, IsActive = false }; // Save changes this._organisations.Add(newOrganization); // Setup user details var newUser = new User { Name = model.Name, Email = model.Email, NewEmail = model.Email, IsActive = false, IsSysAdmin = false, OrganizationID = newOrganization.ID, Phone = model.Phone }; // Save user details _users.Add(newUser); // Setup token to validate email address var tokenInfo = _tokens.GenerateEmailConfirmationToken(newUser.ID); newUser.Token = tokenInfo.Token; newUser.TokenExpire = tokenInfo.TokenExpire; // Send token to email address SendNewUserConfirmation(newUser.ID, tokenInfo.TokenInfoEncoded); // Save token details to user details _users.Update(newUser); return(newUser); }