public void getGraphicCardFromDatabase() { GraphicCardDataAccess dataAccess = new GraphicCardDataAccess(); ProducerDataAccess producerDataAccess = new ProducerDataAccess(); PhysicalInterfaceDataAccess physicalInterfaceDataAccess = new PhysicalInterfaceDataAccess(); GraphicCard graphicCard = new GraphicCard(); graphicCard.Description = "Dies ist ein Test"; graphicCard.ClockRate = 5; graphicCard.Model = "GTX1234"; graphicCard.Memory = 2000; graphicCard.Producer = producerDataAccess.GetLastEntity<Producer>(); graphicCard.AddPhysicalInterface(new PhysicalInterfaceWithCount(physicalInterfaceDataAccess.GetLastEntity<PhysicalInterface>(), 3)); dataAccess.Save(graphicCard); GraphicCard dbGraphicCard = dataAccess.GetLastEntity<GraphicCard>(); Assert.AreEqual(graphicCard.Description, dbGraphicCard.Description); }
/// <summary> /// Ruft die Informationen aus dem Formular ab und speichert sie in die Datenbank. /// Führt eine Umrechnung in MB aus und wirft eine Fehlermeldung, wenn die Validierung /// fehlschlägt. /// </summary> private void GraphicSave_Click(object sender, RoutedEventArgs e) { GraphicCardDataAccess dataGraphicModel = new GraphicCardDataAccess(); ProducerDataAccess dataProducer = new ProducerDataAccess(); GraphicCardValidator validator = new GraphicCardValidator(); try { this.setEntityWithFormData(dataProducer); if (!validator.CheckConsistency(this.entity)) { ErrorHandler.ShowErrorMessage("Validierung fehlgeschlagen", ErrorHandler.VALIDATION_FAILED); } else { if (isAvailable) dataGraphicModel.Update(this.entity); else dataGraphicModel.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); } }