public async Task TestProcessMeetingInvites_StatusSuccess_WithAttachment() { var applicationAccounts = this.GetApplicationAccounts("*****@*****.**", "*****@*****.**", "Test"); Dictionary <string, string> testConfigValues = new Dictionary <string, string>() { { "ApplicationAccounts", JsonConvert.SerializeObject(applicationAccounts) }, { "RetrySetting", JsonConvert.SerializeObject(this.retrySetting) }, }; var res = new ResponseData <string>() { Status = true, StatusCode = HttpStatusCode.OK, }; _ = this.TokenHelper.Setup(x => x.GetAuthenticationHeaderValueForSelectedAccount(It.IsAny <AccountCredential>())).ReturnsAsync(new AuthenticationHeaderValue("test")); _ = this.MsGraphProvider.Setup(x => x.SendMeetingInvite(It.IsAny <AuthenticationHeaderValue>(), It.IsAny <InvitePayload>(), It.IsAny <string>())).ReturnsAsync(res); var inviteEntities = this.GetMeetingNotificationItems(NotificationItemStatus.Queued); inviteEntities.FirstOrDefault().Attachments = this.GetAttachments(); var attachmentRes = new Dictionary <string, ResponseData <string> >() { { inviteEntities.FirstOrDefault().Attachments.FirstOrDefault().FileName, new ResponseData <string>() { Status = true, StatusCode = HttpStatusCode.OK } }, }; _ = this.MsGraphProvider.Setup(x => x.SendMeetingInviteAttachments(It.IsAny <AuthenticationHeaderValue>(), It.IsAny <List <FileAttachment> >(), It.IsAny <string>(), It.IsAny <string>())).Returns(attachmentRes); var testClass = new MSGraphNotificationProvider(this.Configuration, this.EmailAccountManager.Object, this.Logger, this.MsGraphSetting, Options.Create(this.retrySetting), this.TokenHelper.Object, this.MsGraphProvider.Object, this.EmailManager); await testClass.ProcessMeetingNotificationEntities(this.ApplicationName, inviteEntities); Assert.IsTrue(inviteEntities.FirstOrDefault().Status == NotificationItemStatus.Sent); }
public async Task TestProcessMeetingInvites_AuthHeader_Null() { var applicationAccounts = this.GetApplicationAccounts("*****@*****.**", "*****@*****.**", "Test"); Dictionary <string, string> testConfigValues = new Dictionary <string, string>() { { "ApplicationAccounts", JsonConvert.SerializeObject(applicationAccounts) }, { "RetrySetting", JsonConvert.SerializeObject(this.retrySetting) }, }; var inviteEntities = this.GetMeetingNotificationItems(NotificationItemStatus.Sent); var testClass = new MSGraphNotificationProvider(this.Configuration, this.EmailAccountManager.Object, this.Logger, this.MsGraphSetting, Options.Create(this.retrySetting), this.TokenHelper.Object, this.MsGraphProvider.Object, this.EmailManager); await testClass.ProcessMeetingNotificationEntities(this.ApplicationName, inviteEntities); Assert.IsTrue(inviteEntities.FirstOrDefault().Status == NotificationItemStatus.Failed); }
public async Task TestProcessMeetingInvites_InviteItems_NullOrEmpty() { Exception ex = null; var testClass = new MSGraphNotificationProvider(this.Configuration, this.EmailAccountManager.Object, this.Logger, this.MsGraphSetting, Options.Create(this.retrySetting), this.TokenHelper.Object, this.MsGraphProvider.Object, this.EmailManager); try { await testClass.ProcessMeetingNotificationEntities(this.ApplicationName, null); } catch (ArgumentNullException ane) { ex = ane; } Assert.IsTrue(ex?.Message?.Contains("meetingInviteEntities are null/empty.")); }
public async Task ProcessNotificationEntities_Tests() { _ = this.configuration.Setup(x => x["ApplicationAccounts"]).Returns(JsonConvert.SerializeObject(new List <ApplicationAccounts> { new ApplicationAccounts { Accounts = new List <AccountCredential> { new AccountCredential { AccountName = "Test", IsEnabled = true } }, ApplicationName = "TestAppName", } })); _ = this.configuration.Setup(x => x["RetrySetting:MaxRetries"]).Returns("2"); _ = this.configuration.Setup(x => x["MailSettings"]).Returns(JsonConvert.SerializeObject(new List <MailSettings> { new MailSettings { ApplicationName = "TestAppName", SendForReal = true } })); _ = this.mSGraphSetting.Setup(x => x.Value).Returns(new MSGraphSetting { EnableBatching = true, SendMailUrl = "test", BatchRequestLimit = 4 }); _ = this.msGraphProvider.Setup(x => x.ProcessEmailRequestBatch(It.IsAny <AuthenticationHeaderValue>(), It.IsAny <GraphBatchRequest>())).ReturnsAsync(new List <NotificationBatchItemResponse> { new NotificationBatchItemResponse { Status = System.Net.HttpStatusCode.Accepted } }); var provider = new MSGraphNotificationProvider(this.configuration.Object, new EmailAccountManager(), this.logger.Object, this.mSGraphSetting.Object, this.pollyRetrySetting.Object, this.tokenHelper.Object, this.msGraphProvider.Object, this.emailManager.Object); var notifications = new List <EmailNotificationItemEntity> { new EmailNotificationItemEntity { Application = "TestAppName", SendOnUtcDate = DateTime.Parse("2021-01-18T12:00:00Z"), To = "*****@*****.**" } }; await provider.ProcessNotificationEntities("TestAppName", notifications); Assert.IsTrue(notifications.Count == 1); Assert.IsTrue(notifications.Any(x => x.Status == NotificationItemStatus.Failed)); _ = this.tokenHelper.Setup(x => x.GetAuthenticationHeaderValueForSelectedAccount(It.IsAny <AccountCredential>())).ReturnsAsync(new AuthenticationHeaderValue("Test")); provider = new MSGraphNotificationProvider(this.configuration.Object, new EmailAccountManager(), this.logger.Object, this.mSGraphSetting.Object, this.pollyRetrySetting.Object, this.tokenHelper.Object, this.msGraphProvider.Object, this.emailManager.Object); await provider.ProcessNotificationEntities("TestAppName", notifications); Assert.IsTrue(notifications.Count == 1); Assert.IsTrue(notifications.Any(x => x.Status == NotificationItemStatus.Sent)); this.msGraphProvider.Verify(x => x.ProcessEmailRequestBatch(It.IsAny <AuthenticationHeaderValue>(), It.Is <GraphBatchRequest>(b => b.Requests.Any(g => ((NotificationService.Contracts.EmailMessagePayload)g.Body).Message.SingleValueExtendedProperties[0].Id.Contains("SystemTime 0x3FEF")))), Times.Once); this.msGraphProvider.Verify(x => x.ProcessEmailRequestBatch(It.IsAny <AuthenticationHeaderValue>(), It.Is <GraphBatchRequest>(b => b.Requests.Any(g => ((NotificationService.Contracts.EmailMessagePayload)g.Body).Message.SingleValueExtendedProperties[0].Value.Contains("2021-01-18")))), Times.Once); }
/// <summary> /// Initialization for all Email Manager Tests. /// </summary> protected void SetupTestBase() { this.MsGraphProvider = new Mock <IMSGraphProvider>(); this.CloudStorageClient = new Mock <ICloudStorageClient>(); this.TokenHelper = new Mock <ITokenHelper>(); this.EmailNotificationRepository = new Mock <IRepositoryFactory>(); this.MsGraphSetting = Options.Create(new MSGraphSetting() { EnableBatching = false, SendMailUrl = this.sendEmailUrl, BatchRequestLimit = 4 }); this.Logger = new Mock <ILogger>().Object; this.EncryptionService = new Mock <IEncryptionService>(); this.EmailAccountManager = new Mock <IEmailAccountManager>(); this.TemplateManager = new Mock <IMailTemplateManager>(); this.TemplateMerge = new Mock <ITemplateMerge>(); this.NotificationProviderFactory = new Mock <INotificationProviderFactory>(); this.NotificationRepo = new Mock <IEmailNotificationRepository>(); this.NotificationProvider = new MockNotificationProvider(); var notificationId = Guid.NewGuid().ToString(); IList <NotificationBatchItemResponse> responses = new List <NotificationBatchItemResponse>(); responses.Add(new NotificationBatchItemResponse() { NotificationId = notificationId, Status = System.Net.HttpStatusCode.Accepted }); var applicationAccounts = new List <ApplicationAccounts>() { new ApplicationAccounts() { ApplicationName = this.ApplicationName, ValidAppIds = Guid.NewGuid().ToString(), Accounts = new List <AccountCredential>() { new AccountCredential() { AccountName = "Test", IsEnabled = true, PrimaryPassword = "******", }, }, }, }; var retrySetting = new RetrySetting { MaxRetries = 10, TransientRetryCount = 3, }; IList <EmailNotificationItemEntity> emailNotificationItemEntities = new List <EmailNotificationItemEntity>() { new EmailNotificationItemEntity() { Application = this.ApplicationName, NotificationId = notificationId, To = "*****@*****.**", Subject = "TestEmailSubject", Body = "CfDJ8KvR5DP4DK5GqV1jviPzBnsv3onVDZ-ztz-AvRl_6nvVNg86jfmKjgySREDPW9xNrwpKALT5BIFNX6VK3wzKsxc51dbkQjPPG9l7436wQktrAMRadumTpGKNKG1lLlP0FA", Id = notificationId, }, }; var mailSettings = new List <MailSettings>() { new MailSettings() { ApplicationName = this.ApplicationName, MailOn = true, SendForReal = false, ToOverride = "*****@*****.**", SaveToSent = true, }, }; Dictionary <string, string> testConfigValues = new Dictionary <string, string>() { { "ApplicationAccounts", JsonConvert.SerializeObject(applicationAccounts) }, { "RetrySetting:MaxRetries", "10" }, { "RetrySetting:TransientRetryCount", "3" }, { Constants.StorageType, StorageType.StorageAccount.ToString() }, { "MailSettings", JsonConvert.SerializeObject(mailSettings) }, { Constants.NotificationProviderType, NotificationProviderType.Graph.ToString() }, }; string mergedTemplate = "Testing Html template"; MailTemplate template = new MailTemplate() { TemplateName = "TestTemplate", Description = "Test template", Content = "Testing {{Key}} template", TemplateType = "Text", }; this.Configuration = new ConfigurationBuilder() .AddInMemoryCollection(testConfigValues) .Build(); _ = this.TokenHelper .Setup(th => th.GetAccessTokenForSelectedAccount(It.IsAny <AccountCredential>())) .Returns(Task.FromResult(this.TestToken)); _ = this.TokenHelper .Setup(th => th.GetAuthenticationHeaderFromToken(It.IsAny <string>())) .Returns(Task.FromResult(new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", this.TestToken))); _ = this.MsGraphProvider .Setup(gp => gp.ProcessEmailRequestBatch(It.IsAny <AuthenticationHeaderValue>(), It.IsAny <GraphBatchRequest>())) .Returns(Task.FromResult(responses)); _ = this.MsGraphProvider .Setup(gp => gp.SendEmailNotification(It.IsAny <AuthenticationHeaderValue>(), It.IsAny <EmailMessagePayload>(), It.IsAny <string>())) .Returns(Task.FromResult(It.IsAny <bool>())); _ = this.EmailNotificationRepository .Setup(repository => repository.GetRepository(StorageType.StorageAccount).CreateEmailNotificationItemEntities(It.IsAny <IList <EmailNotificationItemEntity> >(), It.IsAny <string>())) .Returns(Task.CompletedTask); _ = this.EmailNotificationRepository .Setup(repository => repository.GetRepository(StorageType.StorageAccount).UpdateEmailNotificationItemEntities(It.IsAny <IList <EmailNotificationItemEntity> >())) .Returns(Task.CompletedTask); _ = this.EmailNotificationRepository .Setup(repository => repository.GetRepository(StorageType.StorageAccount).GetEmailNotificationItemEntities(It.IsAny <IList <string> >(), It.IsAny <string>())) .Returns(Task.FromResult(emailNotificationItemEntities)); _ = this.CloudStorageClient .Setup(csa => csa.GetCloudQueue(It.IsAny <string>())) .Returns(new CloudQueue(new Uri(this.cloudQueueUri))); _ = this.CloudStorageClient .Setup(csa => csa.QueueCloudMessages(It.IsAny <CloudQueue>(), It.IsAny <IEnumerable <string> >(), null)) .Returns(Task.CompletedTask); _ = this.EmailAccountManager .Setup(ema => ema.FetchAccountToBeUsedForApplication(It.IsAny <string>(), It.IsAny <List <ApplicationAccounts> >())) .Returns(applicationAccounts[0].Accounts[0]); _ = this.TemplateManager .Setup(tmgr => tmgr.GetMailTemplate(It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult(template)); _ = this.TemplateMerge .Setup(tmr => tmr.CreateMailBodyUsingTemplate(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(mergedTemplate); this.EmailManager = new EmailManager(this.Configuration, this.EmailNotificationRepository.Object, this.Logger, this.TemplateManager.Object, this.TemplateMerge.Object); this.MSGraphNotificationProvider = new MSGraphNotificationProvider( this.Configuration, this.EmailAccountManager.Object, this.Logger, this.MsGraphSetting, Options.Create(retrySetting), this.TokenHelper.Object, this.MsGraphProvider.Object, this.EmailManager); _ = this.NotificationProviderFactory .Setup(provider => provider.GetNotificationProvider(NotificationProviderType.Graph)) .Returns(this.MSGraphNotificationProvider); this.EmailHandlerManager = new EmailHandlerManager(this.Configuration, this.MsGraphSetting, this.CloudStorageClient.Object, this.Logger, this.EmailManager); this.EmailServiceManager = new EmailServiceManager(this.Configuration, this.EmailNotificationRepository.Object, this.CloudStorageClient.Object, this.Logger, this.NotificationProviderFactory.Object, this.EmailManager); }