public void TestAddCorrectSchool() { bool isItemAdded = false; var repository = Mock.Create <IRepository <School> >(); var schoolModel = new SchoolModel() { Name = "PMG", Location = "Sofia" }; var schoolEntity = new School() { Id = 1, Name = schoolModel.Name, Location = schoolModel.Location }; Mock.Arrange(() => repository.Add(Arg.IsAny <School>())) .DoInstead(() => isItemAdded = true) .Returns(schoolEntity); var controller = new SchoolController(repository); SetupController.Create(controller, "post", "school"); var result = controller.PostSchool(schoolEntity); Assert.IsTrue(result.IsSuccessStatusCode); Assert.IsTrue(isItemAdded); }
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); }