Esempio n. 1
0
        public async Task SearchNotificationsAsync_GetItems()
        {
            //Arrange
            var searchCriteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance();

            searchCriteria.Take = 20;
            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
            _notificationRegistrar.RegisterNotification <InvoiceEmailNotification>();
            _notificationRegistrar.RegisterNotification <OrderSentEmailNotification>();

            var notifications = new List <NotificationEntity>
            {
                new EmailNotificationEntity
                {
                    Type = nameof(RegistrationEmailNotification), Kind = nameof(EmailNotification),
                    Id   = Guid.NewGuid().ToString(), IsActive = true
                }
            };

            var mockNotifications = new Common.TestAsyncEnumerable <NotificationEntity>(notifications);

            _repositoryMock.Setup(r => r.Notifications).Returns(mockNotifications.AsQueryable());
            var ids = notifications.Select(n => n.Id).ToArray();

            _notificationServiceMock.Setup(ns => ns.GetByIdsAsync(ids, null))
            .ReturnsAsync(notifications.Select(n => n.ToModel(AbstractTypeFactory <Notification> .TryCreateInstance(n.Type))).ToArray());

            //Act
            var result = await _notificationSearchService.SearchNotificationsAsync(searchCriteria);

            //Assert
            Assert.NotEmpty(result.Results);
            Assert.Equal(1, result.Results.Count(r => r.IsActive));
            //Assert.Equal(2, result.Results.Count(r => !r.IsActive));
        }
Esempio n. 2
0
        public async Task GetNotificationByTypeAsync_ReturnNotification()
        {
            //Arrange
            var type = nameof(RegistrationEmailNotification);

            var mockNotifications = new Common.TestAsyncEnumerable <NotificationEntity>(new List <NotificationEntity>());

            _repositoryMock.Setup(r => r.Notifications).Returns(mockNotifications.AsQueryable());
            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();

            //Act
            var result = await _notificationSearchService.GetNotificationAsync(type);

            //Assert
            Assert.NotNull(result);
            Assert.Equal(type, result.Type);
        }
Esempio n. 3
0
        public async Task SearchNotificationsAsync_GetTwoItems()
        {
            //Arrange
            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
            _notificationRegistrar.RegisterNotification <InvoiceEmailNotification>();
            _notificationRegistrar.RegisterNotification <OrderSentEmailNotification>();
            var searchCriteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance();

            searchCriteria.Take = 2;
            searchCriteria.Skip = 0;
            var mockNotifications = new Common.TestAsyncEnumerable <NotificationEntity>(new List <NotificationEntity>());

            _repositoryMock.Setup(r => r.Notifications).Returns(mockNotifications.AsQueryable());

            //Act
            var result = await _notificationSearchService.SearchNotificationsAsync(searchCriteria);

            //Assert
            Assert.Equal(2, result.Results.Count);
        }
Esempio n. 4
0
        public async Task SearchNotificationsAsync_AllActiveNotifications()
        {
            //Arrange
            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
            _notificationRegistrar.RegisterNotification <InvoiceEmailNotification>();
            _notificationRegistrar.RegisterNotification <OrderSentEmailNotification>();

            var responseGroup  = NotificationResponseGroup.Default.ToString();
            var searchCriteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance();

            searchCriteria.Take          = 20;
            searchCriteria.ResponseGroup = responseGroup;
            var notificationEntities = new List <NotificationEntity> {
                new EmailNotificationEntity {
                    Type = nameof(InvoiceEmailNotification), Kind = nameof(EmailNotification), Id = Guid.NewGuid().ToString(), IsActive = true
                },
                new EmailNotificationEntity {
                    Type = nameof(OrderSentEmailNotification), Kind = nameof(EmailNotification), Id = Guid.NewGuid().ToString(), IsActive = true
                },
                new EmailNotificationEntity {
                    Type = nameof(RegistrationEmailNotification), Kind = nameof(EmailNotification), Id = Guid.NewGuid().ToString(), IsActive = true
                }
            };
            var mockNotifications = new Common.TestAsyncEnumerable <NotificationEntity>(notificationEntities);

            _repositoryMock.Setup(r => r.Notifications).Returns(mockNotifications.AsQueryable());
            var notifications = notificationEntities.Select(n => n.ToModel(AbstractTypeFactory <Notification> .TryCreateInstance(n.Type))).ToArray();
            var ids           = notificationEntities.Select(n => n.Id).ToArray();

            _notificationServiceMock.Setup(ns => ns.GetByIdsAsync(ids, responseGroup))
            .ReturnsAsync(notifications);

            //Act
            var result = await _notificationSearchService.SearchNotificationsAsync(searchCriteria);

            //Assert
            Assert.True(result.Results.Where(n => ids.Contains(n.Id)).All(r => r.IsActive));
        }