Inheritance: IEmailPackageSerialiser
        public void EmailPackageSerialiser_Deserialisation_CanHydrateAnEmailPackage()
        {
            EmailPackageSerialiser serialiser = new EmailPackageSerialiser();
            var package = serialiser.Deserialize(File.ReadAllText("SampleEmailPackage.xml"));

            Assert.That(package.From, Is.EqualTo("*****@*****.**"));
            Assert.That(package.Subject, Is.EqualTo("test email subject: {subjectToken}"));
            Assert.That(package.To, Has.Count.EqualTo(1));
            Assert.That(package.To, Has.Some.StringMatching("*****@*****.**"));
            Assert.That(package.Html.Trim(), Is.StringContaining(@"<p>html body</p>"));
            Assert.That(package.Text.Trim(), Is.StringContaining(@"text body"));
            Assert.That(package.Attachments, Has.Count.EqualTo(1));
            Assert.That(package.Attachments, Has.Some.StringContaining("D:\\workspace\\git\\EmailSystem\\EmailRelay.App.Tests.Unit\\attachment.jpg"));
        }
        public void EmailPackageSerialiser_CanSerialiseAndDeserialiseIntoEqualObject()
        {
            EmailPackageSerialiser serialiser = new EmailPackageSerialiser();
            var package = serialiser.Deserialize(File.ReadAllText("SampleEmailPackage.xml"));
            var serialised = serialiser.Serialise(package);
            var deserialised = serialiser.Deserialize(serialised);

            foreach(var propertyInfo in typeof(EmailPackage).GetProperties())
            {
                object expected = propertyInfo.GetValue(package, null);
                object actual = propertyInfo.GetValue(deserialised, null);

                Assert.AreEqual(expected, actual);
            }
        }
        public void EmailPackageSerialiser_Deserialisation_CanHydrateAnEmailPackage()
        {
            EmailPackageSerialiser serialiser = new EmailPackageSerialiser();
            var package = serialiser.Deserialize(File.ReadAllText("SampleEmailPackage.xml"));

            Assert.That(package.From, Is.EqualTo("*****@*****.**"));
            Assert.That(package.Subject, Is.EqualTo("test email subject: {subjectToken}"));
            Assert.That(package.To, Has.Count.EqualTo(1));
            Assert.That(package.To, Has.Some.InstanceOf<Recipient>().With.Property("EmailAddress").StringMatching("*****@*****.**"));
            Assert.That(package.Html.Trim(), Is.StringContaining(@"<p>html body</p>"));
            Assert.That(package.Text.Trim(), Is.StringContaining(@"text body"));
            Assert.That(package.Attachments, Has.Count.EqualTo(1));
            Assert.That(package.Attachments,
                        Has.Some.InstanceOf<Attachment>().With.Property("Path").StringContaining(@"attachment.jpg"));
        }
        public void EmailPackageSerialiser_CanSerialiseAndDeserialiseIntoEqualObject()
        {
            EmailPackageSerialiser serialiser = new EmailPackageSerialiser();
            var expected = serialiser.Deserialize(File.ReadAllText("SampleEmailPackage.xml"));
            var serialised = serialiser.Serialise(expected);
            var actual = serialiser.Deserialize(serialised);

            Assert.That(actual.To[0].EmailAddress, Is.EqualTo(expected.To[0].EmailAddress));
            Assert.That(actual.To[0].Name, Is.EqualTo(expected.To[0].Name));
               Assert.That(actual.Attachments[0].Path, Is.EqualTo(expected.Attachments[0].Path));
            Assert.That(actual.From, Is.EqualTo(expected.From));
            Assert.That(actual.Subject, Is.EqualTo(expected.Subject));
            Assert.That(actual.Html, Is.EqualTo(expected.Html));
            Assert.That(actual.Text, Is.EqualTo(expected.Text));
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            EmailProcessingConfigurationSection configuration = EmailProcessingConfigurationManager.GetConfiguration();

            XmlConfigurator.Configure();
            IEmailPackageSerialiser packageSerializer = null;
            IEmailWatcher watcher = null;
            IEmailSender sender = null;

            Console.Clear();
            var client = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(configuration.Amazon.Key,
                                                                               configuration.Amazon.Secret);
            var emails = client.ListVerifiedEmailAddresses(new ListVerifiedEmailAddressesRequest());
            Console.WriteLine("verified emails:");
            foreach(var email in emails.ListVerifiedEmailAddressesResult.VerifiedEmailAddresses)
                Console.WriteLine(email);

            try
            {
                if (!Directory.Exists(configuration.PickupLocation)) Directory.CreateDirectory(configuration.PickupLocation);
                if (!Directory.Exists(configuration.DeliveredLocation)) Directory.CreateDirectory(configuration.DeliveredLocation);
                if (!Directory.Exists(configuration.FailedLocation)) Directory.CreateDirectory(configuration.FailedLocation);

                packageSerializer = new EmailPackageSerialiser();
                watcher = new EmailWatcher(packageSerializer, configuration);
                sender = EmailSenderFactory.CreateSenderFromConfiguration(configuration);

                watcher.OnMailToSend += sender.SendMail;

                Console.WriteLine("Watching " + configuration.PickupLocation + ". Press Esc to stop");
                watcher.StartWatching();

                ConsoleKeyInfo key = new ConsoleKeyInfo();
                while (key.Key != ConsoleKey.Escape)
                    key = Console.ReadKey();
            }
            finally
            {
                if (watcher != null)
                    watcher.Dispose();
            }
        }
        public void EmailPackageSerialiser_Serialisation_CanSerialiseAnEmailPackage()
        {
            EmailPackageSerialiser serialiser = new EmailPackageSerialiser();
            EmailPackage package = Helpers.SamplePackage();
            string serialised = serialiser.Serialise(package);
            string jgnamespace = "http://www.tanash.net/email/package";

            XDocument doc = XDocument.Parse(serialised);
            var serialisedPackage = doc.Element(XName.Get("emailPackage", jgnamespace));
            Assert.That(serialisedPackage.Element(XName.Get("from", jgnamespace)).Value, Is.EqualTo(package.From));
            Assert.That(serialisedPackage.Element(XName.Get("subject", jgnamespace)).Value, Is.EqualTo(package.Subject));
            Assert.That(serialisedPackage.Element(XName.Get("html", jgnamespace)).Value, Is.EqualTo(package.Html));
            Assert.That(serialisedPackage.Element(XName.Get("text", jgnamespace)).Value, Is.EqualTo(package.Text));
            Assert.That(serialisedPackage
                            .Element(XName.Get("recipients", jgnamespace))
                            .Elements(XName.Get("address", jgnamespace)).ToList(),
                            Has.Count.EqualTo(1));
            Assert.That(serialisedPackage
                            .Element(XName.Get("attachments", jgnamespace))
                            .Elements(XName.Get("attachment", jgnamespace)).ToList(),
                            Has.Count.EqualTo(1));
        }