public async Task CreateUser(RegisterRequest newUser) { if (newUser.ConfirmPassword != newUser.Password) { throw new InvalidOperationException("The confirmation password must match the real password"); } if (await DoesUserExist(newUser.Username)) { throw new InvalidOperationException("That user already exists"); } var command = new CreateUserCommand( newUser.Username, newUser.FirstName, newUser.LastName, newUser.Email); UserRootBudgetRelationship userRootBudgetRelationship = command.Run(); string encryptedPassword = this.cryptor.Encrypt(newUser.Password, this.gateKeeperConfig.EncryptionKey, this.gateKeeperConfig.Salt); UserRecord createdUser = await this.userRepository.SaveUser(userRootBudgetRelationship.User, encryptedPassword); userRootBudgetRelationship.RootBudget.Fund.SetOwner(createdUser.Id); this.context.Budgets.Add(userRootBudgetRelationship.RootBudget); this.context.BudgetPeriods.Add(userRootBudgetRelationship.FirstPeriod); await this.context.SaveChangesAsync(); }
public void Create_User_Command_Should_Persist_New_User() { CreateUserCommand command = new CreateUserCommand(_EfRepository); Guid userId = command.Run("John", "Brown"); User user = _EfRepository.Get <User>(userId); Assert.IsNotNull(user); }
public void Test_CreateUser_SetsRootBudgetDurationToMonthlyBookEndedDuration() { string firstName = "Ian"; string lastName = "Kirkpatrick"; string email = "*****@*****.**"; string username = "******"; CreateUserCommand command = new CreateUserCommand(username, firstName, lastName, email); UserRootBudgetRelationship userRootBudgetRelationship = command.Run(); Assert.IsAssignableFrom <MonthlyBookEndedDuration>(userRootBudgetRelationship.RootBudget.Fund.Duration); }
public void Test_CreateUser_CreatesRootBudget() { string firstName = "Ian"; string lastName = "Kirkpatrick"; string email = "*****@*****.**"; string username = "******"; CreateUserCommand command = new CreateUserCommand(username, firstName, lastName, email); UserRootBudgetRelationship userRootBudgetRelationship = command.Run(); Assert.NotNull(userRootBudgetRelationship.RootBudget); }
public async Task Open_Account_Command_Should_Persist_New_Account_And_Movement() { CreateUserCommand createUserCommand = new CreateUserCommand(_EfRepository); Guid userId = createUserCommand.Run("John", "Brown"); OpenAccountCommand command = new OpenAccountCommand(_EfRepository, _EsRepository); Guid accountId = await command.RunAsync(userId, 100); Account account = _EfRepository.Get <Account>(accountId); Assert.NotNull(account); }
public void Test_CreateUser_SetsRootBudgetSetAmountTo0() { string firstName = "Ian"; string lastName = "Kirkpatrick"; string email = "*****@*****.**"; string username = "******"; decimal expectedSetAmount = 0; CreateUserCommand command = new CreateUserCommand(username, firstName, lastName, email); UserRootBudgetRelationship userRootBudgetRelationship = command.Run(); Assert.Equal(userRootBudgetRelationship.RootBudget.SetAmount, expectedSetAmount); }
public void Test_CreateUser_SetsPropertiesCorrectly() { string firstName = "Ian"; string lastName = "Kirkpatrick"; string email = "*****@*****.**"; string username = "******"; CreateUserCommand command = new CreateUserCommand(username, firstName, lastName, email); UserRootBudgetRelationship userRootBudgetRelationship = command.Run(); Assert.Equal(userRootBudgetRelationship.User.FirstName, firstName); Assert.Equal(userRootBudgetRelationship.User.LastName, lastName); Assert.Equal(userRootBudgetRelationship.User.Email, email); Assert.Equal(userRootBudgetRelationship.User.Username, username); }
public void Test_CreateUser_SetsRootBudgetDurationToEndOn31st() { string firstName = "Ian"; string lastName = "Kirkpatrick"; string email = "*****@*****.**"; string username = "******"; int expectedDurationEndDay = 31; CreateUserCommand command = new CreateUserCommand(username, firstName, lastName, email); UserRootBudgetRelationship userRootBudgetRelationship = command.Run(); MonthlyBookEndedDuration duration = (MonthlyBookEndedDuration)userRootBudgetRelationship.RootBudget.Fund.Duration; Assert.Equal(duration.EndDayOfMonth, expectedDurationEndDay); }
public void Test_CreateUser_SetsRootBudgetDurationRolloverToFalse() { string firstName = "Ian"; string lastName = "Kirkpatrick"; string email = "*****@*****.**"; string username = "******"; bool expectedDurationRollover = false; CreateUserCommand command = new CreateUserCommand(username, firstName, lastName, email); UserRootBudgetRelationship userRootBudgetRelationship = command.Run(); MonthlyBookEndedDuration duration = (MonthlyBookEndedDuration)userRootBudgetRelationship.RootBudget.Fund.Duration; Assert.Equal(duration.RolloverEndDateOnSmallMonths, expectedDurationRollover); }