public async void TestCreate() { //Arrange var c = new Competition { Id = 1, Name = "Vorhlaup", Description = "Um vorhlaupid", Email = "*****@*****.**", Phone = "5551234", Sponsor = "", WebPage = "vorhlaup.is" }; var cMod = new CompetitionsViewModel { Name = "Vorhlaup", Description = "Um vorhlaupid", Email = "*****@*****.**", PhoneNumber = "5551234", Sponsor = "", WebPage = "vorhlaup.is" }; var serviceMock = new Mock <ICompetitionService>(); serviceMock.Setup(x => x.AddAsync(cMod)).Returns(Task.FromResult(c)); var controller = new CompetitionController(serviceMock.Object); //Act var result = await controller.Create(cMod) as RedirectToActionResult; //Assert Assert.Equal(expected: "Competitions", actual: result.ActionName); }
public void CreateTestView() { var controller = new CompetitionController(); var result = controller.Create() as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("", result.ViewName); }
public void CreateByPOST_WhenDoesNotReceiveANameForTheCompetition_AddNewCompetitionToRepositoryWithARandomName() { var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession <Competition>() }; var controller = new CompetitionController(); controller.CompetitionRepository = competitionRepository; controller.Create(new CreateCompetitionModel()); Assert.AreEqual(1, competitionRepository.Count); var compCreated = competitionRepository[0]; Assert.IsNotNull(compCreated.Name); }
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 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"]); }