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 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 UserRootBudgetRelationship Run() { User user = new User(this.userName, this.firstName, this.lastName, this.email); (Budget rootBudget, BudgetPeriod firstPeriod)budgetWithPeriod = CreateNewUserRootBudget(user); UserRootBudgetRelationship userWithBudget = new UserRootBudgetRelationship(user, budgetWithPeriod.rootBudget, budgetWithPeriod.firstPeriod); return(userWithBudget); }
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 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); }