Exemple #1
0
        static void ResourceFileTestInGerman()
        {
            var queue = new InMemoryMailQueue();

            var senderx = new MailSenderService(queue);

            var generator = new MailGeneratorService(queue, mailSenderService: senderx, async: false);

            var loader = new ResourceFileTemplateRepository(new DefaultResourceManagerAdapter(Templates.ResourceManager));

            loader.EnumerateTemplates(generator.Register);

            dynamic recipient = new ExpandoObject();

            recipient.email    = "*****@*****.**";
            recipient.fullname = "Bob";
            recipient.userid   = "baxtor";

            dynamic data = new ExpandoObject();

            data.link = "http://www.google.com";
            data.name = "Google";

            generator.Send(recipient, "Welcome", data, language: CultureInfo.CreateSpecificCulture("de-AT"));
        }
Exemple #2
0
        static void FolderTest()
        {
            var queue = new InMemoryMailQueue();

            var senderx = new MailSenderService(queue);

            var generator = new MailGeneratorService(queue, mailSenderService: senderx, async: false);


            var loader = new FileFolderTemplateRepository(@"..\..\templates");

            loader.EnumerateTemplates(generator.Register);

            dynamic recipient = new ExpandoObject();

            recipient.email    = "*****@*****.**";
            recipient.fullname = "Bob";
            recipient.userid   = "baxtor";

            dynamic data = new ExpandoObject();

            data.link = "http://www.google.com";
            data.name = "Google";

            generator.Send(recipient, "Welcome", data);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            //var md = new TableMetadata();

            //MetadataHelper.MetadataForClass(typeof(Dragon.Mail.SqlQueue.Mail), ref md);
            //var s = TSQLGenerator.BuildCreate(md);

            var queue = new InMemoryMailQueue();
            
            var senderx = new MailSenderService(queue);

            var generator = new MailGeneratorService(queue, mailSenderService: senderx, async: false);


            var loader = new FileFolderTemplateRepository(@"..\..\templates");

            loader.EnumerateTemplates(generator.Register);

            dynamic recipient = new ExpandoObject();
            recipient.email = "*****@*****.**";
            recipient.fullname = "Bob";
            recipient.userid = "baxtor";
            
            dynamic data = new ExpandoObject();
            data.link = "http://www.google.com";
            data.name = "Google";

            generator.Send(recipient, "Welcome", data);

            //while (senderx.ProcessNext())
            //{
            //}
        }
