public void CreateByPOST_WhenExecuteCorrectly_AddNewCompetitionToRepository() { var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() }; var createCompetitionModel = new CreateCompetitionModel(); createCompetitionModel.Name = "name"; var controller = new CompetitionController(); controller.CompetitionRepository = competitionRepository; controller.Create(createCompetitionModel); Assert.AreEqual(1, competitionRepository.Count); var compCreated = competitionRepository[0]; Assert.AreEqual(createCompetitionModel.Name, compCreated.Name); }
public ActionResult Create(CreateCompetitionModel formModel) { var newCompetition = new Competition(); newCompetition.Name = formModel.Name; if(string.IsNullOrEmpty(newCompetition.Name)) { var randomKey = Guid.NewGuid(); newCompetition.Name = randomKey.ToString(); } CompetitionRepository.Add(newCompetition); TempData["InformationMessage"] = "The competition was successfully created. Now you can add participants and checkpoints to your competition."; return RedirectToAction("Details",new {id = newCompetition.Name}); }
public void CreateByPOST_WhenExecuteCorrectly_RedirectToDetailsOfTheNewCompetition() { var createCompetitionModel = new CreateCompetitionModel(); createCompetitionModel.Name = "competitionName"; var controller = new CompetitionController(); controller.CompetitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() }; var actionResult = controller.Create(createCompetitionModel); var redirectToRouteResult= actionResult as RedirectToRouteResult; Assert.IsNotNull(redirectToRouteResult); Assert.AreEqual("Details", redirectToRouteResult.RouteValues["action"]); Assert.AreEqual(createCompetitionModel.Name, redirectToRouteResult.RouteValues["id"]); Assert.AreEqual("The competition was successfully created. Now you can add participants and checkpoints to your competition.", controller.TempData["InformationMessage"]); }