Ejemplo n.º 1
0
        public void Should_Handle_Connection_Failure()
        {
            var email = new Email {
                To = "George", Body = "Very Important!"
            };

            // assume maxConnections is 10, so that I can test boundary value using 11
            var client    = new EmailClient(10);
            var _eService = new EmailingService(client, _mockLogger.Object);

            int numFailure = 0;

            // try concurrency within 5s to test the boundary value using 11
            Parallel.For(0, 11, i =>
            {
                try
                {
                    var res = _eService.SendEmail(email);

                    if (res == "Failure.")
                    {
                        numFailure++;
                    }
                }
                catch (Exception)
                {
                }
            });


            Assert.True(numFailure > 0, "No Connection error found");
        }
Ejemplo n.º 2
0
        public void Should_Handle_Unexpected_Failure()
        {
            var email = new Email {
                To = "George", Body = "Very Important!"
            };


            var _mockClient1 = new EmailClient(100);

            var _eService = new EmailingService(_mockClient1, _mockLogger.Object);

            int numFailure = 0;

            Parallel.For(0, 20, i =>
            {
                try
                {
                    _eService.SendEmail(email);
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("Unexpected Error"))
                    {
                        numFailure++;
                    }
                }
            });

            Assert.True(numFailure > 0, "No Connection error found");
        }
 public EmailingServiceTests()
 {
     _mockClient  = new Mock <IEmailClient>();
     _mockClient2 = new EmailClient(100, 10);
     _mockLogger  = new Mock <ILogger <EmailingService> >();
     _sut         = new EmailingService(_mockClient.Object, _mockLogger.Object);
     _sut2        = new EmailingService(_mockClient2, _mockLogger.Object);
 }
Ejemplo n.º 4
0
        public async Task TestSendMessage()
        {
            const string content    = "content";
            const string mail       = "*****@*****.**";
            var          options    = new Settings("host");
            var          mokeClient = new MokeSmtpClient(message =>
            {
                Assert.AreEqual(content, message.Body);
                Assert.AreEqual(new MailAddress("noreply@host"), message.From);
            });
            var service = new EmailingService(options, mokeClient);

            await service.SendMessage(mail, content);
        }
Ejemplo n.º 5
0
        public static void RegisterConfig(HttpApplication httpApplication)
        {
            // Connection string (we need to have this first, to start logging)
            Config.Database.ConnectionString = AppInfo.WebConfig.ConnectionString;

            // Paths
            Config.Paths.Application    = httpApplication.Server.MapPath("~");
            Config.Paths.Temp           = httpApplication.Server.MapPath("~/Temp");
            Config.Paths.EmailTemplates = httpApplication.Server.MapPath("~/Content/Emails");

            // Load all other configs from database
            //ConfigService.LoadConfig();

            // Initialize temp folder
            FileService.InitializeTempFolder();

            // Set Config refresh task (Disabled for now, it was clogging the event log)
            // ConfigService.SetupRefreshConfigTask();

            // Path for the email templates
            EmailingService.EmailTemplatePath = Config.Paths.EmailTemplates;
            EmailingService.EmailingEnabled   = true;
            EmailingService.StartQueueManager();
        }