public void validateMotherboard() { Motherboard motherboard = new Motherboard(); MotherboardValidator validator = new MotherboardValidator(); motherboard.Description = "Dies ist ein Test"; motherboard.Inch = 24.2; motherboard.Socket = "!$%&§&"; Assert.AreEqual(false, validator.CheckConsistency(motherboard)); }
/// <summary> /// Ruft die Informationen aus dem Formular ab und speichert sie in die Datenbank. /// Wirft eine Fehlermeldung, wenn die Validierung fehlschlägt. /// </summary> private void MainboardSave_Click(object sender, RoutedEventArgs e) { ProducerDataAccess dataProducer = new ProducerDataAccess(); MotherboardDataAccess diskDataAccess = new MotherboardDataAccess(); MotherboardValidator validator = new MotherboardValidator(); try { this.setEntityWithFormData(dataProducer); if (!validator.CheckConsistency(this.entity)) { ErrorHandler.ShowErrorMessage("Validierung fehlgeschlagen", ErrorHandler.VALIDATION_FAILED); } else { if (this.isAvailable) diskDataAccess.Update(this.entity); else diskDataAccess.Save(this.entity); this.Close(); } } catch (FormatException exception) { ErrorHandler.ShowErrorMessage(exception, ErrorHandler.WRONG_FORMAT); } catch (MySql.Data.MySqlClient.MySqlException exception) { ErrorHandler.ShowErrorMessage(exception, ErrorHandler.SAVE_WENT_WRONG); } catch (System.OverflowException exception) { ErrorHandler.ShowErrorMessage(exception, ErrorHandler.DATA_TOO_LONG); } }