public void TestRegistraUtente() { Utente utente = new UtenteNormale { Nome = "tizio", Cognome = "caio", Email = "*****@*****.**", LoginRemoto = true, Username = "******" }; utente.ImpostaPasswordDaOriginale("password"); // Verifico che non esista Assert.IsNull(gestioneUtentiController.ValidaCredenziali("tizio", "password")); // Lo registro, e verifico che adesso esiste Assert.IsTrue(gestioneUtentiController.Registra(utente)); IUtente utenteValidato = gestioneUtentiController.ValidaCredenziali("tizio", "password"); Assert.IsNotNull(utenteValidato); // Mi assicuro che sia del tipo giusto Assert.IsInstanceOfType(utenteValidato, typeof(UtenteNormale), "L'utente è di tipo sbagliato"); }
private void btnCrea_Click(object sender, EventArgs e) { String error = validation(); if (error != null) { MessageBox.Show("Il campo " + error + " non è corretto", "Inserimento dati non valido", MessageBoxButtons.OK); return; } Utente utente; if (checkboxAmm.Checked) { utente = new Amministratore { Nome = inputNome.Text, Cognome = inputCognome.Text, Email = inputEmail.Text, LoginRemoto = checkboxLoginRemoto.Checked, Username = inputUsername.Text } } ; else { utente = new UtenteNormale { Nome = inputNome.Text, Cognome = inputCognome.Text, Email = inputEmail.Text, LoginRemoto = checkboxLoginRemoto.Checked, Username = inputUsername.Text } }; utente.ImpostaPasswordDaOriginale(inputPassword.Text); bool res = Controller.Registra(utente); if (res) { this.ParentForm.DialogResult = DialogResult.Abort; } else { this.ParentForm.DialogResult = DialogResult.OK; } }