diff --git a/test/src/EMailling.cs b/test/src/EMailling.cs index 9031c8c0..6c58b483 100644 --- a/test/src/EMailling.cs +++ b/test/src/EMailling.cs @@ -27,17 +27,21 @@ namespace test [Fact] public void SendEMailSynchrone() { - output.WriteLine("SendEMailSynchrone ..."); - EmailSentViewModel mailSentInfo = _serverFixture._mailSender.SendEmailAsync - (_serverFixture._siteSetup.Owner.Name, _serverFixture._siteSetup.Owner.EMail, $"monthly email", "test boby monthly email").Result; - if (mailSentInfo==null) - _serverFixture._logger.LogError("No info on sending"); - else if (!mailSentInfo.Sent) - _serverFixture._logger.LogError($"{mailSentInfo.ErrorMessage}"); - else - _serverFixture._logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{_serverFixture._siteSetup.Owner.Name}"); - Assert.NotNull(mailSentInfo); - output.WriteLine($">>done with {mailSentInfo.EMail} {mailSentInfo.Sent} {mailSentInfo.MessageId} {mailSentInfo.ErrorMessage}"); + + AssertAsync.CompletesIn(2, () => + { + output.WriteLine("SendEMailSynchrone ..."); + EmailSentViewModel mailSentInfo = _serverFixture._mailSender.SendEmailAsync + (_serverFixture._siteSetup.Owner.Name, _serverFixture._siteSetup.Owner.EMail, $"monthly email", "test boby monthly email").Result; + if (mailSentInfo==null) + _serverFixture._logger.LogError("No info on sending"); + else if (!mailSentInfo.Sent) + _serverFixture._logger.LogError($"{mailSentInfo.ErrorMessage}"); + else + _serverFixture._logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{_serverFixture._siteSetup.Owner.Name}"); + Assert.NotNull(mailSentInfo); + output.WriteLine($">>done with {mailSentInfo.EMail} {mailSentInfo.Sent} {mailSentInfo.MessageId} {mailSentInfo.ErrorMessage}"); + }); } } } diff --git a/test/src/TestHelpers.cs b/test/src/TestHelpers.cs new file mode 100644 index 00000000..3898ff95 --- /dev/null +++ b/test/src/TestHelpers.cs @@ -0,0 +1,33 @@ +using System; +using System.Threading.Tasks; + +namespace test { + + public static class AssertAsync { + + public static void CompletesIn(int timeout, Action action) + { + var task = Task.Run(action); + var completedInTime = Task.WaitAll(new[] { task }, TimeSpan.FromSeconds(timeout)); + + if (task.Exception != null) + { + if (task.Exception.InnerExceptions.Count == 1) + { + throw task.Exception.InnerExceptions[0]; + } + + throw task.Exception; + } + + if (!completedInTime) + { + throw new TimeoutException($"Task did not complete in {timeout} seconds."); + } + } + } + +} + + +