public void Remove_WhenShiftExists_ThenShiftShouldBeReturned() { // Arrange var mockedRepository = new Mock <IRepository>(); var mockedPublisher = new Mock <IMessagePublisher>(); mockedRepository.Setup(m => m.RemoveShift(It.IsAny <int>())).Returns(Task.FromResult(RemoveShiftStatus.Ok)); var controller = new ShiftController(mockedRepository.Object, mockedPublisher.Object); // Act var result = controller.RemoveAsync(1); var okResult = result.Result as OkResult; // Assert Assert.IsNotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); mockedPublisher.Verify(m => m.SendMessageShiftRemoved(It.IsAny <Shift>()), Times.Once); }
public void Remove_WhenShiftDoesNotExist_ThenExceptionShouldBeReturned() { // Arrange var mockedPublisher = new Mock <IMessagePublisher>(); var mockedRepository = new Mock <IRepository>(); mockedRepository.Setup(m => m.RemoveShift(It.IsAny <int>())) .Returns(Task.FromResult(RemoveShiftStatus.RecordDoesNotExist)); var controller = new ShiftController(mockedRepository.Object, mockedPublisher.Object); Task <IActionResult> result = null; // Act result = controller.RemoveAsync(1); // Assert var exception = (AggregateException)result.Exception; Assert.IsNotNull(exception); }