public async Task GetTeacherTest() { //Arrange TeachersController teachersController = new TeachersController(_inMemoryDBContext); //Act ActionResult <Teacher> teacherItem = await teachersController.GetTeacher(1); //Assert Assert.IsTrue(teacherItem.Value.TeacherName == "Mr. Test Teacher"); }
public void GetTeacher_ShouldReturnBadRequest() { //Arrange testSchoolRegisterContext = new TestSchoolRegisterContext(); teacherRepo = new MockTeacherRepo(testSchoolRegisterContext); teachersController = new TeachersController(teacherRepo); //Act IHttpActionResult actionResult = teachersController.GetTeacher(null); //Assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestResult)); }
public void TestGetTeacher() { ExpectedTeachers expectedTeachers = new ExpectedTeachers(); List <Teacher> expected = expectedTeachers.GetTeachers(); string expectedSsn = expected[0].SSN; string expectedName = expected[0].name; string expectedSurname = expected[0].surname; ObjectResult result = (ObjectResult)teachersController.GetTeacher(expectedSsn).Result; int?statusCode = result.StatusCode; Assert.Equal(200, statusCode); Teacher teacher = (Teacher)result.Value; Assert.True(teacher.name == expectedName && teacher.surname == expectedSurname); }
public void GetTeacher_ShouldReturnForbidden() { //Arrange testSchoolRegisterContext = new TestSchoolRegisterContext(); teacherRepo = new MockTeacherRepo(testSchoolRegisterContext); teachersController = new TeachersController(teacherRepo); PopulateTeacherFields(); //Act var actionResult = teachersController.GetTeacher("unauthenticatedTeacherId") as ResponseMessageResult; //Assert Assert.IsNotNull(actionResult); Assert.AreEqual(actionResult.Response.StatusCode, HttpStatusCode.Forbidden); }
public void GetTeacher_ShouldReturnNotFound() { //Arrange testSchoolRegisterContext = new TestSchoolRegisterContext(); teacherRepo = new MockTeacherRepo(testSchoolRegisterContext); teachersController = new TeachersController(teacherRepo); PopulateTeacherFields(); //Act var actionResult = teachersController.GetTeacher("notExistingTeacherId"); //Assert Assert.IsNotNull(actionResult); Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult)); }
public void GetTeacher_ShouldReturnOk() { //Arrange testSchoolRegisterContext = new TestSchoolRegisterContext(); teacherRepo = new MockTeacherRepo(testSchoolRegisterContext); teachersController = new TeachersController(teacherRepo); PopulateTeacherFields(); //Act var actionResult = teachersController.GetTeacher("sampleTeacherId"); var contentResult = actionResult as OkNegotiatedContentResult <TeacherBasicDto>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual("sampleTeacherId", contentResult.Content.Id); }
public async Task PutTeacherTest() { //Arrange TeachersController teachersController = new TeachersController(_inMemoryDBContext); Teacher teacher = new Teacher(); teacher.TeacherName = "Señor Maestro"; teacher.TeacherKey = 1; //Act IActionResult putTeacheResult = await teachersController.PutTeacher(1, teacher); ActionResult <Teacher> newTeacher = await teachersController.GetTeacher(1); //Assert Assert.IsTrue(newTeacher.Value.TeacherName == "Señor Maestro"); }