public void RemoveBottle_Allparams_OK() { bool resExpected = true; bool resCalculated; resCalculated = Bottles.RemoveBottle(bottleToAdd.Name, bottleToAdd.BottleNumber, bottleToAdd.Volume, bottleToAdd.Manufacturer, bottleToAdd.Year); Assert.AreEqual(resExpected, resCalculated); }
private void btnDel_Click(object sender, EventArgs e) { //initializing variables to stock informations from the wine bottle string wineName = ""; string manufacturer = ""; int number = 0; double volume = 0; int year = 0; // initializing the boolean to check if everything is correct -> all is false by default, so that if it works, it changes to true bool successName = false; bool successManu = false; bool successNumber = false; bool successYear = false; bool successVolume = false; bool successFormat = false; bool successPresence = false; bool successOut = false; bool successAlert = false; bool successLog = false; /** * verification of data type * if a field is empty and shouldn't be -> the bottle won't get out */ if (comboWine.SelectedIndex != -1) { wineName = comboWine.SelectedItem.ToString(); successName = true; } if (comboVolumeOUT.SelectedIndex != -1) { successVolume = Double.TryParse(comboVolumeOUT.SelectedItem.ToString(), out volume); } if (comboManufacturerOUT.SelectedIndex != -1) { manufacturer = comboManufacturerOUT.SelectedItem.ToString(); successManu = true; } if (txtNumberOUT.Text != "") { successNumber = Int32.TryParse(txtNumberOUT.Text, out number); if (number < 1) { MessageBox.Show("Le nombre de bouteilles spécifié n'est pas valide."); txtNumberOUT.Text = ""; } } if (comboYearOUT.SelectedIndex != -1) { successYear = Int32.TryParse(comboYearOUT.SelectedItem.ToString(), out year); } //verify if the bottle to delete already exists in database -> true : present, false : non present // occur uniquely if the volume, the name and the year have been validated if (successVolume && successName && successYear) { successPresence = req.CheckBottlePresence(wineName, year, volume); } // if all verification are ok -> will be true, otherwise, will be false successFormat = successNumber && successYear && successName && successManu; successAlert = req.CheckAlertPresenceByBottleName(wineName); // all checks passed, bottle present in DB if (successFormat == true && successPresence) { if (successAlert) { MessageBox.Show("Attention, cette bouteille est prévue pour un évènement !!"); } successOut = Bottles.RemoveBottle(wineName, number, volume, manufacturer, year); // message box to show, depending on the result when getting the right number of bottle out if (successOut) { int wineID = req.GetIDBottleByName(wineName); successLog = Logs.AddLog("retrait", wineID); MessageBox.Show("Le retrait de bouteille(s) a été effectué correctement."); } else { MessageBox.Show("Une erreur est survenue lors du retrait de bouteille(s). Veuillez réessayer."); } } // all checks passed, but the combination of data does not concord with DB else if (successFormat == true && !successPresence) { MessageBox.Show("Cette combinaison de données n'existe pas dans les bouteilles présentes. Veuillez vérifier vos informations."); } // problems with at least 1 check else { MessageBox.Show("Une des valeurs spécifiées est incorrecte."); txtNumber.Text = ""; txtYear.Text = ""; } LoadData(); }