Skip to content

Commit fe6f017

Browse files
chore: update unit tests to xunit and Awesome Assertions (#32)
* chore: update testing credentials Can now set credentials for testing in a .env file * chore: update testing credentials Can now set credentials for testing in a .env file * chore: make unit tests better in parallel * fixed missing checks for credentials * Migrate test suite from XUnit v3 to TUnit v0.73.19 (#31) * Initial plan * Migrate from XUnit v3 to TUnit v0.73.19 Co-authored-by: JohnCampionJr <[email protected]> * Update skipped tests to use Skip.Test() instead of early return Co-authored-by: JohnCampionJr <[email protected]> * code tidying --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: JohnCampionJr <[email protected]> Co-authored-by: John Campion Jr <[email protected]> * Revert "Migrate test suite from XUnit v3 to TUnit v0.73.19 (#31)" This reverts commit fd419a3. * tidied code --------- Co-authored-by: Copilot <[email protected]>
1 parent 5ef0119 commit fe6f017

40 files changed

+2333
-2120
lines changed

.github/workflows/dotnet-core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Build & Test
22

33
on:
44
pull_request:
5-
branches: [master]
5+
branches: [main]
66

77
jobs:
88
build:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,5 @@ ModelManifest.xml
246246

247247
# Verify test files
248248
*.received.txt
249+
250+
.env

FluentEmail.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
44
VisualStudioVersion = 17.4.33205.214
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6DC215BD-05EF-49A6-ADBE-8AE399952EEC}"
7+
ProjectSection(SolutionItems) = preProject
8+
test\Directory.Build.props = test\Directory.Build.props
9+
EndProjectSection
710
EndProject
811
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D5C44238-0312-43F8-9705-EACFB039A48C}"
912
EndProject

FluentEmail.sln.DotSettings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=endfor/@EntryIndexedValue">True</s:Boolean>
3+
<s:Boolean x:Key="/Default/UserDictionary/Words/=logotest/@EntryIndexedValue">True</s:Boolean>
4+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mailtrap/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/FluentEmail.Core/FluentEmail.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
<ItemGroup>
23-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
23+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
2424
</ItemGroup>
2525

2626
</Project>

