a test timeout ...
This commit is contained in:
parent
3c1d2c49f5
commit
262edc499b
2 changed files with 48 additions and 11 deletions
|
|
@ -27,17 +27,21 @@ namespace test
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SendEMailSynchrone()
|
public void SendEMailSynchrone()
|
||||||
{
|
{
|
||||||
output.WriteLine("SendEMailSynchrone ...");
|
|
||||||
EmailSentViewModel mailSentInfo = _serverFixture._mailSender.SendEmailAsync
|
AssertAsync.CompletesIn(2, () =>
|
||||||
(_serverFixture._siteSetup.Owner.Name, _serverFixture._siteSetup.Owner.EMail, $"monthly email", "test boby monthly email").Result;
|
{
|
||||||
if (mailSentInfo==null)
|
output.WriteLine("SendEMailSynchrone ...");
|
||||||
_serverFixture._logger.LogError("No info on sending");
|
EmailSentViewModel mailSentInfo = _serverFixture._mailSender.SendEmailAsync
|
||||||
else if (!mailSentInfo.Sent)
|
(_serverFixture._siteSetup.Owner.Name, _serverFixture._siteSetup.Owner.EMail, $"monthly email", "test boby monthly email").Result;
|
||||||
_serverFixture._logger.LogError($"{mailSentInfo.ErrorMessage}");
|
if (mailSentInfo==null)
|
||||||
else
|
_serverFixture._logger.LogError("No info on sending");
|
||||||
_serverFixture._logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{_serverFixture._siteSetup.Owner.Name}");
|
else if (!mailSentInfo.Sent)
|
||||||
Assert.NotNull(mailSentInfo);
|
_serverFixture._logger.LogError($"{mailSentInfo.ErrorMessage}");
|
||||||
output.WriteLine($">>done with {mailSentInfo.EMail} {mailSentInfo.Sent} {mailSentInfo.MessageId} {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}");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
33
test/src/TestHelpers.cs
Normal file
33
test/src/TestHelpers.cs
Normal file
|
|
@ -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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue