public void Enumerate_LoadsTextFilesCorrectly()
        {
            // ARRANGE
            var fsMock = new Mock<IFileSystem>();
            fsMock.Setup(m => m.ExistDir(It.IsAny<string>())).Returns(true);

            var fsMock2 = new InMemoryFileSystem(fsMock.Object);

            var defaultCulture = "en-US";
            CreateTemplateSet(fsMock2, @"c:\mock", "t1", null, defaultCulture, "txt");
            CreateTemplateSet(fsMock2, @"c:\mock", "t1", "de", defaultCulture, "txt");
            CreateTemplateSet(fsMock2, @"c:\mock", "t2", null, defaultCulture, "txt");
            CreateTemplateSet(fsMock2, @"c:\notinrightdir", "t3", null, defaultCulture, "txt");

            var configMock = new Mock<IConfiguration>();
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_FOLDER))
                .Returns(@"c:\mock");
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_DEFLANG))
                .Returns(defaultCulture);

            // ACT
            var queue = new FileFolderTemplateRepository(
                configuration: configMock.Object,
                fileSystem: fsMock2);

            var templates = new List<Template>();
            queue.EnumerateTemplates(templates.Add);

            // ASSERT
            Assert.AreEqual(3, templates.Count);

            AssertTemplateContents(templates, "t1", "en-US");
            AssertTemplateContents(templates, "t1", "de");
            AssertTemplateContents(templates, "t2", "en-US");
        }
Пример #2
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())
            //{
            //}
        }
        public void NoBaseDirectoryThrowsException()
        {
            // ARRANGE

            // ACT
            var queue = new FileFolderTemplateRepository(null);

            // ASSERT
        }
        public void InvalidCultureThrowsException()
        {
            // ARRANGE
            var fsMock = new Mock<IFileSystem>();

            var configMock = new Mock<IConfiguration>();
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_FOLDER))
                .Returns(@"\-hamster-/");
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_DEFLANG))
                .Returns(@"does-not-exist-as-a-culture");

            // ACT
            var queue = new FileFolderTemplateRepository(
                configuration: configMock.Object,
                fileSystem: fsMock.Object);

            // ASSERT
        }
        public void Enumerate_LoadsTextAndHtmlFilesCorrectlyWithincludes()
        {
            // ARRANGE
            var fsMock = new Mock<IFileSystem>();
            fsMock.Setup(m => m.ExistDir(It.IsAny<string>())).Returns(true);

            var fsMock2 = new InMemoryFileSystem(fsMock.Object);
            var basedir = @"c:\mock";
            var defaultCulture = "en-US";

            fsMock2.Save(Path.Combine(basedir, "t1", "body.txt"), "Hi @inc(body2.txt) bob");
            fsMock2.Save(Path.Combine(basedir, "t1", "body2.txt"), "alice");

            fsMock2.Save(Path.Combine(basedir, "t1", "body.html"), "Hi @inc(body2.html) john");
            fsMock2.Save(Path.Combine(basedir, "t1", "body2.html"), "mary");
           
            var configMock = new Mock<IConfiguration>();
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_FOLDER))
                .Returns(basedir);
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_DEFLANG))
                .Returns(defaultCulture);

            // ACT
            var queue = new FileFolderTemplateRepository(
                configuration: configMock.Object,
                fileSystem: fsMock2);

            var templates = new List<Template>();
            queue.EnumerateTemplates(templates.Add);

            // ASSERT
            Assert.AreEqual(1, templates.Count);

            var t = templates.FirstOrDefault(x => x.Key =="t1" && x.Language.Name.StartsWith("en"));

            Assert.AreEqual("Hi alice bob", t.Content.TextBody);
            Assert.AreEqual("Hi mary john", t.Content.Body);

        }
Пример #6
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"));


        }