public async Task GetTeachers_ShouldReturnAnonymousObject_WhenQueryFromDbIsNullOrListLenIs0() { //Arrange List <Teacher> teachers = new List <Teacher>(); var mock = teachers.AsQueryable().BuildMock(); _repoMock.Setup(x => x.GetAll()).Returns(mock.Object); ////Act var result = await _controller.GetTeachers(); var valueFromAnnonymous = result.Value.GetType().GetProperty("text").GetValue(result.Value, null); ////Assert Assert.NotNull(result); Assert.Equal("No teachers found!", valueFromAnnonymous); }
public async Task GetTeachersTest() { //Arrange TeachersController teachersController = new TeachersController(_inMemoryDBContext); //Act ActionResult <IEnumerable <Teacher> > teacherList = await teachersController.GetTeachers(); //Assert Assert.IsTrue(teacherList.Value.Count <Teacher>() >= 2); }
public async Task PostTeacherTest() { //Arrange TeachersController teachersController = new TeachersController(_inMemoryDBContext); ActionResult <IEnumerable <Teacher> > _teacherList = await teachersController.GetTeachers(); int startingCount = _teacherList.Value.Count <Teacher>(); Teacher teacher = new Teacher(); teacher.TeacherName = "Señora Maestra"; //Act ActionResult <Teacher> newTeacher = await teachersController.PostTeacher(teacher); //Assert CreatedAtActionResult postResult = (CreatedAtActionResult)newTeacher.Result; Teacher createdTeacher = (Teacher)postResult.Value; Assert.IsTrue(createdTeacher.TeacherKey > startingCount); }