// ToDo: Figure out why the mock setup for SchoolRepository.DeleteSchool() is not being mocked correctly //[TestMethod] public void DeleteSchool() { // Arrange var school = DataSeeder.SchoolSeeder.Objects[0]; Mock.Get(_repositoryWrapper.School).Setup(x => x.DeleteSchool(school)); Mock.Get(_repositoryWrapper.School).Setup(x => x.GetSchoolById(school.Id)).ReturnsAsync(school); Mock.Get(_repositoryWrapper.SchoolStudent).Setup(x => x.SchoolStudentsBySchool(school.Id)).ReturnsAsync(new List <SchoolStudent>()); var controller = new SchoolController(_loggerManager, _mapper, _repositoryWrapper); // Act var actionResult = controller.DeleteSchool(school.Id).Result; // Assert var noContentResult = actionResult as NoContentResult; Assert.IsNotNull(noContentResult); }
public void TestDeleteSchool() { bool isItemDeleted = false; bool isItemAdded = false; var repository = Mock.Create <IRepository <School> >(); var schoolModel = new SchoolModel() { Location = "sofia", Name = "HMG" }; var schoolEntity = new School() { Id = 1, Location = schoolModel.Location, Name = schoolModel.Name }; Mock.Arrange(() => repository.Add(Arg.IsAny <School>())) .DoInstead(() => isItemAdded = true) .Returns(schoolEntity); var controller = new SchoolController(repository); SetupController.Create(controller, "post", "school"); controller.PostSchool(schoolEntity); Mock.Arrange(() => repository.Delete(Arg.IsAny <School>())) .DoInstead(() => isItemDeleted = true); SetupController.Create(controller, "delete", "school"); controller.DeleteSchool(schoolEntity.Id); Assert.IsFalse(isItemDeleted); }