public void Teachers_Controller_Test_On_Edit_With_Existent_Id() { //Arrange Guid id = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795"); string firstName = "TestF"; string lastName = "TestL"; string userName = "******"; string password = "******"; string emailAdress = "TestE"; Teacher expectedTeacher = new Teacher(firstName, lastName, userName, password, emailAdress); expectedTeacher.Id = id; var repo = Substitute.For <IRepository>(); var sut = new TeachersController(repo); repo.GetById <Teacher>(id).Returns(expectedTeacher); //Act var actual = sut.Edit(id).Result as ViewResult; //Assert Assert.IsInstanceOfType(actual, typeof(ViewResult)); var viewResult = actual; Assert.AreEqual(expectedTeacher, viewResult.Model); }
public void Teachers_Controller_Test_On_EditModel_With_Invalid_Id() { //Arrange Guid id = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795"); string firstName = "a"; string lastName = "TestL"; string userName = "******"; string password = "******"; string emailAdress = "TestE"; Teacher expectedTeacher = new Teacher(firstName, lastName, userName, password, emailAdress); expectedTeacher.Id = id; Guid faultId = new Guid("1e4966f0-68f7-4f24-9f4f-53d528787be5"); TeacherModel expectedModel = new TeacherModel(); expectedModel.EmailAddress = " "; var repo = Substitute.For <IRepository>(); var sut = new TeachersController(repo); repo.Update(expectedTeacher); //Act var actual = sut.Edit(faultId, expectedTeacher).Result; //Assert Assert.IsInstanceOfType(actual, typeof(NotFoundResult)); }
public void Teachers_Controller_Test_On_EditModel_With_Invalid_Model() { //Arrange Guid id = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795"); string firstName = "a"; string lastName = "TestL"; string userName = "******"; string password = "******"; string emailAdress = "TestE"; Teacher expectedTeacher = new Teacher(firstName, lastName, userName, password, emailAdress); expectedTeacher.Id = id; TeacherModel expectedModel = new TeacherModel(); expectedModel.EmailAddress = " "; var repo = Substitute.For <IRepository>(); var sut = new TeachersController(repo); repo.Update(expectedTeacher); //Act sut.ModelState.AddModelError("FirstName", "Firstname Required"); var actual = sut.Edit(id, expectedTeacher).Result; //Assert Assert.IsInstanceOfType(actual, typeof(ViewResult)); }
public void Teachers_Controller_Test_On_EditModel_With_Valid_Model() { //Arrange Guid id = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795"); string firstName = "TestF"; string lastName = "TestL"; string userName = "******"; string password = "******"; string emailAdress = "TestE"; Teacher expectedTeacher = new Teacher(firstName, lastName, userName, password, emailAdress); expectedTeacher.Id = id; var repo = Substitute.For <IRepository>(); var sut = new TeachersController(repo); repo.Update(expectedTeacher); //Act var actual = sut.Edit(id, expectedTeacher).Result; //Assert Assert.IsInstanceOfType(actual, typeof(RedirectToActionResult)); }
public async Task Edit_ShouldReturnAnonymousObject_WhenInvalidObjectPassed() { // Arrange var teacher = new Teacher() { LastName = "Brzeczyszczykiewicz", Email = "*****@*****.**" }; _controller.ModelState.AddModelError("FirstName", "Required"); // Act dynamic response = await _controller.Edit(teacher); var valueFromAnnonymous = response.Value.GetType().GetProperty("text").GetValue(response.Value, null); // Assert Assert.IsType <JsonResult>(response); Assert.NotNull(response); Assert.Equal("Invalid Techer model!", valueFromAnnonymous); }
public void Teachers_Controller_Test_On_Edit_With_NonExistent_Id() { //Arrange Guid id = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795"); var repo = Substitute.For <IRepository>(); var sut = new TeachersController(repo); repo.GetById <Teacher>(id); //Act var actual = sut.Edit(id).Result; //Assert Assert.IsInstanceOfType(actual, typeof(NotFoundResult)); }