public void SendTemplate_GivenValidEmailTemplate_SendMail()
		{
			var senderMock = new Mock<IEmailSender>();
			var mcmRepository = new Mock<IMcmRepository>();
			var service = new Portal.EmailService.EmailService(senderMock.Object);

			const string to = "*****@*****.**";
			const string from = "*****@*****.**";
			const string subject = "Test Email";

			var templateMetadataIdentifier = new MetadataIdentifier(Guid.NewGuid(), Guid.NewGuid(), null);
			var dataMetadataIdentifier = new MetadataIdentifier(Guid.NewGuid(), Guid.NewGuid(), null);
			var templateObject = CreateObjectWithMetadata(templateMetadataIdentifier, 
				string.Format("<EmailTemplate><From>{0}</From><Subject>{1}</Subject><Body><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"/\"><html><body><h1>Hallo</h1><p>How are you <xsl:value-of select=\"//Person/Name\"/>?</p></body></html></xsl:template></xsl:stylesheet></Body></EmailTemplate>",
					@from, subject));
			var dataObject = CreateObjectWithMetadata(dataMetadataIdentifier, "<Person><Name>Albert Einstein</Name></Person>");

			SendEmailRequest request = null;

			mcmRepository.Setup(r => r.ObjectGet(templateMetadataIdentifier.ObjectGuid, true, false, false, false, false)).Returns(templateObject);
			mcmRepository.Setup(r => r.ObjectGet(dataMetadataIdentifier.ObjectGuid, true, false, false, false, false)).Returns(dataObject);
			senderMock.Setup(s => s.Send(It.IsAny<SendEmailRequest>())).Callback<SendEmailRequest>(r => request = r);

			service.SendFromEmailSchema(to, mcmRepository.Object, templateMetadataIdentifier, new List<MetadataIdentifier> { dataMetadataIdentifier });

			senderMock.Verify(s => s.Send(It.IsAny<SendEmailRequest>()), Times.Once());

			Assert.That(request, Is.Not.Null);
			Assert.That(request.Message.Body.Html.Data, Is.EqualTo("<html>\r\n  <body>\r\n    <h1>Hallo</h1>\r\n    <p>How are you Albert Einstein?</p>\r\n  </body>\r\n</html>"));
		}
Ejemplo n.º 2
0
        public void Send_GivenSingleTo_SendSingleEmail()
        {
            var senderMock = new Mock<IEmailSender>();
            var service = new Portal.EmailService.EmailService(senderMock.Object);

            const string to = "*****@*****.**";
            const string from = "*****@*****.**";
            const string subject = "Test Email";
            const string body = "<div>Hallo test</div>";

            SendEmailRequest request = null;

            senderMock.Setup(s => s.Send(It.IsAny<SendEmailRequest>())).Callback<SendEmailRequest>(r => request = r);

            service.Send(from, to, subject, body);

            senderMock.Verify( s => s.Send(It.IsAny<SendEmailRequest>()), Times.Once());

            Assert.That(request, Is.Not.Null);
            Assert.That(request.Source, Is.EqualTo(from));
            Assert.That(request.Destination.ToAddresses, Is.Not.Null);
            Assert.That(request.Destination.ToAddresses.Count, Is.EqualTo(1));
            Assert.That(request.Destination.ToAddresses.First(), Is.EqualTo(to));
            Assert.That(request.Message.Subject.Data, Is.EqualTo(subject));
            Assert.That(request.Message.Body.Html.Data, Is.EqualTo(body));
        }
Ejemplo n.º 3
0
        public void Send_Given51Tos_SendTwoBatches()
        {
            var senderMock = new Mock<IEmailSender>();
            var service = new Portal.EmailService.EmailService(senderMock.Object);

            var tos = new List<string>();
            const string from = "*****@*****.**";
            const string subject = "Test Email";
            const string body = "<div>Hallo test</div>";

            for (var i = 0; i < 51; i++)
                tos.Add(string.Format("MyMail{0}@test.test", i));

            IList<SendEmailRequest> request = new List<SendEmailRequest>();

            senderMock.SetupGet(s => s.MaxRecipientPerBatch).Returns(50);
            senderMock.Setup(s => s.Send(It.IsAny<SendEmailRequest>())).Callback<SendEmailRequest>(request.Add);

            service.Send(from, tos, null, subject, body);

            senderMock.Verify(s => s.Send(It.IsAny<SendEmailRequest>()), Times.Exactly(2));

            Assert.That(request.Count, Is.EqualTo(2));
            Assert.That(request.First().Destination.ToAddresses.Count, Is.EqualTo(50));
            Assert.That(request.Skip(1).First().Destination.ToAddresses.Count, Is.EqualTo(1));
        }
Ejemplo n.º 4
0
        public void Send_GivenTemplate_TransformData()
        {
            var senderMock = new Mock<IEmailSender>();
            IEmailService service = new Portal.EmailService.EmailService(senderMock.Object);

            const string to = "*****@*****.**";
            const string from = "*****@*****.**";
            const string subject = "Test Email";
            var template = XElement.Load("EmailService/EmailTemplate01.xml");
            var data = XElement.Parse("<Person><Name>Albert Einstein</Name></Person>");

            SendEmailRequest request = null;

            senderMock.Setup(s => s.Send(It.IsAny<SendEmailRequest>())).Callback<SendEmailRequest>(r => request = r);

            service.SendTemplate(from, to, subject, template, data);

            Assert.That(request, Is.Not.Null);
            Assert.That(request.Message.Body.Html.Data, Is.EqualTo("<html>\r\n  <body>\r\n    <h1>Hallo</h1>\r\n    <p>\r\n\t\t\t\t\tHow are you Albert Einstein?\r\n\t\t\t\t</p>\r\n  </body>\r\n</html>"));
        }
Ejemplo n.º 5
0
        public void Send_GivenTemplateAndMultipleData_TransformData()
        {
            var senderMock = new Mock<IEmailSender>();
            IEmailService service = new Portal.EmailService.EmailService(senderMock.Object);

            const string to = "*****@*****.**";
            const string from = "*****@*****.**";
            const string subject = "Test Email";
            var template = XElement.Load("EmailService/EmailTemplate02.xml");
            var datas = new List<XElement>
            {
                XElement.Parse("<Person><Name>Richard Dawkins</Name></Person>"),
                XElement.Parse("<Order><Name>The God Delusion</Name></Order>")
            };

            SendEmailRequest request = null;

            senderMock.Setup(s => s.Send(It.IsAny<SendEmailRequest>())).Callback<SendEmailRequest>(r => request = r);

            service.SendTemplate(from, to, subject, template, datas);

            Assert.That(request, Is.Not.Null);
            Assert.That(request.Message.Body.Html.Data, Is.EqualTo("<html>\r\n  <body>\r\n    <h1>Hallo</h1>\r\n    <p>\r\n\t\t\t\t\tHow are you Richard Dawkins?\r\n\t\t\t\t</p>\r\n    <p>\r\n\t\t\t\t\tYou ordered The God Delusion.\r\n\t\t\t\t</p>\r\n  </body>\r\n</html>"));
        }