public async Task GetNotifications_ReturnWelcomePage_ForNameEqualNull() { //Arrange string name = null; //Act var result = await _controller.GetNotifications(name); //Assert var redirectToAction = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Welcome", redirectToAction.ActionName); Assert.Equal("Success", redirectToAction.ControllerName); }
public async Task Get_All_Notification_Of_Existing_User() { var result = (await _notificationsController.GetNotifications("333-555-333")).Result as OkObjectResult; Assert.IsNotNull(result); Assert.IsNotNull(result.Value); Assert.IsInstanceOf <IEnumerable <NotificationViewModel> >(result.Value); var notifications = result.Value as IEnumerable <NotificationViewModel>; Assert.IsNotNull(notifications); Assert.AreEqual(1, notifications.Count()); }
public async void NotificationsController_GetNotifications_ShouldCallServiceToGetNotifications() { // Arrange _mockNotificationService.Setup(_ => _.GetNotifications(It.IsAny <string>())) .ReturnsAsync(new List <NotificationModel> { new NotificationModel() }); var principal = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim> { new Claim(ClaimTypes.NameIdentifier, "UserId") })); _mockAuthenticationManager.SetupGet(_ => _.User).Returns(principal); // Act var result = await _controller.GetNotifications(); // Assert result.Should().BeOfType <OkNegotiatedContentResult <IEnumerable <NotificationModel> > >(); var resultContent = result.As <OkNegotiatedContentResult <IEnumerable <NotificationModel> > >(); resultContent.Content.Count().Should().Be(1); Mock.VerifyAll(); }
public async void get_notifications_should_return_all_notifications_per_user() { var options = new DbContextOptionsBuilder <DatabaseContext>().UseInMemoryDatabase(databaseName: "NotificationTest").Options; string userId = "1"; using (var context = new DatabaseContext(options)) { // Act var controller = new NotificationsController(context); AddUserClaim(controller, userId); context.Users.Add(new User() { FacebookId = userId }); context.Notifications.Add(new Notification() { ReceiverId = "1", MessageType = 1, Id = 1 }); context.Notifications.Add(new Notification() { ReceiverId = "2", MessageType = 1, Id = 2 }); context.SaveChanges(); var notifications = await controller.GetNotifications(); // Assert var notificationsCount = notifications.Value.Count(); Assert.Equal(1, notificationsCount); } }
public async void GetNotifications_ReturnsBadRequestObjectResult_WhenTheUserIsInvalid() { //Arrange var controller = new NotificationsController(_loggerMock.Object, _mockNotificationService.Object, _mockUserService.Object); //Act var result = await controller.GetNotifications(ConstIds.InvalidGuid, _paginationsParams); //Assert var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result.Result); Assert.Equal($"{ConstIds.InvalidGuid} is not valid guid.", badRequestObjectResult.Value); }
public void GetNotifications_ValidRequest_ShouldReturnNotificationDtos() { // Arrange var user = new ApplicationUser(); var notification = Notification.FactoryGig(new Gig(), NotificationType.GigCancelled); _mockNotificationRepository.Setup(r => r.GetUnreadUserNotificationsWithArtist(_UserId)) .Returns(new List <Notification>() { notification }); // Act var result = _controller.GetNotifications(); // Assert Assert.IsInstanceOf <IEnumerable <NotificationDto> >(result); }
public async void GetNotifications_ReturnsNotFoundObjectResult_WhenUserDoesntExist() { //Arrange _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>())) .ReturnsAsync(false) .Verifiable(); var controller = new NotificationsController(_loggerMock.Object, _mockNotificationService.Object, _mockUserService.Object); //Act var result = await controller.GetNotifications(ConstIds.ExampleUserId, _paginationsParams); //Assert var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result.Result); Assert.Equal($"User: {ConstIds.ExampleUserId} not found.", notFoundObjectResult.Value); _mockUserService.Verify(); }
public async void GetNotifications_ReturnsInternalServerErrorResult_WhenExceptionThrownInService() { //Arrange _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>())) .Throws(new ArgumentNullException(nameof(Guid))) .Verifiable(); var controller = new NotificationsController(_loggerMock.Object, _mockNotificationService.Object, _mockUserService.Object); //Act var result = await controller.GetNotifications(ConstIds.ExampleUserId, _paginationsParams); //Assert var internalServerErrorResult = Assert.IsType <StatusCodeResult>(result.Result); Assert.Equal(StatusCodes.Status500InternalServerError, internalServerErrorResult.StatusCode); _mockUserService.Verify(); }
public async void GetNotifications_ReturnsOkObjectResult_WithAListOfNotificationsData() { //Arrange var notifications = GetTestNotificationData(); var pagedList = PagedList <NotificationDto> .Create(notifications, _paginationsParams.PageNumber, _paginationsParams.PageSize, _paginationsParams.Skip); _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>())) .ReturnsAsync(true) .Verifiable(); _mockNotificationService.Setup(Service => Service.GetUserNotifications(It.IsAny <Guid>(), _paginationsParams, null, 0, null)) .Returns(pagedList) .Verifiable(); var mockUrlHelper = new Mock <IUrlHelper>(); mockUrlHelper .Setup(m => m.Link("GetNotifications", It.IsAny <object>())) .Returns("some url") .Verifiable(); var controller = new NotificationsController(_loggerMock.Object, _mockNotificationService.Object, _mockUserService.Object) { Url = mockUrlHelper.Object }; //Act var result = await controller.GetNotifications(ConstIds.ExampleUserId, _paginationsParams); //Assert var actionResult = Assert.IsType <OkObjectResult>(result.Result); var model = Assert.IsType <CollectionWithPaginationData <NotificationDto> >(actionResult.Value); Assert.Equal(notifications.Count, model.Collection.Count); _mockUserService.Verify(); _mockNotificationService.Verify(); }