Exemple #4
0
        static void Basic()
        {
            // Create the main generator service
            var generatorService = new MailGeneratorService();

            // Use template helper to load templates from folder 
            // and add to generator service
            var templateFolder = new FileFolderTemplateRepository();
            templateFolder.EnumerateTemplates(generatorService.Register);

            /*
             * Send basic templated email with the service
             */
            generatorService.Send(
                /* the recipient, email is required, fullname is optional */
                new { email = "*****@*****.**" },
                /* the name of the folder to take the template files from */
                "template1",
                /* data passed to the template for e-mail generation      */
                new { title = "Example", link = "http://www.google.com" });

            /*
             * Send template in different language
             */
            generatorService.Send(
                new { email = "*****@*****.**" },
                "template1",
                new { title = "Example", link = "http://www.google.com" },
                /* pass a specific culture to use the template in that language */
                /* if no template for that culture exists, it will fall back to */
                /* the default culture specific in application configuration    */
                CultureInfo.GetCultureInfo("de"));

            /*
             * Send template with more complex data
             */
            dynamic data = new ExpandoObject();
            data.title = "Another example";

            dynamic link1 = new ExpandoObject();
            link1.name = "Google";
            link1.link = "http://www.google.com";

            dynamic link2 = new ExpandoObject();
            link2.name = "Bing";
            link2.link = "http://www.bing.com";

            dynamic link3 = new ExpandoObject();
            link3.name = "DuckDuckGo";
            link3.link = "http://www.duckduckgo.com";

            data.links = new[] { link1, link2, link3 };

            generatorService.Send(new { email = "*****@*****.**" }, "template2", data);


            /*
             * Send asynchronous email (generatorService must be configuration with async=true)
             */
            generatorService.Send(
                new
                {
                    email = "*****@*****.**",
                    userid = "unique-identifier-for-user-1",
                    bufferHours = 4,
                    ignoreBuffer = false,
                    flushBuffer = false
                },
                "template1",
                new { title = "Example", link = "http://www.google.com" },
                CultureInfo.GetCultureInfo("de"));


          /*
           * using REST resolver
           */
            generatorService.Send(
                new Uri("http://example.org/api/v1/users/123"),
                "template1",
                new {
                    title = "Example",
                    link = "http://www.google.com",
                    order = new Uri("http://example.org/api/v1/orders/17823")
                },
                CultureInfo.GetCultureInfo("de"));


        }
        public void Basic_AsyncOn()
        {
            // ARRANGE
            var senderMock = new Mock<IMailSenderService>();

            var configMock = new Mock<IConfiguration>();
            configMock.Setup(m => m.GetValue(DefaultSenderConfiguration.APP_KEY_FROM_ADDRESS))
                .Returns("*****@*****.**");
            configMock.Setup(m => m.GetValue(DefaultSenderConfiguration.APP_KEY_FROM_NAME))
                .Returns("John Doe");
            configMock.Setup(m => m.GetValue(MailGeneratorService.APP_KEY_ASYNCACTIVE))
                .Returns("1");

            dynamic url1 = new ExpandoObject();
            url1.Var1 = "Foo1";
            url1.Var2 = "Bar2";

            dynamic url2 = new ExpandoObject();
            dynamic url2sub = new ExpandoObject();
            url2.Sub1 = url2sub;
            url2sub.Var3 = "Foo3";
            url2sub.Var4 = "Bar4";

            dynamic user = new ExpandoObject();
            user.email = "*****@*****.**";
            user.fullname = "Tina Test";
            user.fname = "Tina";

            var datastoreMock = new Mock<IDataStore>();
            datastoreMock.Setup(m => m.Get(new Uri("http://example.org/url1"))).Returns((object)url1);
            datastoreMock.Setup(m => m.Get(new Uri("http://example.org/url2"))).Returns((object)url2);
            datastoreMock.Setup(m => m.Get(new Uri("http://example.org/user"))).Returns((object)user);

            var queueMock = new Mock<IMailQueue>();

            var template = new Template();
            template.Key = "key1";
            template.Content.Body = "Hello {{user.fullname}} <br/> {{two.Sub1.Var3}} {{one.Var2}}";
            template.Content.SummaryBody = "H {{user.fname}}";
            template.Content.SummaryFooter = "B {{user.fname}}";
            template.Content.SummaryHeader = "C {{user.fname}}";
            template.Content.SummarySubject = "D {{user.fname}}";

            dynamic receiver = new Uri("http://example.org/user");

            dynamic data = new ExpandoObject();
            data.one = new Uri("http://example.org/url1");
            data.two = new Uri("http://example.org/url2");
            data.user = new Uri("http://example.org/user");

            var mailService = new MailGeneratorService(
                queueMock.Object,
                datastoreMock.Object,
                configuration: configMock.Object,
                mailSenderService: senderMock.Object);

            mailService.Register(template);

            // ACT
            mailService.Send(receiver, "key1", data);

            // ASSERT
            Expression<Func<Models.Mail, bool>> mailCheck = mail =>
                mail.Sender.Address == "*****@*****.**" &&
                       mail.Sender.DisplayName == "John Doe" &&
                       mail.Receiver.Address == "*****@*****.**" &&
                       mail.Receiver.DisplayName == "Tina Test" &&
                       mail.Body == "Hello Tina Test <br/> Foo3 Bar2" &&
                       mail.SummaryBody == "H Tina" &&
                       mail.SummaryFooter == "B Tina" &&
                       mail.SummaryHeader == "C Tina" &&
                       mail.SummarySubject == "D Tina";

            queueMock.Verify(m => m.Enqueue(It.Is<Models.Mail>(mailCheck), It.IsAny<object>()));
            senderMock.Verify(m => m.ProcessNext(), Times.Never);
        }