public async Task <IList <BackInStockSubscription> > Handle(SendNotificationsToSubscribersCommand request, CancellationToken cancellationToken) { if (request.Product == null) { throw new ArgumentNullException("product"); } int result = 0; var subscriptions = await GetAllSubscriptionsByProductId(request.Product.Id, request.Attributes, request.Warehouse); foreach (var subscription in subscriptions) { var customer = await _customerService.GetCustomerById(subscription.CustomerId); //ensure that customer is registered (simple and fast way) if (customer != null && CommonHelper.IsValidEmail(customer.Email)) { var customerLanguageId = customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.LanguageId, subscription.StoreId); await _workflowMessageService.SendBackInStockNotification(customer, request.Product, subscription, customerLanguageId); result++; } } return(subscriptions); }
public void Init() { _expected = new List <BackInStockSubscription> { new BackInStockSubscription { WarehouseId = "11", ProductId = "11" }, new BackInStockSubscription { WarehouseId = "11", ProductId = "11" } }; _backInStockSubscriptionRepository = new MongoDBRepositoryTest <BackInStockSubscription>(); _backInStockSubscriptionRepository.Insert(_expected); _mockWorkflowMessageService = new Mock <IWorkflowMessageService>(); _sendNotificationsToSubscribersCommand = new SendNotificationsToSubscribersCommand { Product = new Product { Id = "11" }, Warehouse = "11" }; _mockCustomerService = new Mock <ICustomerService>(); _handler = new SendNotificationsToSubscribersCommandHandler(_mockCustomerService.Object, _mockWorkflowMessageService.Object, _backInStockSubscriptionRepository); }