public async void ConfirmNotificationNotificationIsNull_BadRequest() { // Arrange Notification notification = new Notification { Id = 1 }; Mock <GenericRepository <Notification> > mockNotificationRepository = new Mock <GenericRepository <Notification> >(); mockNotificationRepository .Setup(nr => nr.GetAsync(It.IsAny <int>(), It.IsAny <string>())) .Returns(Task.FromResult(null as Notification)); Mock <IUnitOfWork> mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(u => u.GetRepository <Notification, GenericRepository <Notification> >()) .Returns(mockNotificationRepository.Object); NotificationsController controller = new NotificationsController(mockUnitOfWork.Object); // Act IActionResult result = await controller.ConfirmNotification(notification.Id); // Assert Assert.NotNull(result); BadRequestObjectResult badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result); Assert.Equal("No such notification", badRequestObjectResult.Value.ToString()); }
public async void ConfirmNotification_OkResult() { // Arrange Notification notification = new Notification { Id = 1 }; Mock <GenericRepository <Notification> > mockNotificationRepository = new Mock <GenericRepository <Notification> >(); mockNotificationRepository .Setup(nr => nr.GetAsync(It.IsAny <int>(), It.IsAny <string>())) .Returns(Task.FromResult(notification)); Mock <IUnitOfWork> mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(u => u.GetRepository <Notification, GenericRepository <Notification> >()) .Returns(mockNotificationRepository.Object); NotificationsController controller = new NotificationsController(mockUnitOfWork.Object); // Act IActionResult result = await controller.ConfirmNotification(notification.Id); // Assert Assert.NotNull(result); Assert.IsType <OkResult>(result); }