Ejemplo n.º 1
0
        public async Task GetByIdTest()
        {
            var notificationId = Guid.NewGuid();
            var service        = new Mock <INotificationHistoryService>();
            var response       = new NotificationResponse(NotificationEvent.ArticleCreated)
            {
                OwnerUserId = UserId
            };

            GetNotificationRequest req = null;

            service.Setup(x => x.GetAsync(It.IsAny <GetNotificationRequest>()))
            .Callback <GetNotificationRequest>(request => req = request)
            .ReturnsAsync(response)
            .Verifiable();

            var controller = new NotificationHistoryController(_logger, service.Object).WithUser();
            var result     = await controller.GetNotificationByIdAsync(notificationId);

            service.Verify();
            Assert.NotNull(req);
            Assert.Equal(UserId, req.UserId);
            Assert.Equal(notificationId, req.NotificationId);

            var res = Assert.IsType <OkObjectResult>(result);

            Assert.Equal(response, res.Value);
            Assert.IsType <NotificationResponse>(res.Value);
        }
Ejemplo n.º 2
0
        public async Task ListTest(int pageSize, string startTime, string endTime)
        {
            var expectedStartTime = startTime == null ? (DateTimeOffset?)null: DateTimeOffset.Parse(startTime, CultureInfo.InvariantCulture);
            var expectedEndTime   = endTime == null ? (DateTimeOffset?)null : DateTimeOffset.Parse(endTime, CultureInfo.InvariantCulture);
            var service           = new Mock <INotificationHistoryService>();
            var response          = new NotificationSetResponse
            {
                Results = new List <NotificationResponse>
                {
                    new NotificationResponse(NotificationEvent.ArticleCreated)
                    {
                        OwnerUserId = UserId
                    },
                    new NotificationResponse(NotificationEvent.CommentLiked)
                    {
                        OwnerUserId = UserId
                    }
                },
                ItemsCount = 2
            };

            GetNotificationsRequest req = null;

            service.Setup(x => x.ListAsync(It.IsAny <GetNotificationsRequest>()))
            .Callback <GetNotificationsRequest>(request => req = request)
            .ReturnsAsync(response)
            .Verifiable();

            var controller = new NotificationHistoryController(_logger, service.Object).WithUser();
            var result     = await controller.GetNotificationsAsync(pageSize, startTime, endTime);

            service.Verify();
            Assert.NotNull(req);
            Assert.Equal(UserId, req.UserId);
            Assert.Equal(pageSize, req.PageSize);
            Assert.Equal(expectedEndTime, req.Options.EndTime);
            Assert.Equal(expectedStartTime, req.Options.StartTime);

            var res = Assert.IsType <OkObjectResult>(result);

            Assert.IsType <NotificationSetResponse>(res.Value);
            Assert.Equal(response, res.Value);
        }
Ejemplo n.º 3
0
        public async Task DeleteNotificationsTest()
        {
            var         service = new Mock <INotificationHistoryService>();
            UserRequest req     = null;

            service.Setup(x => x.DeleteAllAsync(It.IsAny <UserRequest>()))
            .Callback <UserRequest>(request => req = request)
            .Returns(Task.CompletedTask)
            .Verifiable();

            var controller = new NotificationHistoryController(_logger, service.Object).WithUser();
            var result     = await controller.DeleteNotificationsAsync();

            service.Verify();
            Assert.NotNull(req);
            Assert.Equal(UserId, req.UserId);

            Assert.IsType <NoContentResult>(result);
        }