public void DeleteGetStudentValidId() { //act var actual = ((ViewResult)controller.Delete(1)).Model; //assert Assert.AreEqual(students[0], actual); }
public async Task Delete_ShouldReturnAnonymousObject_WhenNonExistingIdPassed() { // Arrange var studentId = 0; // Act _repoMock.Setup(x => x.GetById(studentId)).ReturnsAsync((Student)null); dynamic result = await _controller.Delete(studentId); var valueFromAnnonymous = result.Value.GetType().GetProperty("text").GetValue(result.Value, null); // Assert Assert.NotNull(result); Assert.Equal("Student does not exists!", valueFromAnnonymous); }
public void Students_Controller_Test_On_Delete_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.Delete(id).Result as ViewResult; //Assert Assert.IsInstanceOfType(actual, typeof(ViewResult)); var viewResult = actual; Assert.AreEqual(expectedStudent, viewResult.Model); }
public void Delete_FailureTestCase_ThrowsException() { // Arrange string message = "student not found to Delete"; _mockStudentService.Setup(c => c.Delete(It.IsAny <string>(), out message)).Throws(new Exception()); StudentsController studentsController = new StudentsController(_mockStudentService.Object); studentsController.Request = new HttpRequestMessage(); studentsController.Configuration = new HttpConfiguration(); //Act HttpResponseMessage results = studentsController.Delete(It.IsAny <string>()); //Assert message = "Error in execution of API"; Assert.IsTrue(results.StatusCode == HttpStatusCode.BadRequest); Object responseContent; Assert.IsTrue(results.TryGetContentValue(out responseContent)); HttpError error = responseContent as HttpError; if (error != null) { string errorMessage = error.Message; string errorMessageDetail = error.MessageDetail; } Assert.IsTrue(error.Message == message); }
public void DeleteReturnsStudent() { //Arrange var context = new Mock <HttpContext>(); controller.ControllerContext = new ControllerContext { HttpContext = context.Object }; var identity = new Mock <ClaimsIdentity>(); context.SetupGet(c => c.User.Identity).Returns(identity.Object); string email = "*****@*****.**"; identity.Setup(i => i.FindFirst(ClaimTypes.Email)).Returns(new Claim("email", email)); people.Setup(p => p.Get(It.IsAny <long>())).ReturnsAsync(new Person { Email = email }); repository.Setup(r => r.Exists(It.IsAny <object[]>())).ReturnsAsync(true); repository.Setup(r => r.Delete(It.IsAny <object[]>())).ReturnsAsync(new Student()); //Act var result = (controller.Delete(1).Result as OkObjectResult).Value; //Assert Assert.IsInstanceOfType(result, typeof(Student)); }
public void StudentCanBeDelete() { DbContextOptions <Lab13StudentEnrollmentDbContext> options = new DbContextOptionsBuilder <Lab13StudentEnrollmentDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; using (Lab13StudentEnrollmentDbContext context = new Lab13StudentEnrollmentDbContext(options)) { Student student = new Student(); student.Name = "Bob"; student.Age = 24; student.CourseID = "cs201"; StudentsController sc = new StudentsController(context); var x = sc.Create(student); var retrieve = context.Students.Where(s => s.Name == "Bob").ToList(); ViewResult current = (ViewResult)sc.Details(retrieve[0].ID).Result; StudentDetailsViewModel test = (StudentDetailsViewModel)current.Model; Assert.Equal("Bob", test.Student.Name); x = sc.Delete(test.Student.ID); retrieve = context.Students.Where(s => s.Name == "Bob").ToList(); Assert.Empty(retrieve); } }
public void TestDelete_Failure_ReturnsBadRequest() { Student s2 = new Student { Id = "", studentID = "222222", firstName = "Jack", lastName = "Ryan", grade = "A", department = "Science" }; HttpResponseMessage results = _studentsController.Post(s2); List <Student> listStudents = _studentService.GetAll(); Assert.True(listStudents.Count == 1); Assert.True(CompareStudent(listStudents[0], s2)); //Try to create the same student document again string message = "Student not found to Delete"; results = _studentsController.Delete("123456"); Assert.IsTrue(results.StatusCode == HttpStatusCode.BadRequest); Object responseContent; Assert.IsTrue(results.TryGetContentValue(out responseContent)); HttpError error = responseContent as HttpError; if (error != null) { string errorMessage = error.Message; string errorMessageDetail = error.MessageDetail; } Assert.IsTrue(error.Message == message); //Cleanup Assert.IsTrue(_studentService.Delete(s2.studentID, out message)); }
public void Delete() { var student = new Student() { StudentID = 1, RefNo = string.Empty, FirstName = "John", LastName = "Smith", DateOfBirth = DateTime.Now.AddYears(-10), DateCreated = DateTime.Now }; _studentService.Setup(s => s.GetDetail(1)).Returns(student); var vr = _controller.Delete(1) as ViewResult; var model = vr.Model as Student; Assert.NotNull(vr); Assert.Equal(student.StudentID, model.StudentID); _studentService.Verify(); }
public void Delete_ShouldDeleteStudentByIdOkResult() { int testStudentDeletedId = 3; var controller = new StudentsController(studentDataProvider); var response = controller.Delete(testStudentDeletedId) as OkResult; Assert.IsNotNull(response); }
public void TestDeleteViewFail() { var controller = new StudentsController(); var result = controller.Delete(-1) as ViewResult; Assert.IsNotNull(result); Assert.IsNull(result.Model); }
public void Delete_ShouldDeleteStudentNotFoundResult() { int deletedStudentId = 10; var controller = new StudentsController(studentDataProvider); var response = controller.Delete(deletedStudentId) as NotFoundResult; Assert.IsNotNull(response); }
public void TestDeleteView() { var controller = new StudentsController(); var result = controller.Delete(2) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(2, ((Student)result.Model).Id); }
public void Delete_Valid_Detail() { StudentsRep loandata = new StudentsRep(db); StudentsController obj = new StudentsController(loandata); var data = obj.Delete(5); var okResult = data as OkObjectResult; Assert.AreEqual(200, okResult.StatusCode); }
public void StudentsDelete() { // Arrange StudentsController controller = new StudentsController(); // Act JsonResult result = controller.Delete(99999) as JsonResult; // Assert Assert.IsFalse(((JsonResultData)result.Data).isOK); }
public async Task DeleteStudentTest() { //Arrange var controller = new StudentsController(StudentServiceMock.Object); //Act var result = await controller.Delete(1); //Assert result.Should().NotBeNull(); result.Should().BeOfType <NoContentResult>(); }
public void Students_Controller_Test_On_Delete_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.Delete(id).Result; //Assert Assert.IsInstanceOfType(actual, typeof(NotFoundResult)); }
public void Students_Controller_Test_On_Delete_With_Null_Id() { //Arrange var id = Guid.Empty; var repo = Substitute.For <IRepository>(); var sut = new StudentsController(repo); repo.GetById <Student>(id); //Act var actual = sut.Delete(id).Result; //Assert Assert.IsInstanceOfType(actual, typeof(NotFoundResult)); }
public static void Menu() { Console.WriteLine("\nSelect following options \n"); bool terminate = true; do { Console.WriteLine("1.Add student \n2.Get a list of students \n3.Update a student \n4.Delete a student \n5.Exit program"); bool loopState = true; while (loopState) { switch (int.TryParse(Console.ReadLine(), out int value) ? value : 0) { case (int)HomeMenu.Create: StudentsController.Create(); loopState = false; break; case (int)HomeMenu.Read: Console.Clear(); Console.WriteLine("List of students\n"); StudentsController.Read(); loopState = false; break; case (int)HomeMenu.Update: StudentsController.Update(int.Parse(Utility.Ask("Select student by ID", Student.DefaultValueId))); loopState = false; break; case (int)HomeMenu.Delete: StudentsController.Delete(int.Parse(Utility.Ask("Select a student to delete by Student ID", Student.DefaultValueId))); loopState = false; break; case (int)HomeMenu.Exit: loopState = false; terminate = false; break; default: Console.WriteLine("Please choose between 1-5 again"); break; } } } while (terminate); }
public void Delete_SuccessfulTestCase() { // Arrange string message = null; _mockStudentService.Setup(c => c.Delete(It.IsAny <string>(), out message)).Returns(true); StudentsController studentsController = new StudentsController(_mockStudentService.Object); studentsController.Request = new HttpRequestMessage(); studentsController.Configuration = new HttpConfiguration(); //Act HttpResponseMessage results = studentsController.Delete(It.IsAny <string>()); //Assert Assert.IsTrue(results.StatusCode == HttpStatusCode.OK); }
static void TestConnection() { var connection = new Connection("localhost", "sqlexpress", "EdDb"); var studentsCtrl = new StudentsController(connection); var newStudent = new Student() { Firstname = "Frederick", Lastname = "Flintstone", StateCode = "SA", SAT = 1000, GPA = 2.5M, MajorId = null }; //var itWorked = studentsCtrl.Insert(newStudent); var fred = new Student(61) { Firstname = "Fred", Lastname = "Flintstone", StateCode = "SA", SAT = 1000, GPA = 2.5M, MajorId = null }; var itWorked = studentsCtrl.Update(fred); itWorked = studentsCtrl.Delete(61); var student = studentsCtrl.GetByPK(10); var noStudent = studentsCtrl.GetByPK(-1); var students = studentsCtrl.GetAll(); connection.Close(); }
public async Task Delete_ReturnsANotFoundResult(int?id) { var result = await sut.Delete(id); Assert.Equal(404, ((NotFoundResult)result).StatusCode); }