public void Insert(Registreren registreer) { string query = "dbo.spCreateUser"; using (SqlConnection connection = new SqlConnection(ConnectionString)) using (SqlCommand cmd = new SqlCommand(query, connection)) { DbContext.OpenConnection(connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@username", SqlDbType.NVarChar).Value = registreer.Gebruikersnaam; cmd.Parameters.AddWithValue("@password", SqlDbType.NVarChar).Value = registreer.Wachtwoord; cmd.Parameters.AddWithValue("@e_mail", SqlDbType.NVarChar).Value = registreer.Email; var returnParameter = cmd.Parameters.Add("@ReturnVal", SqlDbType.Int); returnParameter.Direction = ParameterDirection.ReturnValue; try { cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine(e); } if ((int)returnParameter.Value == -6) { throw new DuplicateNameException(); } } }
public void TestMaakAccountAan() { AccountContext context = new AccountContext(); Registreren registereer = new Registreren { Email = "*****@*****.**", Wachtwoord = "wachtwoord", Gebruikersnaam = "unittest" }; try { context.Insert(registereer); } catch (DuplicateNameException) { } Account account = new Account { Email = "*****@*****.**", Wachtwoord = "wachtwoord", }; Account accountOphalen = context.Select(account); Assert.IsNotNull(accountOphalen); }
public void TestNiet2ZelfdeAccounts() { AccountContext context = new AccountContext(); Registreren registereer = new Registreren { Email = "*****@*****.**", Wachtwoord = "wachtwoord", Gebruikersnaam = "unittest" }; Assert.ThrowsException <DuplicateNameException>(() => context.Insert(registereer)); }
public IActionResult Registreer(Registreren registreer) { aRepo.Registreren(registreer); return(Redirect("~/Account/Index")); }
public bool Registreren(Registreren registreren) { _context.Insert(registreren); return(true); }