public async void Should_Send_Emails_Simultaneously()
        {
            var email = new Email {
                To = "George", Body = "Very Important!"
            };
            var tasks = new[] { _sut.SendEmail(email), _sut.SendEmail(email), _sut.SendEmail(email), _sut.SendEmail(email) };

            await Task.WhenAll(tasks);

            _mockClient.Verify(a => a.SendEmail(email.To, email.Body), Times.Exactly(4));
        }
        public async void Should_Send_Emails_SimultaneouslyWithConcreteClient()
        {
            var email = new Email {
                To = "George", Body = "Very Important!"
            };
            var tasks = new[] { _sut2.SendEmail(email), _sut2.SendEmail(email), _sut2.SendEmail(email), _sut2.SendEmail(email) };

            var results = await Task.WhenAll(tasks);

            Assert.Equal(4, results.Length);
            Assert.True(!results.ToList().Contains("Failure."));
        }
Exemplo n.º 3
0
        public void Should_Send_Emails_to_Email_Client()
        {
            var email = new Email {
                To = "George", Body = "Very Important!"
            };

            _sut.SendEmail(email);
            _sut.SendEmail(email);
            _sut.SendEmail(email);
            _sut.SendEmail(email);

            _mockClient.Verify(call => call.SendEmail(email.To, email.Body), Times.Exactly(4));
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
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");
        }