public void SoftDelete_WhenCalled_CourseWillBeRemoved() { // Arrange var computerLab = TestDataApi.CloneCourse(TestDataApi.computerLab); courseService.Setup(m => m.Get(It.IsAny <int>())) .Returns(computerLab); courseService.Setup(m => m.Trash(It.IsAny <Course>())) .Callback((Course c) => { c.IsDeleted = true; }); var id = 4; var controller = new CoursesController(courseService.Object, courseTypeService.Object); TestHelper.SetUpControllerRequest(controller, "courses"); // Act var actionResult = controller.Trash(id); var okResult = actionResult as OkResult; // Assert courseService.Verify(m => m.Get(It.IsAny <int>())); courseService.Verify(m => m.Trash(It.IsAny <Course>())); Assert.That(okResult, Is.Not.Null); Assert.That(computerLab.IsDeleted, Is.True); }
public void Put_WhenCalled_CourseWillBeUpdated() { // Arrange var computerLab = TestDataApi.CloneCourse(TestDataApi.computerLab); var courseForm = new CourseDto { Id = computerLab.Id, Name = "Cyber Security Workshop", CourseTypeId = 2 }; courseService.Setup(m => m.Get(It.IsAny <int>())) .Returns(computerLab); courseService.Setup(m => m.Update(It.IsAny <Course>())) .Callback((Course c) => computerLab = c); var id = 4; var controller = new CoursesController(courseService.Object, courseTypeService.Object); TestHelper.SetUpControllerRequest(controller, "courses"); // Act var actionResult = controller.Put(id, courseForm); var okResult = actionResult as OkResult; // Assert courseService.Verify(m => m.Get(It.IsAny <int>())); courseService.Verify(m => m.Update(It.IsAny <Course>())); Assert.That(okResult, Is.Not.Null); Assert.That(computerLab.Name, Is.EqualTo("Cyber Security Workshop")); }
public void Get_WhenCalled_ReturnsListOfCourses() { // Arrange courseService.Setup(m => m.GetAll()) .Returns(TestDataApi.GetCourses()); var controller = new CoursesController(courseService.Object, courseTypeService.Object); TestHelper.SetUpControllerRequest(controller, "Course"); // Act var actionResult = controller.Get(); var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <CourseDto> >; var courseNames = contentResult.Content.Select(c => c.Name); // Assert courseService.Verify(m => m.GetAll()); Assert.That(contentResult, Is.Not.Null); Assert.That(contentResult.Content, Is.Not.Null); Assert.That(courseNames, Has.Exactly(1).EqualTo(TestDataApi.CloneCourse(TestDataApi.computerLab).Name)); }