diff --git a/FlexiMail.Test.Integration/Clients/FlexiMailClientTests.SendAndCopy.cs b/FlexiMail.Test.Integration/Clients/FlexiMailClientTests.SendAndCopy.cs new file mode 100644 index 0000000..4d2e493 --- /dev/null +++ b/FlexiMail.Test.Integration/Clients/FlexiMailClientTests.SendAndCopy.cs @@ -0,0 +1,36 @@ +// --------------------------------------- +// Copyright (c) 2024 Mabrouk Mahdhi. +// Made with love for the .NET Community +// --------------------------------------- + +using FlexiMail.Models.Foundations.Bodies; +using FlexiMail.Models.Foundations.Messages; + +namespace FlexiMail.Test.Integration.Clients +{ + public partial class FlexiMailClientTests + { + [Fact] + public async void ShouldSendAndCopyMessageAsync() + { + // Given + var flexiMessage = new FlexiMessage() + { + Subject = "FlexiMessage is a cool library", + To = [GetReceiverTestEmail()], + Body = new FlexiBody + { + Content = "

This is a test

Bonjour tout le monde!

", + ContentType = BodyContentType.Html + } + }; + + // when + var sendMessageTask = + this.flexiMailClient.SendAndSaveCopyAsync(flexiMessage); + + // then + Assert.True(sendMessageTask.IsCompletedSuccessfully, "The message should be sent and copied successfully."); + } + } +} \ No newline at end of file diff --git a/FlexiMail.Test.Integration/Clients/FlexiMailClientTests.cs b/FlexiMail.Test.Integration/Clients/FlexiMailClientTests.cs new file mode 100644 index 0000000..60ca74a --- /dev/null +++ b/FlexiMail.Test.Integration/Clients/FlexiMailClientTests.cs @@ -0,0 +1,40 @@ +// --------------------------------------- +// Copyright (c) 2024 Mabrouk Mahdhi. +// Made with love for the .NET Community +// --------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using FlexiMail.Models.Configurations; + +namespace FlexiMail.Test.Integration.Clients +{ + public partial class FlexiMailClientTests + { + private readonly IFlexiMailClient flexiMailClient; + + public FlexiMailClientTests() + { + var tenantId = Environment.GetEnvironmentVariable("TenantId",EnvironmentVariableTarget.Machine); + var authority = $"https://login.microsoftonline.com/{tenantId}"; + + var configurations = new ExchangeConfigurations + { + ClientId = Environment.GetEnvironmentVariable("ClientId"), + ClientSecret = Environment.GetEnvironmentVariable("ClientSecret"), + TenantId = tenantId, + Authority = authority, + SmtpAddress = Environment.GetEnvironmentVariable("SmtpAddress"), + PrincipalName = Environment.GetEnvironmentVariable("PrincipalName"), + Sid = Environment.GetEnvironmentVariable("Sid"), + Scopes = ["https://outlook.office365.com/.default"], + }; + + this.flexiMailClient = new FlexiMailClient(configurations); + } + + private static string GetReceiverTestEmail() => + Environment.GetEnvironmentVariable("FlexiTestEmail"); + } +} \ No newline at end of file diff --git a/FlexiMail.Test.Integration/DeleteMe.cs b/FlexiMail.Test.Integration/DeleteMe.cs deleted file mode 100644 index 29505b7..0000000 --- a/FlexiMail.Test.Integration/DeleteMe.cs +++ /dev/null @@ -1,13 +0,0 @@ -// --------------------------------------- -// Copyright (c) 2024 Mabrouk Mahdhi. -// Made with love for the .NET Community -// --------------------------------------- - -namespace FlexiMail.Test.Integration -{ - public class DeleteMe - { - [Fact] - public void ShouldBeTrue() => Assert.True(true); - } -} \ No newline at end of file diff --git a/FlexiMail/FlexiMailClient.cs b/FlexiMail/FlexiMailClient.cs index a095559..9736c8b 100644 --- a/FlexiMail/FlexiMailClient.cs +++ b/FlexiMail/FlexiMailClient.cs @@ -4,6 +4,7 @@ //--------------------------------------- using System; +using System.Threading.Tasks; using FlexiMail.Brokers.Exchanges; using FlexiMail.Models.Configurations; using FlexiMail.Models.Foundations.Messages; @@ -24,8 +25,8 @@ public FlexiMailClient(ExchangeConfigurations configurations) serviceProvider.GetRequiredService(); } - public void SendAndSaveCopyAsync(FlexiMessage flexiMessage) => - this.exchangeService.SendAndSaveCopyAsync(flexiMessage); + public async ValueTask SendAndSaveCopyAsync(FlexiMessage flexiMessage) => + await this.exchangeService.SendAndSaveCopyAsync(flexiMessage); private static IServiceProvider RegisterServices(ExchangeConfigurations configurations) { diff --git a/FlexiMail/IFlexiMailClient.cs b/FlexiMail/IFlexiMailClient.cs index 5082902..ccb238a 100644 --- a/FlexiMail/IFlexiMailClient.cs +++ b/FlexiMail/IFlexiMailClient.cs @@ -3,12 +3,13 @@ // Made with love for the .NET Community // --------------------------------------- +using System.Threading.Tasks; using FlexiMail.Models.Foundations.Messages; namespace FlexiMail { public interface IFlexiMailClient { - void SendAndSaveCopyAsync(FlexiMessage flexiMessage); + ValueTask SendAndSaveCopyAsync(FlexiMessage flexiMessage); } } \ No newline at end of file