public async Task WhenValidationFailedThenExecutionFailed() { var settings = new UserSettings { Email = "testEmail", Settings = new List <NotificationSetting> { new NotificationSetting(NotificationType.Email, NotificationEvent.PackageArrived, true) } }; var message = new NotificationMessage { Event = NotificationEvent.PackageArrived, Parameters = new Dictionary <string, object>() }; var emailSender = new Mock <IEmailNotificationService>(); var factory = new Mock <IMessageFactory <IEmailNotification> >(); factory.Setup(x => x.Create(It.Is <NotificationMessage>(notificationMessage => notificationMessage == message), It.Is <UserSettings>(userSettings => userSettings == settings))) .Returns(new PackageArrivedEmailMessage("", "", new PackageArrivedEmailModel())); var sender = new EmailNotificationSender(emailSender.Object, factory.Object, Provider, _loggerFactory); var result = await sender.SendAsync(message, settings); Assert.NotNull(result); Assert.Equal(NotificationSendingStatus.Failed, result.Status); Assert.True(result.Errors.Any()); emailSender.Verify(x => x.SendAsync(It.IsAny <IEmailNotification>()), Times.Never); }
public async Task WhenSettingDisabledOrUnsupportedThenExecutionSkipped() { var settings = new UserSettings { Email = "testEmail", Settings = new List <NotificationSetting> { new NotificationSetting(NotificationType.Email, NotificationEvent.PackageArrived, false) } }; var emailSender = new Mock <IEmailNotificationService>(); var factory = new Mock <IMessageFactory <IEmailNotification> >(); var sender = new EmailNotificationSender(emailSender.Object, factory.Object, Provider, _loggerFactory); var result = await sender.SendAsync(new NotificationMessage { Event = NotificationEvent.PackageArrived, Parameters = new Dictionary <string, object>() }, settings); Assert.NotNull(result); Assert.Equal(NotificationSendingStatus.Skipped, result.Status); result = await sender.SendAsync(new NotificationMessage { Event = NotificationEvent.CommentLiked, Parameters = new Dictionary <string, object>() }, settings); Assert.NotNull(result); Assert.Equal(NotificationSendingStatus.Skipped, result.Status); emailSender.Verify(x => x.SendAsync(It.IsAny <IEmailNotification>()), Times.Never); }
public async Task MessageSentSuccessfully() { var settings = new UserSettings { Email = "testEmail", Settings = new List <NotificationSetting> { new NotificationSetting(NotificationType.Email, NotificationEvent.PackageArrived, true) } }; var message = new NotificationMessage { Event = NotificationEvent.PackageArrived, Parameters = new Dictionary <string, object>() }; var factory = new Mock <IMessageFactory <IEmailNotification> >(); factory.Setup(x => x.Create(It.Is <NotificationMessage>(notificationMessage => notificationMessage == message), It.Is <UserSettings>(userSettings => userSettings == settings))) .Returns(validMessage); var emailSender = new Mock <IEmailNotificationService>(); var sender = new EmailNotificationSender(emailSender.Object, factory.Object, Provider, _loggerFactory); var result = await sender.SendAsync(message, settings); Assert.NotNull(result); Assert.Equal(NotificationSendingStatus.Success, result.Status); Assert.False(result.Errors.Any()); }
public async Task WhenEmailIsNotConfiguredThenErrorReturned() { var settings = new UserSettings { Email = "", Settings = new List <NotificationSetting> { new NotificationSetting(NotificationType.Email, NotificationEvent.PackageArrived, true) } }; var message = new NotificationMessage { Event = NotificationEvent.PackageArrived, Parameters = new Dictionary <string, object>() }; var emailSender = new Mock <IEmailNotificationService>(); var factory = new Mock <IMessageFactory <IEmailNotification> >(); var sender = new EmailNotificationSender(emailSender.Object, factory.Object, Provider, _loggerFactory); var result = await sender.SendAsync(message, settings); Assert.NotNull(result); Assert.Equal(NotificationSendingStatus.Failed, result.Status); Assert.True(result.Errors.Any()); emailSender.Verify(x => x.SendAsync(It.IsAny <IEmailNotification>()), Times.Never); }
public ClientsController(MerkatoDbContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager) { _context = context; _userManager = userManager; _roleManager = roleManager; repository = new Repository(); mailSender = new EmailNotificationSender(); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="userManager"></param> /// <param name="roleManager"></param> /// <param name="logger"></param> /// <param name="hostingEnvironment"></param> public AgentsController(MerkatoDbContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager, ILogger <AgentsController> logger, IHostingEnvironment hostingEnvironment) { _context = context; _userManager = userManager; _roleManager = roleManager; _logger = logger; _appEnvironment = hostingEnvironment; repository = new Repository(); _mailSender = new EmailNotificationSender(); _smtpConfig = new SmtpConfig(); }
private void ChangeTrackedHandler(ChangeTrackingArgs args) { string notificationMessage; if (Convert.ToInt32(args.NotificationSettings.NecessaryPrice) >= args.ProductChanges.Price && args.NotificationSettings.Sign == Sign.LessOrEqual || Convert.ToInt32(args.NotificationSettings.NecessaryPrice) <= args.ProductChanges.Price && args.NotificationSettings.Sign == Sign.BiggerOrEqual) { notificationMessage = EmailNotificationSender.GenerateNotificationMessage(args.NotificationSettings.Availability, args.NotificationSettings.PriceChanging, args.ProductChanges.Available, args.ProductChanges.Price, args.ProductName); } else { notificationMessage = EmailNotificationSender.GenerateNotificationMessage(args.NotificationSettings.Availability, args.NotificationSettings.PriceChanging, args.ProductChanges.Available, null, args.ProductName); } _notificationSender.Send(notificationMessage, args.UserEmail); }
static void Main(string[] args) { EmailNotificationSender emailNotificationSender = new EmailNotificationSender(); SMSNotificationSender smsNotificationSender = new SMSNotificationSender(); UINotificationSender uiNotificationSender = new UINotificationSender(); CreditSystem creditSystem = new CreditSystem(); DebitSystem debitSystem = new DebitSystem(); PromotionSystem promotionSystem = new PromotionSystem(); Account account = new Account() { AccountName = "Dumpi", Balance = 0 }; //////////////////////////////////////////////////////////////////////////////////////////// creditSystem._notificationSender = emailNotificationSender; creditSystem.Credit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); creditSystem._notificationSender = smsNotificationSender; creditSystem.Credit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); creditSystem._notificationSender = uiNotificationSender; creditSystem.Credit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// debitSystem._notificationSender = emailNotificationSender; debitSystem.Debit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); debitSystem._notificationSender = smsNotificationSender; debitSystem.Debit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); debitSystem._notificationSender = uiNotificationSender; debitSystem.Debit(account, 200); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// string offer = "$1 million loan approved"; promotionSystem._notificationSender = emailNotificationSender; promotionSystem.Promote(account, offer); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); promotionSystem._notificationSender = smsNotificationSender; promotionSystem.Promote(account, offer); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); promotionSystem._notificationSender = uiNotificationSender; promotionSystem.Promote(account, offer); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); //////////////////////////////////////////////////////////////////////////////////////////// //Just to stop the console Console.ReadLine(); }
public static void SendMail(Client client, String message) { var emailSender = new EmailNotificationSender(); emailSender.Notify(client, message); }
public async Task Execute(IJobExecutionContext context) { INotificationSender notificationSender = new EmailNotificationSender(); await notificationSender.Send(); }
/// <summary> /// /// </summary> /// <param name="context"></param> public AgentApiController(MerkatoDbContext context) { _context = context; _mailSender = new EmailNotificationSender(); dataManager = new DataManager(); }