54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using CM.Authentication.Abstractions;
|
|
using CM.TransactionalEmail;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace CM.Tests;
|
|
|
|
public class TransactionalEmailTests(TestFixture fixture, ITestOutputHelper output) : IClassFixture<TestFixture>
|
|
{
|
|
[Fact]
|
|
public async Task AuthenticationAsync()
|
|
{
|
|
var jwtTokenManagerService = fixture.ServiceProvider.GetRequiredService<IJwtTokenManagerService>();
|
|
|
|
var response = await jwtTokenManagerService.GetTokenAsync();
|
|
output.WriteLine("Successfully receive token type {0}", response.TokenType.ToString());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SendEmailAsync()
|
|
{
|
|
var configuration = fixture.ServiceProvider.GetRequiredService<IConfiguration>();
|
|
var transactionalEmailService = fixture.ServiceProvider.GetRequiredService<TransactionalEmailService>();
|
|
|
|
var testRecipient = configuration["TestRecipient"];
|
|
var senderId = configuration["SenderId"];
|
|
|
|
Assert.NotNull(testRecipient);
|
|
Assert.NotNull(senderId);
|
|
|
|
await transactionalEmailService.SendEmailAsync(new SendEmailOptions
|
|
{
|
|
Email = testRecipient,
|
|
Sender = new Sender
|
|
{
|
|
Id = senderId
|
|
},
|
|
Content = new EmailContent
|
|
{
|
|
Subject = "Send Email Test",
|
|
Text = "Test Email",
|
|
Encoding = EmailEncoding.Utf8,
|
|
},
|
|
Tracking = new TrackingOptions
|
|
{
|
|
ClicksHtml = false,
|
|
ClicksText = false,
|
|
Opens = true
|
|
},
|
|
Queue = 0
|
|
});
|
|
}
|
|
} |