Skip to content

Commit

Permalink
ShouldSendAndCopyMessageAsync -> FAIL
Browse files Browse the repository at this point in the history
  • Loading branch information
mabroukmahdhi committed Aug 11, 2024
1 parent 6ddf20b commit cbab9dc
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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()

Check warning on line 14 in FlexiMail.Test.Integration/Clients/FlexiMailClientTests.SendAndCopy.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 14 in FlexiMail.Test.Integration/Clients/FlexiMailClientTests.SendAndCopy.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// Given
var flexiMessage = new FlexiMessage()
{
Subject = "FlexiMessage is a cool library",
To = [GetReceiverTestEmail()],
Body = new FlexiBody
{
Content = "<h3>This is a test</h3><p>Bonjour tout le monde!</p>",
ContentType = BodyContentType.Html
}
};

// when
var sendMessageTask =
this.flexiMailClient.SendAndSaveCopyAsync(flexiMessage);

// then
Assert.True(sendMessageTask.IsCompletedSuccessfully, "The message should be sent and copied successfully.");
}
}
}
40 changes: 40 additions & 0 deletions FlexiMail.Test.Integration/Clients/FlexiMailClientTests.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
13 changes: 0 additions & 13 deletions FlexiMail.Test.Integration/DeleteMe.cs

This file was deleted.

5 changes: 3 additions & 2 deletions FlexiMail/FlexiMailClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//---------------------------------------

using System;
using System.Threading.Tasks;
using FlexiMail.Brokers.Exchanges;
using FlexiMail.Models.Configurations;
using FlexiMail.Models.Foundations.Messages;
Expand All @@ -24,8 +25,8 @@ public FlexiMailClient(ExchangeConfigurations configurations)
serviceProvider.GetRequiredService<IFlexiExchangeService>();
}

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)
{
Expand Down
3 changes: 2 additions & 1 deletion FlexiMail/IFlexiMailClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit cbab9dc

Please sign in to comment.