public NotificationSenderIntegrationTests()
        {
            _emailSendingOptions = new SmtpSenderOptions()
            {
                SmtpServer = "smtp.gmail.com",
                Port       = 587,
                Login      = "******",
                Password   = ""
            };
            _templateRender            = new LiquidTemplateRenderer();
            _messageServiceMock        = new Mock <INotificationMessageService>();
            _emailSendingOptionsMock   = new Mock <IOptions <SmtpSenderOptions> >();
            _serviceMock               = new Mock <INotificationService>();
            _repositoryMock            = new Mock <INotificationRepository>();
            _logNotificationSenderMock = new Mock <ILogger <NotificationSender> >();
            _eventPulisherMock         = new Mock <IEventPublisher>();
            INotificationRepository RepositoryFactory() => _repositoryMock.Object;

            _notificationRegistrar = new NotificationService(RepositoryFactory, _eventPulisherMock.Object);

            if (!AbstractTypeFactory <NotificationTemplate> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(EmailNotificationTemplate)))
            {
                AbstractTypeFactory <NotificationTemplate> .RegisterType <EmailNotificationTemplate>().MapToType <NotificationTemplateEntity>();
            }

            if (!AbstractTypeFactory <NotificationMessage> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(EmailNotificationMessage)))
            {
                AbstractTypeFactory <NotificationMessage> .RegisterType <EmailNotificationMessage>().MapToType <NotificationMessageEntity>();
            }

            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
            _notificationRegistrar.RegisterNotification <ResetPasswordEmailNotification>();
        }
        public async Task GetNotificationByTypeAsync_ReturnNotification()
        {
            //Arrange
            var type = nameof(RegistrationEmailNotification);

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

            var mockNotifications = notifications.AsQueryable().BuildMock();

            _repositoryMock.Setup(r => r.Notifications).Returns(mockNotifications.Object);
            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
            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.GetNotificationAsync(type);

            //Assert
            Assert.NotNull(result);
            Assert.Equal(type, result.Type);
        }
Пример #3
0
        public NotificationsExportImportManagerIntegrationTests()
        {
            _repositoryMock    = new Mock <INotificationRepository>();
            _eventPulisherMock = new Mock <IEventPublisher>();
            INotificationRepository RepositoryFactory() => _repositoryMock.Object;

            _mockUnitOfWork = new Mock <IUnitOfWork>();
            _repositoryMock.Setup(ss => ss.UnitOfWork).Returns(_mockUnitOfWork.Object);
            _notificationSearchService        = new NotificationSearchService(RepositoryFactory);
            _notificationService              = new NotificationService(RepositoryFactory, _eventPulisherMock.Object);
            _notificationsExportImportManager = new NotificationsExportImportManager(_notificationSearchService, _notificationService);

            _notificationRegistrar = new NotificationService(RepositoryFactory, _eventPulisherMock.Object);

            if (!AbstractTypeFactory <Notification> .AllTypeInfos.Any(t => t.IsAssignableTo(nameof(EmailNotification))))
            {
                AbstractTypeFactory <Notification> .RegisterType <EmailNotification>().MapToType <NotificationEntity>();

                AbstractTypeFactory <NotificationEntity> .RegisterType <EmailNotificationEntity>();
            }

            if (!AbstractTypeFactory <NotificationTemplate> .AllTypeInfos.Any(t => t.IsAssignableTo(nameof(EmailNotificationTemplate))))
            {
                AbstractTypeFactory <NotificationTemplate> .RegisterType <EmailNotificationTemplate>().MapToType <NotificationTemplateEntity>();
            }

            if (!AbstractTypeFactory <NotificationMessage> .AllTypeInfos.Any(t => t.IsAssignableTo(nameof(EmailNotificationMessage))))
            {
                AbstractTypeFactory <NotificationMessage> .RegisterType <EmailNotificationMessage>().MapToType <NotificationMessageEntity>();
            }



            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
        }
        public NotificationsExportImportManagerIntegrationTests()
        {
            _repositoryMock    = new Mock <INotificationRepository>();
            _eventPulisherMock = new Mock <IEventPublisher>();
            INotificationRepository RepositoryFactory() => _repositoryMock.Object;

            _mockUnitOfWork = new Mock <IUnitOfWork>();
            _repositoryMock.Setup(ss => ss.UnitOfWork).Returns(_mockUnitOfWork.Object);
            _notificationSearchServiceMock = new Mock <INotificationSearchService>();
            _notificationServiceMock       = new Mock <INotificationService>();

            _notificationsExportImportManager = new NotificationsExportImport(_notificationSearchServiceMock.Object, _notificationServiceMock.Object, GetJsonSerializer());

            if (!AbstractTypeFactory <NotificationTemplate> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(EmailNotificationTemplate)))
            {
                AbstractTypeFactory <NotificationTemplate> .RegisterType <EmailNotificationTemplate>().MapToType <NotificationTemplateEntity>();
            }

            if (!AbstractTypeFactory <NotificationMessage> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(EmailNotificationMessage)))
            {
                AbstractTypeFactory <NotificationMessage> .RegisterType <EmailNotificationMessage>().MapToType <NotificationMessageEntity>();
            }

            _notificationRegistrar = new NotificationService(RepositoryFactory, _eventPulisherMock.Object);
            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
        }
