public ActionResult Register(DbUserAccount acc) { if (ModelState.IsValid) { using (OurDbContext db = new OurDbContext()) { db.UserAccount.Add(acc); if (db.SaveChanges() == 1) { Session["Email"] = acc.Email; ViewBag.Message = acc.Email + " SuccessFully Registered!. An Email was sent to your account.Please verify you email account"; } } } return(View()); }
public async Task CookieUsedInPriorLoginAsync() { Init(); string username = "******"; string password = "******"; DbUserAccount account = userAccountController.Create(username, password); string randomCookiesHash = Convert.ToBase64String(StrongRandomNumberGenerator.GetBytes(16)); bool cookieAlreadyPresentOnFirstTest = await userAccountController.HasClientWithThisHashedCookieSuccessfullyLoggedInBeforeAsync(account, randomCookiesHash); Assert.False(cookieAlreadyPresentOnFirstTest); await userAccountController.RecordHashOfDeviceCookieUsedDuringSuccessfulLoginAsync(account, randomCookiesHash); bool cookieAlreadyPresentOnSecondTest = await userAccountController.HasClientWithThisHashedCookieSuccessfullyLoggedInBeforeAsync(account, randomCookiesHash); Assert.True(cookieAlreadyPresentOnSecondTest); }
public async Task AddIncorrectPhase2HashAsync() { Init(); string username = "******"; string password = "******"; DbUserAccount account = userAccountController.Create(username, password); string incorrectPasswordHash = Convert.ToBase64String(StrongRandomNumberGenerator.GetBytes(16)); bool incorrectPasswordAlreadyPresentOnFirstTest = await userAccountController.AddIncorrectPhaseTwoHashAsync(account, incorrectPasswordHash); Assert.False(incorrectPasswordAlreadyPresentOnFirstTest); // Since the hash is added via a background task to minimize response latency, we'll want to // wait to be sure it's added Thread.Sleep(1000); bool incorrectPasswordPresentOnSecondTest = await userAccountController.AddIncorrectPhaseTwoHashAsync(account, incorrectPasswordHash); Assert.True(incorrectPasswordPresentOnSecondTest); }
public async Task CreateAccountUseCreditDestroyAccount() { Init(); IRepository <string, DbUserAccount> userAccountRespository = _UserAccountRepositoryFactory.Create(); using (DbUserAccountContext ctx = new DbUserAccountContext(dbOptions)) { ctx.Database.ExecuteSqlCommand("DELETE FROM DbUserAccount"); ctx.Database.ExecuteSqlCommand("DELETE FROM DbUserAccountCreditBalance"); } string username = "******"; string password = "******"; // Make sure that LoadAsync retursn null for an account that doesn't exist yet. DbUserAccount accountThatShouldNotExist = await userAccountRespository.LoadAsync(username); Assert.Null(accountThatShouldNotExist); // Create an add a new account to the database DbUserAccount newAccount = userAccountController.Create(username, password); newAccount.CreditLimit = 1d; await userAccountRespository.AddAsync(newAccount); // Load that account back in DbUserAccount reloadedAccount = await userAccountRespository.LoadAsync(username); Assert.NotNull(reloadedAccount); // Try to use half of the credit limit double credit = await userAccountController.TryGetCreditAsync(reloadedAccount, 0.5); Assert.Equal(credit, 0.5d); // Try to use 100 times the credit limit of 1, only to receive ~.5 back // (you'll get a tiny amount more as the consumed credit has decayed with time) double moreCredit = await userAccountController.TryGetCreditAsync(reloadedAccount, 1000); Assert.InRange(moreCredit, 0.5d, 0.51d); // Clean up using (DbUserAccountContext context = new DbUserAccountContext(dbOptions)) { DbUserAccount account = context.DbUserAccounts.FirstOrDefault(a => a.UsernameOrAccountId == username); Assert.NotNull(account); if (account != null) { context.DbUserAccounts.Remove(account); } await context.SaveChangesAsync(); DbUserAccountCreditBalance balance = context.DbUserAccountCreditBalances.FirstOrDefault(a => a.DbUserAccountId == username); if (balance != null) { context.DbUserAccountCreditBalances.Remove(balance); await context.SaveChangesAsync(); } } }