public void MarkAsRead_ServiceSucceeded_OkResult() { var serverResult = new ServiceResult(true); _mockService.Setup(m => m.MarkAsRead(_userId)) .Returns(serverResult); var result = _controller.MarkAsRead(); result.Should().BeOfType <OkResult>(); }
public async Task MarkAsRead_ServiceMethodThrowsInvalidOperationException_ReturnsForbiddenStatusCodeWishMessage() { var exceptionMessage = "User cannot mark as read notification that does not belong to him"; _notificationsServiceMock.Setup(obj => obj.MarkAsReadAsync(It.IsAny <int>())) .ThrowsAsync(new InvalidOperationException(exceptionMessage)); var result = await _controller.MarkAsRead(It.IsAny <int>()); var objectResult = result.Should().BeOfType <ObjectResult>().Subject; objectResult.StatusCode.Should().Be(403); objectResult.Value.Should().Be(exceptionMessage); }
public async void MarkAsRead_HappyPath_ShouldReturnOkObject() { _mockRepository.Setup(g => g.GetNewUserNotifications(_userId)).ReturnsAsync(new List <UserNotification>()); var result = await _controller.MarkAsRead(); result.Should().BeOfType <OkObjectResult>(); }
public void MarkAsRead_ValidRequest_ShouldReturnOk() { // Arrange var user = new ApplicationUser(); var notification = Notification.FactoryGig(new Gig(), NotificationType.GigCancelled); var userNotification = new UserNotification(user, notification); var userNotifications = new List <UserNotification>() { userNotification }; _mockNotificationRepository.Setup(r => r.GetUnreadUserNotifications(_UserId)) .Returns(userNotifications); // Act var result = _controller.MarkAsRead().Result; // Assert Assert.IsInstanceOf <OkResult>(result); }