public TypeAdhesion GetTypeAdhesion(int id) { string connectionString = Initialisation.InitialiserConnexion(); TypeAdhesion leTypeAdhesion = null; using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); string query = "SELECT idTypeAdhesion, libelle, tarif from typeadhesion WHERE idTypeAdhesion = @id; "; //Create Command MySqlCommand cmd = new MySqlCommand(query, connection); cmd.Parameters.AddWithValue("@id", id); //Crée un data reader et exécute la commande using (MySqlDataReader dataReader = cmd.ExecuteReader()) { //Lit les données while (dataReader.Read()) { int idType = Convert.ToInt32(dataReader["idTypeAdhesion"]); string nom = dataReader["Libelle"].ToString(); int tarif = Convert.ToInt32(dataReader["Tarif"]); leTypeAdhesion = new TypeAdhesion(idType, nom, tarif); } } } return leTypeAdhesion; }
public void TestReductionTarif1() { TypeAdhesion t = new TypeAdhesion(1, "loisir", 12); //On applique une réduction de 20% au tarif. t.ReductionTarif(20); //le tarif doit maintenant être égal à 10 en arrondissant. Assert.AreEqual(t.Tarif, 10); }