Пример #5
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);
        }
        public async Task GetNotificationByTypeAsync_ReturnNotification()
        {
            //Arrange
            var type = nameof(RegistrationSocialNetworkNotification);

            var mockNotifications = new List <NotificationEntity>().AsQueryable().BuildMock();

            _repositoryMock.Setup(r => r.Notifications).Returns(mockNotifications.Object);
            _notificationRegistrar.RegisterNotification <RegistrationSocialNetworkNotification>();

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

            //Assert
            Assert.NotNull(result);
            Assert.Equal(type, result.Type);
        }
Пример #7
0
        public async Task SearchNotificationsAsync_GetNotifications()
        {
            //Arrange
            var searchCriteria = new NotificationSearchCriteria();

            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
            _notificationRegistrar.RegisterNotification <InvoiceEmailNotification>();
            _notificationRegistrar.RegisterNotification <OrderSentEmailNotification>();

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

            //Assert
            Assert.NotEmpty(result.Results);
        }
Пример #8
0
        public async Task GetNotificationByTypeAsync_ReturnNotifiction()
        {
            //Arrange
            string type = nameof(RegistrationEmailNotification);

            _repositoryMock.Setup(n => n.GetByTypeAsync(nameof(RegistrationEmailNotification), null, null, NotificationResponseGroup.Default.ToString()))
            .ReturnsAsync(new EmailNotificationEntity()
            {
                IsActive = true
            });
            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();

            //Act
            var result = await _notificationService.GetByTypeAsync(type, null, null);

            //Assert
            Assert.NotNull(result);
            Assert.Equal(type, result.Type);
        }
        public NotificationSearchServiceUnitTests()
        {
            _repositoryMock                = new Mock <INotificationRepository>();
            _repositoryFactoryMock         = new Mock <Func <INotificationRepository> >();
            _eventPublisherMock            = new Mock <IEventPublisher>();
            _repositoryFactory             = () => _repositoryMock.Object;
            _notificationServiceMock       = new Mock <INotificationService>();
            _notificationSearchServiceMock = new Mock <INotificationSearchService>();
            _memCache                  = GetCache();
            _cacheEntryMock            = new Mock <ICacheEntry>();
            _notificationRegistrar     = new NotificationRegistrar(null);
            _notificationSearchService = new NotificationSearchService(_repositoryFactory, _notificationServiceMock.Object, _memCache);


            var criteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance();

            criteria.Take             = 1;
            criteria.NotificationType = nameof(InvoiceEmailNotification);
            _notificationSearchServiceMock.Setup(x => x.SearchNotificationsAsync(criteria)).ReturnsAsync(new NotificationSearchResult());
            _notificationRegistrar.RegisterNotification <InvoiceEmailNotification>();

            criteria.NotificationType = nameof(OrderSentEmailNotification);
            _notificationSearchServiceMock.Setup(x => x.SearchNotificationsAsync(criteria)).ReturnsAsync(new NotificationSearchResult());
            _notificationRegistrar.RegisterNotification <OrderSentEmailNotification>();

            criteria.NotificationType = nameof(OrderPaidEmailNotification);
            _notificationSearchServiceMock.Setup(x => x.SearchNotificationsAsync(criteria)).ReturnsAsync(new NotificationSearchResult());
            _notificationRegistrar.RegisterNotification <OrderPaidEmailNotification>();

            criteria.NotificationType = nameof(RemindUserNameEmailNotification);
            _notificationSearchServiceMock.Setup(x => x.SearchNotificationsAsync(criteria)).ReturnsAsync(new NotificationSearchResult());
            _notificationRegistrar.RegisterNotification <RemindUserNameEmailNotification>();

            criteria.NotificationType = nameof(RegistrationEmailNotification);
            _notificationSearchServiceMock.Setup(x => x.SearchNotificationsAsync(criteria)).ReturnsAsync(new NotificationSearchResult());
            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
        }
