public async Task ScheduleSendNotification_GetNotification() { //Arrange var type = nameof(SampleEmailNotification); var criteria4 = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance(); criteria4.Take = 1; criteria4.NotificationType = type; _notificationSearchServiceMock.Setup(x => x.SearchNotificationsAsync(criteria4)).ReturnsAsync(new NotificationSearchResult()); _notificationRegistrar.RegisterNotification <SampleEmailNotification>().WithTemplates(new EmailNotificationTemplate() { Subject = "SampleEmailNotification test", Body = "SampleEmailNotification body test", }); var notification = AbstractTypeFactory <Notification> .TryCreateInstance(nameof(SampleEmailNotification)); notification.IsActive = true; var jsonSerializeSettings = new JsonSerializerSettings { Converters = new List <JsonConverter> { new PolymorphJsonConverter() } }; GlobalConfiguration.Configuration.UseSerializerSettings(jsonSerializeSettings); //Act await _sender.ScheduleSendNotificationAsync(notification); //Assert Func <Job, bool> condition = job => job.Method.Name == nameof(NotificationSender.TrySendNotificationMessageAsync) && job.Args[0] is null; Expression <Func <Job, bool> > expression = a => condition(a); _backgroundJobClient.Verify(x => x.Create(It.Is(expression), It.IsAny <EnqueuedState>())); }
public void RegisterNotification_GetNotification() { //Arrange var type = nameof(SampleEmailNotification); var criteria4 = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance(); criteria4.Take = 1; criteria4.NotificationType = type; _notificationSearchServiceMock.Setup(x => x.SearchNotificationsAsync(criteria4)).ReturnsAsync(new NotificationSearchResult()); //Act _notificationRegistrar.RegisterNotification <SampleEmailNotification>(); var notification = CreateNotification(type, new UnregisteredNotification()); //Assert Assert.Equal(type, notification.Type); }
public NotificationMessageServiceUnitTests() { _repositoryMock = new Mock <INotificationRepository>(); Func <INotificationRepository> factory = () => _repositoryMock.Object; _mockUnitOfWork = new Mock <IUnitOfWork>(); _repositoryMock.Setup(ss => ss.UnitOfWork).Returns(_mockUnitOfWork.Object); _eventPublisherMock = new Mock <IEventPublisher>(); _notificationServiceMock = new Mock <INotificationService>(); _notificationSearchServiceMock = new Mock <INotificationSearchService>(); _notificationMessageService = new NotificationMessageService(factory, _eventPublisherMock.Object); if (!AbstractTypeFactory <NotificationMessageEntity> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(EmailNotificationMessageEntity))) { AbstractTypeFactory <NotificationMessageEntity> .RegisterType <EmailNotificationMessageEntity>(); } 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>(); } var criteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance(); criteria.NotificationType = nameof(RegistrationEmailNotification); criteria.Take = 1; _notificationSearchServiceMock.Setup(x => x.SearchNotificationsAsync(criteria)).ReturnsAsync(new NotificationSearchResult()); var notificationService = new NotificationRegistrar(null); notificationService.RegisterNotification <RegistrationEmailNotification>(); }