Ejemplo n.º 1
0
        public void RemoveMissingParametersRemovesThem()
        {
            var testOptions    = Options.Create <NoticeEmailOptions> (new NoticeEmailOptions());
            var templateString = "This is a template with a %%Parameters%%";
            var expected       = "This is a template with a ";
            var cut            = new NoticeEmail(testOptions, null, null, fileSystem);
            var actual         = cut.RemoveMissingParameters(templateString);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        public NoticeAsAttachmentNoticeProviderTests()
        {
            var noticeStorageOptions = Options.Create <NoticeStorageOptions>(
                new NoticeStorageOptions {
                ConnectionString = "UseDevelopmentStorage=true",
                ApplicationName  = "notice"
            });

            _noticeStorageService = new NoticeStorageService(noticeStorageOptions, null);
            _documentService      = new NoticeDocumentService(null, new FileSystem(), _noticeStorageService, GetDocumentOptions());
            _emailService         = new NoticeEmail(GetEmailOptions(), null, _noticeStorageService, new FileSystem());
        }
Ejemplo n.º 3
0
        public void LoadTemplateReturnsData()
        {
            var testOptions = Options.Create <NoticeEmailOptions> (
                new NoticeEmailOptions
            {
                EmailTemplateFolder = @"c:\approot\emailTemplates"
            });

            string expected = testHtml;

            var cut    = new NoticeEmail(testOptions, null, null, fileSystem);
            var actual = cut.LoadTemplate("testtemplate.html");

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 4
0
        public void GetSubjectReturnsSubject()
        {
            var testOptions = Options.Create <NoticeEmailOptions> (new NoticeEmailOptions());
            var parameters  = new Dictionary <string, string> ()
            {
                { "Subject", "subject" }
            };

            var expected = parameters["Subject"];

            var cut    = new NoticeEmail(testOptions, null, null, fileSystem);
            var actual = cut.GetSubject(parameters);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 5
0
        public void GetSubjectReturnsSubjectThatLooksOKWhenAParameterIsMissing()
        {
            var testOptions = Options.Create <NoticeEmailOptions> (new NoticeEmailOptions());
            var parameters  = new Dictionary <string, string> ()
            {
                { "Subject", "%%Reminder%%Subject with %%Replacement1%% and %%Replacement2%%" }, { "Replacement1", "replacement1" }, { "Replacement2", "replacement2" }
            };

            var expected = "Subject with replacement1 and replacement2";

            var cut    = new NoticeEmail(testOptions, null, null, fileSystem);
            var actual = cut.GetSubject(parameters);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 6
0
        public void GetFromMailboxAddressReturnsValue()
        {
            var testOptions = Options.Create <NoticeEmailOptions> (new NoticeEmailOptions
            {
                EmailSenderAddress = "*****@*****.**",
                EmailSenderName    = "someone"
            });

            var expected = new MailboxAddress(testOptions.Value.EmailSenderName, testOptions.Value.EmailSenderAddress);

            var cut    = new NoticeEmail(testOptions, null, null, fileSystem);
            var actual = cut.GetFromMailboxAddress();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 7
0
        public void ReplaceParametersReplacesEverything()
        {
            var testOptions = Options.Create <NoticeEmailOptions> (new NoticeEmailOptions());
            var template    = "token1=%%Token1%%, token2=%%Token2%%, token3=%%Token3%%";
            var parameters  = new Dictionary <string, string>
            {
                { "Token1", "token1" },
                { "Token2", "token2" },
                { "Token3", "token3" },
            };

            var expected = "token1=token1, token2=token2, token3=token3";
            var cut      = new NoticeEmail(testOptions, null, null, fileSystem);
            var actual   = cut.ReplaceParameters(template, parameters);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 8
0
        public void LoadTemplateThrowsExceptionWhenMessingTemplateFolderOption()
        {
            var testOptions = Options.Create <NoticeEmailOptions> (new NoticeEmailOptions());

            var  expected = typeof(EmailServiceException);
            Type actual   = null;

            try
            {
                var cut = new NoticeEmail(testOptions, null, null, fileSystem);
                cut.LoadTemplate("testfolder");
            }
            catch (Exception ex)
            {
                actual = ex.GetType();
            }
        }
Ejemplo n.º 9
0
        public async Task CanSendEmail()
        {
            var recipients = new List <string> {
                "*****@*****.**"
            };
            var parameters = new Dictionary <string, string>
            {
                { "Link1HREF", "Link1HREF" },
                { "Link1Title", "Link1Title" },
                { "Subject", "%%Reminder%%Subject with %%Link1Title%%" }
            };

            var cut = new NoticeEmail(_testOptions, null, _noticeStorageService, new FileSystem());

            var archiveFile = await cut.SendNoticeEmail(_emailTemplate, recipients, parameters);

            Assert.NotNull(archiveFile);
        }
Ejemplo n.º 10
0
        public void GetToMailboxAddressesThrowsExceptionForNullAddressList()
        {
            var testOptions = Options.Create <NoticeEmailOptions> (new NoticeEmailOptions());

            var  expected = typeof(EmailServiceException);
            Type actual   = null;

            try
            {
                var cut = new NoticeEmail(testOptions, null, null, fileSystem);
                cut.GetToMailboxAddresses(null);
            }
            catch (Exception ex)
            {
                actual = ex.GetType();
            }
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 11
0
        public void GetSubjectThrowExceptionIfThereIsNotSubjectParameter()
        {
            var testOptions = Options.Create <NoticeEmailOptions> (new NoticeEmailOptions());
            var parameters  = new Dictionary <string, string> ();

            var  expected = typeof(EmailServiceException);
            Type actual   = null;

            try
            {
                var cut = new NoticeEmail(testOptions, null, null, fileSystem);
                cut.GetSubject(null);
            }
            catch (Exception ex)
            {
                actual = ex.GetType();
            }
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 12
0
        public void GetToMailboxAddressesReturnsProperMailboxAddresses()
        {
            var testOptions   = Options.Create <NoticeEmailOptions> (new NoticeEmailOptions());
            var recipientList = new List <string>
            {
                "*****@*****.**",
                "*****@*****.**"
            };
            var expected = new List <MailboxAddress>
            {
                new MailboxAddress("*****@*****.**"),
                new MailboxAddress("*****@*****.**")
            };

            var cut    = new NoticeEmail(testOptions, null, null, fileSystem);
            var actual = cut.GetToMailboxAddresses(recipientList);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 13
0
        public void LoadTemplateThrowsOnBadTemplateFilename()
        {
            IOptions <NoticeEmailOptions> testOptions = Options.Create <NoticeEmailOptions> (
                new NoticeEmailOptions
            {
                EmailTemplateFolder = @"c:\approot\emailTemplates"
            });

            var  expected = typeof(EmailServiceException);
            Type actual   = null;

            try
            {
                var cut = new NoticeEmail(testOptions, null, null, fileSystem);
                cut.LoadTemplate("BadFile.html");
            }
            catch (Exception ex)
            {
                actual = ex.GetType();
            }
        }
Ejemplo n.º 14
0
        public void LoadBodyReturnsBody()
        {
            IOptions <NoticeEmailOptions> testOptions = Options.Create <NoticeEmailOptions> (
                new NoticeEmailOptions
            {
                EmailTemplateFolder = @"c:\approot\emailTemplates"
            });

            string expected = @"<p>You have been notified</p><p> Click here to see your notice <a href='NoticeHREF'>LinkTitle</a></p>";

            var parameters = new Dictionary <string, string>
            {
                { "NoticeHREF", "NoticeHREF" },
                { "LinkTitle", "LinkTitle" }
            };

            var cut    = new NoticeEmail(testOptions, null, null, fileSystem);
            var actual = cut.LoadBody("testtemplate.html", parameters);

            Assert.Equal(expected, actual, true, true);
        }
Ejemplo n.º 15
0
        public void GetFromMailboxAddressThrowsExceptionNoEmailSenderAddressOption()
        {
            IOptions <NoticeEmailOptions> testOptions = Options.Create <NoticeEmailOptions> (
                new NoticeEmailOptions
            {
                EmailSenderAddress = "someName"
            });

            var  expected = typeof(EmailServiceException);
            Type actual   = null;

            try
            {
                var cut = new NoticeEmail(testOptions, null, null, fileSystem);
                cut.GetFromMailboxAddress();
            }
            catch (Exception ex)
            {
                actual = ex.GetType();
            }
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 16
0
        // Connect to the Azure Cosmos DB Emulator running locally
        // DocumentClient client = new DocumentClient(
        //     new Uri("https://localhost:8081"),
        //     "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");

        public DCNoticeProviderTests()
        {
            // EndpointUrl;
            // _authorizationKey = options.Value.AuthorizationKey;
            // _databaseId = options.Value.DatabaseId;
            // _collectionId = options.Value.CollectionId;


            var noticeStorageOptions = Options.Create <NoticeStorageOptions> (
                new NoticeStorageOptions
            {
                ConnectionString = "UseDevelopmentStorage=true",
                ApplicationName  = "notice",
                EndpointUrl      = "https://localhost:8081",
                AuthorizationKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
                DatabaseId       = "Notices",
                CollectionId     = "NoticeRecords"
            });

            _noticeStorageService = new NoticeStorageService(noticeStorageOptions, null);

            _documentService = new NoticeDocumentService(null, new FileSystem(), _noticeStorageService, GetDocumentOptions());
            _emailService    = new NoticeEmail(GetEmailOptions(), null, _noticeStorageService, new FileSystem());
        }