public void Index_AvecSondageNormalMaisSansUtilisateur_RenvoiLeBonViewModelEtAfficheLaVue() { ViewResult view = (ViewResult)controleur.Index(idSondage); RestaurantVoteViewModel viewModel = (RestaurantVoteViewModel)view.Model; Assert.AreEqual(3, viewModel.ListeDesResto.Count); Assert.AreEqual(1, viewModel.ListeDesResto[0].Id); Assert.IsFalse(viewModel.ListeDesResto[0].EstSelectionne); Assert.AreEqual("Resto pinambour (0102030405)", viewModel.ListeDesResto[0].NomEtTelephone); }
public void IndexPost_AvecViewModelValideEtUtilisateur_AppelleBienAjoutVoteEtRenvoiBonneAction() { Mock <IDal> mock = new Mock <IDal>(); mock.Setup(m => m.ObtenirUtilisateur("1")).Returns(new Utilisateur { Id = 1, Prenom = "Nico" }); Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); controllerContext.Setup(p => p.HttpContext.User.Identity.Name).Returns("1"); controleur = new VoteController(mock.Object); controleur.ControllerContext = controllerContext.Object; RestaurantVoteViewModel viewModel = new RestaurantVoteViewModel { ListeDesResto = new List <RestaurantCheckBoxViewModel> { new RestaurantCheckBoxViewModel { EstSelectionne = true, Id = 2, NomEtTelephone = "Resto pinière (0102030405)" }, new RestaurantCheckBoxViewModel { EstSelectionne = false, Id = 3, NomEtTelephone = "Resto toro (0102030405)" }, } }; controleur.ValideLeModele(viewModel); RedirectToRouteResult resultat = (RedirectToRouteResult)controleur.Index(viewModel, idSondage); mock.Verify(m => m.AjouterVote(idSondage, 2, 1)); Assert.AreEqual("AfficheResultat", resultat.RouteValues["action"]); Assert.AreEqual(idSondage, resultat.RouteValues["id"]); }
public void Can_View_Cart_Contents() { votes = new VoteResults(); VoteController target = new VoteController(null, null, null); VotesViewModel result = (VotesViewModel)target.Index(votes, "myUrl").ViewData.Model; // Assert Assert.AreSame(result.Votes, votes); Assert.AreEqual(result.ReturnUrl, "myUrl"); }