Exemple #1
0
 public void ModifierRestaurant(int id, string nom, string telephone)
 {
     Resto.Models.Resto resto = listeDesRestaurants.FirstOrDefault(r => r.Id == id);
     if (resto != null)
     {
         resto.Nom       = nom;
         resto.Telephone = telephone;
     }
 }
        public void RestaurantController_ModifierRestaurantAvecRestoInvalideEtBindingDeModele_RenvoiVueParDefaut()
        {
            RestaurantController controller = new RestaurantController(new DalEnDur());

            Resto.Models.Resto resto = new Resto.Models.Resto {
                Id = 1, Nom = null, Telephone = "0102030405"
            };
            controller.ValideLeModele(resto);

            ViewResult resultat = (ViewResult)controller.ModifierRestaurant(resto);

            Assert.AreEqual(string.Empty, resultat.ViewName);
            Assert.IsFalse(resultat.ViewData.ModelState.IsValid);
        }
Exemple #3
0
        public List <Resultats> ObtenirLesResultats(int idSondage)
        {
            List <Resto.Models.Resto> restaurants = ObtientTousLesRestaurants();
            List <Resultats>          resultats   = new List <Resultats>();
            Sondage sondage = listeDessondages.First(s => s.Id == idSondage);

            foreach (IGrouping <int, Vote> grouping in sondage.Votes.GroupBy(v => v.Resto.Id))
            {
                int idRestaurant         = grouping.Key;
                Resto.Models.Resto resto = restaurants.First(r => r.Id == idRestaurant);
                int nombreDeVotes        = grouping.Count();
                resultats.Add(new Resultats {
                    Nom = resto.Nom, Telephone = resto.Telephone, NombreDeVotes = nombreDeVotes
                });
            }
            return(resultats);
        }
        public void RestaurantController_ModifierRestaurantAvecRestoValide_CreerRestaurantEtRenvoiVueIndex()
        {
            using (IDal dal = new DalEnDur())
            {
                RestaurantController controller = new RestaurantController(dal);
                Resto.Models.Resto   resto      = new Resto.Models.Resto {
                    Id = 1, Nom = "Resto mate", Telephone = "0102030405"
                };
                controller.ValideLeModele(resto);

                RedirectToRouteResult resultat = (RedirectToRouteResult)controller.ModifierRestaurant(resto);

                Assert.AreEqual("Index", resultat.RouteValues["action"]);
                Resto.Models.Resto restoTrouve = dal.ObtientTousLesRestaurants().First();
                Assert.AreEqual("Resto mate", restoTrouve.Nom);
            }
        }