public async void CreateButtonTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new StadiumsController(db); var stadiums = new Stadium { Stadium_Id = 2, StadiumName = "Ever After", City = "Everett", Team_Id = 1 }; //Act await c.Create(stadiums); var r = c.Create(); //Assert Assert.IsType <ViewResult>(r); }
public async void EditWrongIdTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new StadiumsController(db); var stadiums = new Stadium { Stadium_Id = 2, StadiumName = "Ever After", City = "Everett", Team_Id = 1 }; //Act await c.Create(stadiums); var r = await c.Edit(db.Stadium.Find(1).Stadium_Id, stadiums); //Assert Assert.IsType <NotFoundResult>(r); }
public async void DeleteConfirmTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new StadiumsController(db); var stadiums = new Stadium { Stadium_Id = 2, StadiumName = "Ever After", City = "Everett", Team_Id = 1 }; //Act var r = await c.Create(stadiums); //Finds the second element stores in a tmp variable var elementToDelete = db.Stadium.Find(2); await c.DeleteConfirmed(elementToDelete.Stadium_Id); Assert.DoesNotContain(elementToDelete, db.Stadium); }
public async void TestAddStadium() { //Arrange var db = MockDb.CreateMockDb(); var c = new StadiumsController(db); var stadiums = new Stadium { Stadium_Id = 2, StadiumName = "Ever After", City = "Everett", Team_Id = 1 }; //Act var r = await c.Create(stadiums); //Assert var result = Assert.IsType <RedirectToActionResult>(r); Assert.Equal("Index", result.ActionName); Assert.Equal(1, db.Stadium.Where(x => x.Stadium_Id == stadiums.Stadium_Id && x.StadiumName == stadiums.StadiumName && x.City == stadiums.City && x.Team_Id == stadiums.Team_Id).Count()); }
public async void EditTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new StadiumsController(db); string tempName = "ScotiaBank Arena"; var stadiums = new Stadium { Stadium_Id = 2, StadiumName = "Ever After", City = "Everett", Team_Id = 1 }; //Act await c.Create(stadiums); stadiums.StadiumName = tempName; var r = await c.Edit(db.Stadium.Find(2).Stadium_Id, stadiums); //Assert Assert.IsType <RedirectToActionResult>(r); Assert.Equal(db.Stadium.Find(2).StadiumName, tempName); }
public async void DeletePageTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new StadiumsController(db); var stadiums = new Stadium { Stadium_Id = 2, StadiumName = "Ever After", City = "Everett", Team_Id = 1 }; //Act await c.Create(stadiums); var r = await c.Delete(db.Stadium.Find(2).Stadium_Id); //Assert var result = Assert.IsType <ViewResult>(r); var model = Assert.IsAssignableFrom <Stadium>(result.ViewData.Model); Assert.Equal(db.Stadium.Find(2).Stadium_Id, model.Stadium_Id); Assert.Equal(db.Stadium.Find(2).StadiumName, model.StadiumName); }
public async void TestAddInvalidStadium() { //Arrange var db = MockDb.CreateMockDb(); var c = new StadiumsController(db); var stadiums = new Stadium { Stadium_Id = 2, City = "Everett", Team_Id = 2 }; c.ModelState.AddModelError("StadiumName", "Required"); //Act var r = await c.Create(stadiums); //Assert var result = Assert.IsType <ViewResult>(r); var model = Assert.IsAssignableFrom <Stadium>(result.ViewData.Model); Assert.Equal(stadiums, model); Assert.IsType <SelectList>(result.ViewData["Team_Id"]); }
public async void EditModelStateNotValidTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new StadiumsController(db); var stadiums = new Stadium { Stadium_Id = 2, City = "Everett", Team_Id = 1 }; //Act await c.Create(stadiums); c.ModelState.AddModelError("StadiumName", "Required"); var r = await c.Edit(db.Stadium.Find(2).Stadium_Id, stadiums); //Assert var result = Assert.IsType <ViewResult>(r); var model = Assert.IsAssignableFrom <Stadium>(result.ViewData.Model); Assert.Equal(stadiums, model); }