src/Senders/FluentEmail.Mailtrap/MailtrapSender.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace FluentEmail.Mailtrap
1919
/// </summary>
2020
public class MailtrapSender : IMailtrapSender, IDisposable
2121
{
22-
private const string URL = "https://send.api.mailtrap.io/api/send";
2322
private readonly SmtpClient _smtpClient;
2423
private static readonly int[] ValidPorts = {25,587, 2525};
2524
private readonly string _apiKey;
25+
private readonly string _apiHost;
2626

2727
/// <summary>
2828
/// Creates a sender that uses the given Mailtrap credentials, but does not dispose it.
@@ -31,7 +31,7 @@ public class MailtrapSender : IMailtrapSender, IDisposable
3131
/// <param name="password">Password of your mailtrap.io SMTP inbox</param>
3232
/// <param name="host">Host address for the Mailtrap.io SMTP inbox</param>
3333
/// <param name="port">Port for the Mailtrap.io SMTP server. Accepted values are 25, 465 or 2525.</param>
34-
public MailtrapSender(string userName, string password, string host = "smtp.mailtrap.io", int? port = null)
34+
public MailtrapSender(string userName, string password, string host = "smtp.mailtrap.io", int? port = null, string apiHost = "https://send.api.mailtrap.io/api/send")
3535
{
3636
if (string.IsNullOrWhiteSpace(userName))
3737
throw new ArgumentException("Mailtrap UserName needs to be supplied", nameof(userName));
@@ -42,6 +42,7 @@ public MailtrapSender(string userName, string password, string host = "smtp.mail
4242
if (port.HasValue && !ValidPorts.Contains(port.Value))
4343
throw new ArgumentException("Mailtrap Port needs to be either 25, 465 or 2525", nameof(port));
4444
_apiKey = password;
45+
_apiHost = apiHost;
4546
_smtpClient = new SmtpClient(host, port.GetValueOrDefault(587))
4647
{
4748
Credentials = new NetworkCredential(userName, password),
@@ -66,12 +67,12 @@ public Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken? token
6667
public async Task<SendResponse> SendWithTemplateAsync(IFluentEmail email, string templateName, object templateData, CancellationToken? token = null)
6768
{
6869
token?.ThrowIfCancellationRequested();
69-
using (var httpClient = new HttpClient { BaseAddress = new Uri(URL) })
70+
using (var httpClient = new HttpClient { BaseAddress = new Uri(_apiHost) })
7071
{
7172
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
7273
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
7374
var jsonContent = HttpClientHelpers.GetJsonBody(BuildMailtrapParameters(email, templateName, templateData));
74-
var response = await httpClient.Post<MailtrapResponse>(URL, jsonContent);
75+
var response = await httpClient.Post<MailtrapResponse>(_apiHost, jsonContent);
7576
var result = new SendResponse { MessageId = response.Data?.Id };
7677
if (!response.Success)
7778
{

test/Directory.Build.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
<IsPackable>false</IsPackable>
55
<IsTestProject>true</IsTestProject>
66
<TargetFramework>net8.0</TargetFramework>
7-
<OutputType>Exe</OutputType>
87
</PropertyGroup>
98

109
<ItemGroup>
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
1211
<PackageReference Include="xunit.v3" Version="3.1.0" />
1312
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
1413
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

test/FluentEmail.Bootstrap.Tests/BootstrapTests.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Threading.Tasks;
66
using FluentEmail.Core;
7+
using FluentEmail.Core.Interfaces;
78
using FluentEmail.Liquid;
89
using Fluid;
910
using Microsoft.Extensions.FileProviders;
@@ -25,11 +26,9 @@ public BootstrapTests()
2526
{
2627
_settings.ScrubLinesContaining("Compiled with Bootstrap Email DotNet");
2728
_settings.DisableDiff();
28-
// default to have no file provider, only required when layout files are in use
29-
SetupRenderer();
3029
}
3130

32-
private static void SetupRenderer(
31+
private static ITemplateRenderer SetupRenderer(
3332
IFileProvider fileProvider = null,
3433
Action<TemplateContext, object> configureTemplateContext = null)
3534
{
@@ -38,7 +37,7 @@ private static void SetupRenderer(
3837
FileProvider = fileProvider,
3938
ConfigureTemplateContext = configureTemplateContext,
4039
};
41-
Email.DefaultRenderer = new LiquidRenderer(Options.Create(options));
40+
return new LiquidRenderer(Options.Create(options));
4241
}
4342

4443
[Fact]
@@ -51,11 +50,13 @@ public Task CompileBootstrap_Compiles()
5150
</body>
5251
</html>
5352
""";
54-
var email = Email
55-
.From(FromEmail)
53+
var email = new Email(FromEmail)
54+
{
55+
Renderer = SetupRenderer()
56+
}
5657
.To(ToEmail)
5758
.Subject(Subject)
58-
.UsingTemplate(template, new ViewModel { Name = "LUKE", Numbers = new[] { "1", "2", "3" } })
59+
.UsingTemplate(template, new ViewModel { Name = "LUKE", Numbers = ["1", "2", "3"] })
5960
.CompileBootstrap();
6061

6162
return Verifier.Verify(email.Data.Body, _settings);
@@ -71,8 +72,10 @@ public Task UsingBootstrapBody_Compiles()
7172
</body>
7273
</html>
7374
""";
74-
var email = Email
75-
.From(FromEmail)
75+
var email = new Email(FromEmail)
76+
{
77+
Renderer = SetupRenderer()
78+
}
7679
.To(ToEmail)
7780
.Subject(Subject)
7881
.UsingBootstrapBody(body);
@@ -91,11 +94,13 @@ public Task UsingBootstrapTemplate_Compiles()
9194
</body>
9295
</html>
9396
""";
94-
var email = Email
95-
.From(FromEmail)
97+
var email = new Email(FromEmail)
98+
{
99+
Renderer = SetupRenderer()
100+
}
96101
.To(ToEmail)
97102
.Subject(Subject)
98-
.UsingBootstrapTemplate(template, new ViewModel { Name = "LUKE", Numbers = new[] { "1", "2", "3" } });
103+
.UsingBootstrapTemplate(template, new ViewModel { Name = "LUKE", Numbers = ["1", "2", "3"] });
99104

100105
return Verifier.Verify(email.Data.Body, _settings);
101106
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
54
<PreserveCompilationContext>true</PreserveCompilationContext>
6-
<LangVersion>preview</LangVersion>
75
</PropertyGroup>
86

97
<ItemGroup>
@@ -12,10 +10,9 @@
1210
</ItemGroup>
1311

1412
<ItemGroup>
15-
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.21" />
1614
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.0.0" />
17-
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.11.1" />
18-
<PackageReference Include="Verify.XunitV3" Version="31.0.2" />
15+
<PackageReference Include="Verify.XunitV3" Version="31.0.3" />
1916
</ItemGroup>
20-
17+
2118
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FE_TEST_TO_EMAIL=
2+
FE_TEST_FROM_EMAIL=
3+
4+
# MailTrap Tests Credentials
5+
FE_TEST_MAILTRAP_TO_EMAIL=
6+
FE_TEST_MAILTRAP_FROM_EMAIL=
7+
FE_TEST_MAILTRAP_HOST=
8+
FE_TEST_MAILTRAP_USER=
9+
FE_TEST_MAILTRAP_PWD=
10+
FE_TEST_MAILTRAP_PORT=587
11+
FE_TEST_MAILTRAP_API_HOST=
12+
FE_TEST_MAILTRAP_API_KEY=
13+
FE_TEST_MAILTRAP_TEMPLATE=
14+
15+
# MailGun Tests Credentials
16+
FE_TEST_MAILGUN_TO_EMAIL=
17+
FE_TEST_MAILGUN_FROM_EMAIL=
18+
FE_TEST_MAILGUN_DOMAIN=
19+
FE_TEST_MAILGUN_API_KEY=
20+
21+
# Azure Email Service Credentials
22+
FE_TEST_AZURE_TO_EMAIL=
23+
FE_TEST_AZURE_FROM_EMAIL=
24+
FE_TEST_AZURE_API_HOST=
25+
26+
# Postmark Credentials
27+
FE_TEST_POSTMARK_API_KEY=
28+
FE_TEST_POSTMARK_FROM_EMAIL=
29+
30+
# SendGrid Credentials
31+
FE_TEST_SENDGRID_API_KEY=
32+
FE_TEST_SENDGRID_TEMPLATE=
33+
34+
# Graph Credentials
35+
FE_TEST_GRAPH_TO_EMAIL=
36+
FE_TEST_GRAPH_FROM_EMAIL=
37+
FE_TEST_GRAPH_TENANT_ID=
38+
FE_TEST_GRAPH_APP_ID=
39+
FE_TEST_GRAPH_CLIENT_SECRET=

0 commit comments

Comments
 (0)