public void ValidResponseCreate() { MatchesController controller = new MatchesController(databaseContext); IActionResult result = controller.Create() as IActionResult; Assert.IsNotNull(result); }
public async void CreateButtonTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new MatchesController(db); var match = new Matches { Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1 }; //Act await c.Create(match); var r = c.Create(); //Assert Assert.IsType <ViewResult>(r); }
public async void EditWrongIdTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new MatchesController(db); var match = new Matches { Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1 }; //Act await c.Create(match); var r = await c.Edit(db.Matches.Find(1).Matche_Id, match); //Assert Assert.IsType <NotFoundResult>(r); }
public async void TestAddMatch() { //Arrange var db = MockDb.CreateMockDb(); var c = new MatchesController(db); var match = new Matches { Matche_Id = 2, HomeTeam_Id = 1, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1 }; //Act var r = await c.Create(match); //Assert var result = Assert.IsType <RedirectToActionResult>(r); Assert.Equal("Index", result.ActionName); Assert.Equal(1, db.Matches.Where(x => x.Matche_Id == match.Matche_Id && x.HomeTeam_Id == match.HomeTeam_Id && x.AwayTeam_Id == match.AwayTeam_Id && x.MatchDate == match.MatchDate && x.Stadium_Id == match.Stadium_Id).Count()); }
public async void DeleteConfirmTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new MatchesController(db); var match = new Matches { Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1 }; //Act var r = await c.Create(match); //Finds the second element stores in a tmp variable var elementToDelete = db.Matches.Find(2); await c.DeleteConfirmed(elementToDelete.Matche_Id); Assert.DoesNotContain(elementToDelete, db.Matches); }
public async void EditTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new MatchesController(db); int tempId = 1; var match = new Matches { Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1 }; //Act await c.Create(match); match.AwayTeam_Id = tempId; var r = await c.Edit(db.Matches.Find(2).Matche_Id, match); //Assert Assert.IsType <RedirectToActionResult>(r); Assert.Equal(db.Matches.Find(2).AwayTeam_Id, tempId); }
public async void DeletePageTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new MatchesController(db); var match = new Matches { Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1 }; //Act await c.Create(match); var r = await c.Delete(db.Matches.Find(2).Matche_Id); //Assert var result = Assert.IsType <ViewResult>(r); var model = Assert.IsAssignableFrom <Matches>(result.ViewData.Model); Assert.Equal(db.Matches.Find(2).Matche_Id, model.Matche_Id); Assert.Equal(db.Matches.Find(2).AwayTeam_Id, model.AwayTeam_Id); }
public async void CreatePageForEmptyAccountTest() { // Arrange const string userId = "MyUserId"; Context.Add(new ApplicationUser { Id = userId }); Context.SaveChanges(); var user = new ClaimsPrincipal( new[] { new ClaimsIdentity( new[] { new Claim(ClaimTypes.NameIdentifier, userId) }) }); var controller = new MatchesController(Context, UserManager, StringLocalizerMock.Object, InviteServiceMock.Object, LeaguesRepositoryMock.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } } }; // Act var result = await controller.Create(null); // Assert result.Should().BeOfType <RedirectToActionResult>().Which.ControllerName.Should().Be("Leagues"); result.Should().BeOfType <RedirectToActionResult>().Which.ActionName.Should().Be("NoLeagues"); }
public async void TestAddInvalidMatch() { //Arrange var db = MockDb.CreateMockDb(); var c = new MatchesController(db); var match = new Matches { Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1 }; c.ModelState.AddModelError("HomeTeam_Id", "Required"); //Act var r = await c.Create(match); //Assert var result = Assert.IsType <ViewResult>(r); var model = Assert.IsAssignableFrom <Matches>(result.ViewData.Model); Assert.Equal(match, model); Assert.IsType <SelectList>(result.ViewData["AwayTeam_Id"]); Assert.IsType <SelectList>(result.ViewData["HomeTeam_Id"]); Assert.IsType <SelectList>(result.ViewData["Stadium_Id"]); }
public async void EditModelStateNotValidTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new MatchesController(db); var match = new Matches { Matche_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1 }; //Act await c.Create(match); c.ModelState.AddModelError("AwayTeam_Id", "Required"); var r = await c.Edit(db.Matches.Find(2).Matche_Id, match); //Assert var result = Assert.IsType <ViewResult>(r); var model = Assert.IsAssignableFrom <Matches>(result.ViewData.Model); Assert.Equal(match, model); }