public async Task Edit_ReturnsANotFoundResult(int?id) { var result = await sut.Edit(id); Assert.IsType <NotFoundResult>(result); Assert.Equal(404, ((NotFoundResult)result).StatusCode); }
public void EditGetStudentValidId() { //act var actual = ((ViewResult)controller.Edit(1)).Model; //assert Assert.AreEqual(students[0], actual); }
public async Task TestingUpdateStudentDetails() { //InitializeDatabaseWithDataTest(); StudentsController controller = new StudentsController(_context); string studentIndex = _context.Students.Where(s => s.UserFullname.Equals("Random user")).FirstOrDefault().Id; var user = new Student { UserName = "******", UserFullname = "New Random user", Email = "random@random", UserCc = "123456789", PhoneNumber = "936936999", UserAddress = "Avenida random", PostalCode = "2912-200", BirthDate = new DateTime(1995, 3, 2), StudentNumber = "987987987", ALOGrade = 20, CollegeSubjectId = 1, Id = studentIndex }; // Act var result = await controller.Edit(studentIndex, user); // Assert /*var viewResult = Assert.IsType<RedirectToActionResult>(result); * var model = Assert.IsAssignableFrom<IEnumerable<Student>>( * viewResult.RouteValues);*/ Assert.Equal(20, _context.Students.Where(m => m.Id == studentIndex).First().ALOGrade); }
public void Students_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"; Student expectedStudent = new Student(firstName, lastName, userName, password, emailAdress); expectedStudent.Id = id; Guid faultId = new Guid("1e4966f0-68f7-4f24-9f4f-53d528787be5"); StudentModel expectedModel = new StudentModel(); expectedModel.EmailAddress = " "; var repo = Substitute.For <IRepository>(); var sut = new StudentsController(repo); repo.Update(expectedStudent); //Act var actual = sut.Edit(faultId, expectedStudent).Result; //Assert Assert.IsInstanceOfType(actual, typeof(NotFoundResult)); }
public void Students_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"; Student expectedStudent = new Student(firstName, lastName, userName, password, emailAdress); expectedStudent.Id = id; var repo = Substitute.For <IRepository>(); var sut = new StudentsController(repo); repo.GetById <Student>(id).Returns(expectedStudent); //Act var actual = sut.Edit(id).Result as ViewResult; //Assert Assert.IsInstanceOfType(actual, typeof(ViewResult)); var viewResult = actual; Assert.AreEqual(expectedStudent, viewResult.Model); }
public void Students_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"; Student expectedStudent = new Student(firstName, lastName, userName, password, emailAdress); expectedStudent.Id = id; var repo = Substitute.For <IRepository>(); var sut = new StudentsController(repo); repo.Update(expectedStudent); //Act var actual = sut.Edit(id, expectedStudent).Result; //Assert Assert.IsInstanceOfType(actual, typeof(RedirectToActionResult)); }
public void Students_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"; Student expectedStudent = new Student(firstName, lastName, userName, password, emailAdress); expectedStudent.Id = id; StudentModel expectedModel = new StudentModel(); expectedModel.EmailAddress = " "; var repo = Substitute.For <IRepository>(); var sut = new StudentsController(repo); repo.Update(expectedStudent); //Act sut.ModelState.AddModelError("FirstName", "Firstname Required"); var actual = sut.Edit(id, expectedStudent).Result; //Assert Assert.IsInstanceOfType(actual, typeof(ViewResult)); }
public async Task UpdateView_ReturnsAViewResult_WithData() { // Arrange var model = new Student() { Id = 1, Faculty = "AMI", Group = new Group { Name = "AMI31" }, GroupId = 1, UserId = "1" }; var mockLogic = new Mock <IStudentsLogic>(); int studentId = 1; mockLogic.Setup(repo => repo.GetStudent(studentId)).Returns(Task.FromResult(model)); var controller = new StudentsController(mockLogic.Object); // Act IActionResult actionResult = await controller.Edit(studentId, model); // Assert var viewResult = Assert.IsType <RedirectToActionResult>(actionResult); mockLogic.Verify(repo => repo.UpdateStudent(model), Times.Once); }
public void TestEditView() { var controller = new StudentsController(); var result = controller.Edit(2) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(2, ((Student)result.Model).Id); }
public void TestEditViewFail() { var controller = new StudentsController(); var result = controller.Edit(-1) as ViewResult; Assert.IsNotNull(result); Assert.IsNull(result.Model); }
public void StudentsEdit() { // Arrange StudentsController controller = new StudentsController(); // Act ViewResult result = controller.Edit(999999) as ViewResult; // Assert Assert.IsNull(result); }
public void Edit() { var student = new Student() { StudentID = 1, RefNo = string.Empty, FirstName = "John", LastName = "Smith", DateOfBirth = DateTime.Now.AddYears(-10), DateCreated = DateTime.Now, CampusID = 1 }; _studentService.Setup(s => s.GetDetail(1)).Returns(student); var vr = _controller.Edit(1) as ViewResult; Assert.NotNull(vr); var model = vr.Model as ViewModels.StudentViewModel; Assert.Equal(student.StudentID, model.Student.StudentID); Assert.Equal(student.FirstName, model.Student.FirstName); _studentService.Verify(); }
public async Task Edit_ShouldReturnAnonymousObject_WhenInvalidObjectPassed() { // Arrange var course = new Student() { LastName = "Advanced", Email = "*****@*****.**" }; _controller.ModelState.AddModelError("FirstName", "Required"); // Act var response = await _controller.Edit(course); dynamic responseFromTask = response; var valueFromAnnonymous = responseFromTask.Value.GetType().GetProperty("text").GetValue(responseFromTask.Value, null); // Assert Assert.IsType <JsonResult>(response); Assert.NotNull(response); Assert.Equal("Invalid Student model!", valueFromAnnonymous); }
public void Students_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 StudentsController(repo); repo.GetById <Student>(id); //Act var actual = sut.Edit(id).Result; //Assert Assert.IsInstanceOfType(actual, typeof(NotFoundResult)); }
public void GetStudentByIdShouldReturnSingleStudentSuccess() { //Arrange var NewID = new Guid(); moqStudents.Setup(repo => repo.GetById(NewID)).Returns(MocGetStudentsById(NewID)); // Act var result = studentsController.Edit(NewID).Result; //Assert var viewResult = result as PartialViewResult; var model = viewResult.Model as Student; Assert.Multiple(() => { Assert.IsInstanceOf <PartialViewResult>(result); Assert.That(model, Is.TypeOf <Student>()); }); }