Exemplo n.º 1
0
        /// <summary>
        /// Get an array of notifications within the specified filter.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public Paged <NotificationQueue> GetPage(NotificationQueueFilter filter)
        {
            this.User.ThrowIfNotAuthorized(Permissions.SystemAdmin);

            var query = this.Context.GenerateQuery(this.User, filter);
            var total = query.Count();
            var items = query.Skip((filter.Page - 1) * filter.Quantity).Take(filter.Quantity);

            return(new Paged <NotificationQueue>(items, filter.Page, filter.Quantity, total));
        }
Exemplo n.º 2
0
        public IActionResult GetNotificationsPage([FromBody] NotificationQueueFilter filter)
        {
            filter.ThrowBadRequestIfNull($"The request must include a filter.");
            if (!filter.IsValid())
            {
                throw new BadRequestException("Projects filter must contain valid values.");
            }

            var page = _pimsService.NotificationQueue.GetPage(filter);

            return(new JsonResult(_mapper.Map <PageModel <NotificationQueueModel> >(page)));
        }
Exemplo n.º 3
0
        public void GetNotificationsPage_Success(NotificationQueueFilter filter)
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <QueueController>(Permissions.SystemAdmin);

            var template      = EntityHelper.CreateNotificationTemplate(1, "test");
            var notifications = EntityHelper.CreateNotificationQueues(1, 2, template);

            var service = helper.GetService <Mock <IPimsService> >();
            var mapper  = helper.GetService <IMapper>();
            var page    = new Paged <Entity.NotificationQueue>(notifications, filter.Page, filter.Quantity);

            service.Setup(m => m.NotificationQueue.GetPage(It.IsAny <NotificationQueueFilter>())).Returns(page);

            // Act
            var result = controller.GetNotificationsPage(filter);

            // Assert
            var actionResult = Assert.IsType <JsonResult>(result);
            var actualResult = Assert.IsType <Api.Models.PageModel <Model.NotificationQueueModel> >(actionResult.Value);

            service.Verify(m => m.NotificationQueue.GetPage(It.IsAny <NotificationQueueFilter>()), Times.Once());
        }