public int RegUser(string username, Credentials credentials, bool isTeacher) { Ensure.String.IsNotNullOrWhiteSpace(username); Ensure.Any.IsNotNull(credentials); Ensure.Bool.IsFalse(_userRepository.GetAll().Any(u => u.Credentials.Email.Equals(credentials.Email)), nameof(RegUser), opt => opt.WithException(new UserAlreadyExistsException(credentials.Email))); var user = new User(username, credentials, isTeacher, UserType.UnConfirmed, _userSettings.DefaultAvatar); var key = new Key(user.Credentials.Email, KeyAppointment.ConfirmEmail); _keysRepository.AddKey(key); _sender.SendMessage(credentials.Email, new UserConfirmationMessage(username, key.Value), MessageThemes.UserConfirmation, username); _userRepository.Add(user); return(user.Id); }
public void RegistrateAdminUsingRightKey_AdminWasRegistrated() { //Arrange var accountFacade = new AccountFacade(_keysRepository, _userRepository, _emailSender.Object, userSettings); var userFacade = new UserFacade(_userRepository, _groupRepository, _eventRepository, _publisher.Object); var key = new Key("email", KeyAppointment.BecomeAdmin); _keysRepository.AddKey(key); //Act var userId = accountFacade.RegUser("Alena", Credentials.FromRawData("email", "password"), true, key.Value); var currentUser = userFacade.GetUser(userId); //Assert Assert.AreEqual(UserType.Admin, currentUser.Type); }