Пример #10
0
        public NotificationSenderIntegrationTests()
        {
            _emailSendingOptions = new SmtpSenderOptions()
            {
                SmtpServer = "smtp.gmail.com",
                Port       = 587,
                Login      = "******",
                Password   = "******"
            };
            _templateRender            = new LiquidTemplateRenderer();
            _messageServiceMock        = new Mock <INotificationMessageService>();
            _emailSendingOptionsMock   = new Mock <IOptions <SmtpSenderOptions> >();
            _serviceMock               = new Mock <INotificationService>();
            _repositoryMock            = new Mock <INotificationRepository>();
            _logNotificationSenderMock = new Mock <ILogger <NotificationSender> >();
            _eventPulisherMock         = new Mock <IEventPublisher>();
            INotificationRepository RepositoryFactory() => _repositoryMock.Object;

            _notificationRegistrar = new NotificationService(RepositoryFactory, _eventPulisherMock.Object);



            //todo
            if (!AbstractTypeFactory <Notification> .AllTypeInfos.Any(t => t.IsAssignableTo(nameof(EmailNotification))))
            {
                AbstractTypeFactory <Notification> .RegisterType <EmailNotification>().MapToType <NotificationEntity>();
            }

            if (!AbstractTypeFactory <NotificationTemplate> .AllTypeInfos.Any(t => t.IsAssignableTo(nameof(EmailNotificationTemplate))))
            {
                AbstractTypeFactory <NotificationTemplate> .RegisterType <EmailNotificationTemplate>().MapToType <NotificationTemplateEntity>();
            }

            if (!AbstractTypeFactory <NotificationMessage> .AllTypeInfos.Any(t => t.IsAssignableTo(nameof(EmailNotificationMessage))))
            {
                AbstractTypeFactory <NotificationMessage> .RegisterType <EmailNotificationMessage>().MapToType <NotificationMessageEntity>();
            }

            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
        }
        public async Task GetNotificationsByIdsAsync_ReturnNotifications()
        {
            //Arrange
            var id            = Guid.NewGuid().ToString();
            var responseGroup = NotificationResponseGroup.Default.ToString();
            var notifications = new List <NotificationEntity> {
                new EmailNotificationEntity()
                {
                    Id = id, Type = nameof(EmailNotification)
                }
            };

            _repositoryMock.Setup(n => n.GetByIdsAsync(new[] { id }, responseGroup))
            .ReturnsAsync(notifications.ToArray());
            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();

            //Act
            var result = await _notificationService.GetByIdsAsync(new[] { id }, responseGroup);

            //Assert
            Assert.NotNull(result);
            Assert.Contains(result, r => r.Id.Equals(id));
        }
Пример #12
0
        public NotificationSenderIntegrationTests()
        {
            var builder = new ConfigurationBuilder()
                          .AddUserSecrets <NotificationSenderIntegrationTests>();

            Configuration = builder.Build();

            _emailSendingOptions = new SmtpSenderOptions()
            {
                SmtpServer = "smtp.gmail.com", // If use smtp.gmail.com then SSL is enabled and check https://www.google.com/settings/security/lesssecureapps
                Port       = 587,
                Login      = Configuration["SenderEmail"],
                Password   = Configuration["SenderEmailPassword"],
                EnableSsl  = true
            };
            _templateRender = new LiquidTemplateRenderer(Options.Create(new LiquidRenderOptions()
            {
                CustomFilterTypes = new HashSet <Type> {
                    typeof(UrlFilters), typeof(TranslationFilter)
                }
            }));
            _messageServiceMock            = new Mock <INotificationMessageService>();
            _emailSendingOptionsMock       = new Mock <IOptions <SmtpSenderOptions> >();
            _logNotificationSenderMock     = new Mock <ILogger <NotificationSender> >();
            _notificationServiceMock       = new Mock <INotificationService>();
            _notificationSearchServiceMock = new Mock <INotificationSearchService>();
            _backgroundJobClient           = new Mock <IBackgroundJobClient>();
            _notificationRegistrar         = new NotificationRegistrar(null);

            if (!AbstractTypeFactory <NotificationTemplate> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(EmailNotificationTemplate)))
            {
                AbstractTypeFactory <NotificationTemplate> .RegisterType <EmailNotificationTemplate>().MapToType <NotificationTemplateEntity>();
            }

            if (!AbstractTypeFactory <NotificationMessage> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(EmailNotificationMessage)))
            {
                AbstractTypeFactory <NotificationMessage> .RegisterType <EmailNotificationMessage>().MapToType <NotificationMessageEntity>();
            }

            if (!AbstractTypeFactory <NotificationTemplate> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(SmsNotificationTemplate)))
            {
                AbstractTypeFactory <NotificationTemplate> .RegisterType <SmsNotificationTemplate>().MapToType <NotificationTemplateEntity>();
            }

            if (!AbstractTypeFactory <NotificationMessage> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(SmsNotificationMessage)))
            {
                AbstractTypeFactory <NotificationMessage> .RegisterType <SmsNotificationMessage>().MapToType <NotificationMessageEntity>();
            }

            _notificationRegistrar.RegisterNotification <RegistrationEmailNotification>();
            _notificationRegistrar.RegisterNotification <ResetPasswordEmailNotification>();
            _notificationRegistrar.RegisterNotification <TwoFactorSmsNotification>();

            if (!AbstractTypeFactory <NotificationScriptObject> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(NotificationScriptObject)))
            {
                AbstractTypeFactory <NotificationScriptObject> .RegisterType <NotificationScriptObject>()
                .WithFactory(() => new NotificationScriptObject(null, null));
            }

            _emailSendingOptionsMock.Setup(opt => opt.Value).Returns(_emailSendingOptions);
        }