Skip to content

Commit 566a376

Browse files
committed
.
1 parent 4334bf7 commit 566a376

16 files changed

+191
-84
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# <img src="/src/icon.png" height="30px"> Verify.EmailPreviewServices
22

33
[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true&label=)](https://github.com/orgs/VerifyTests/discussions)
4-
[![Build status](https://ci.appveyor.com/api/projects/status/soell7l73pbakm8u?svg=true)](https://ci.appveyor.com/project/SimonCropp/Verify-Ulid)
4+
[![Build status](https://ci.appveyor.com/api/projects/status/nwvywmfs2xb4tpsd?svg=true)](https://ci.appveyor.com/project/SimonCropp/Verify-Ulid)
55
[![NuGet Status](https://img.shields.io/nuget/v/Verify.EmailPreviewServices.svg)](https://www.nuget.org/packages/Verify.EmailPreviewServices/)
66

77
Extends [Verify](https://github.com/VerifyTests/Verify) to enable snapshotting of emails via [EmailPreviewDervices](https://emailpreviewservices.com).<!-- singleLineInclude: intro. path: /docs/intro.include.md -->

src/Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649;NU1608;NU1109</NoWarn>
5-
<Version>1.0.0</Version>
6-
<AssemblyVersion>1.0.0</AssemblyVersion>
5+
<Version>0.1.0</Version>
6+
<AssemblyVersion>0.1.0</AssemblyVersion>
77
<LangVersion>preview</LangVersion>
8-
<PackageTags>Ulid, Verify</PackageTags>
9-
<Description>Extends Verify (https://github.com/VerifyTests/Verify) to enable scrubbing of Universally Unique Lexicographically Sortable Identifiers via Ulid (https://github.com/Cysharp/Ulid).</Description>
8+
<PackageTags>Email, Preview, Verify</PackageTags>
9+
<Description>Extends Verify (https://github.com/VerifyTests/Verify) to enable snapshotting of emails via Email Preview Services (https://emailpreviewservices.com).</Description>
1010
<ResolveAssemblyReferencesSilent>true</ResolveAssemblyReferencesSilent>
1111
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1212
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

src/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.12" />
1414
<PackageVersion Include="Verify" Version="31.3.0" />
1515
<PackageVersion Include="Verify.DiffPlex" Version="3.1.2" />
16+
<PackageVersion Include="Verify.ImageMagick" Version="3.7.7" />
1617
<PackageVersion Include="Verify.NUnit" Version="31.3.0" />
1718
<PackageVersion Include="Microsoft.Sbom.Targets" Version="4.1.2" />
1819
</ItemGroup>

src/Tests/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
global using System.Runtime.CompilerServices;
2+
global using EmailPreviewServices;
23
global using VerifyTests.DiffPlex;

src/Tests/ModuleInitializer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public static void InitOther()
1313
{
1414
VerifyDiffPlex.Initialize(OutputType.Compact);
1515
VerifierSettings.InitializePlugins();
16+
VerifyImageMagick.RegisterComparers(.01);
1617
}
1718
}
38.9 KB
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
Html:
3+
<!DOCTYPE html>
4+
<html>
5+
<head>
6+
<meta charset="UTF-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>Test Email</title>
9+
</head>
10+
<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px;">
11+
<div style="max-width: 600px; margin: 0 auto; background-color: white; padding: 20px; border-radius: 10px;">
12+
<h1 style="color: #333;">Welcome to Our Service!</h1>
13+
<p style="color: #666; line-height: 1.6;">
14+
This is a test email to demonstrate the email preview functionality.
15+
</p>
16+
<a href="https://example.com"
17+
style="display: inline-block; padding: 10px 20px; background-color: #007bff;
18+
color: white; text-decoration: none; border-radius: 5px; margin-top: 10px;">
19+
Get Started
20+
</a>
21+
<p style="color: #999; font-size: 12px; margin-top: 30px;">
22+
© 2025 Your Company. All rights reserved.
23+
</p>
24+
</div>
25+
</body>
26+
</html>,
27+
Devices: [
28+
Outlook2016
29+
]
30+
}
-95.2 KB
Loading

src/Tests/Samples.cs

Lines changed: 13 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
using EmailPreviewServices;
2-
using SixLabors.ImageSharp;
3-
using SixLabors.ImageSharp.PixelFormats;
4-
using SixLabors.ImageSharp.Processing;
5-
6-
[TestFixture]
1+
[TestFixture]
72
public class Samples
83
{
9-
static readonly HttpClient httpClient;
104
static readonly EmailPreviewServicesClient service;
115

126
static Samples()
137
{
14-
var apiKey = Environment.GetEnvironmentVariable("EmailPreviewServicesApiKey")!;
15-
httpClient = new HttpClient();
16-
httpClient.DefaultRequestHeaders.Add("X-API-Key", apiKey);
17-
httpClient.DefaultRequestHeaders.Authorization = new("Bearer", apiKey);
18-
httpClient.DefaultRequestHeaders.Accept.Add(new("application/json"));
19-
service = new("https://app.emailpreviewservices.com/api", httpClient);
8+
var apiKey = VerifyEmailPreviewServices.ApiKey;
9+
HttpClient client = new();
10+
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);
11+
client.DefaultRequestHeaders.Authorization = new("Bearer", apiKey);
12+
client.DefaultRequestHeaders.Accept.Add(new("application/json"));
13+
service = new("https://app.emailpreviewservices.com/api", client);
2014
}
2115

2216
[Test]
@@ -27,8 +21,7 @@ public async Task DeviceList()
2721
}
2822

2923
[Test]
30-
[Explicit]
31-
public async Task Simple()
24+
public async Task GeneratePreviews()
3225
{
3326
var html =
3427
"""
@@ -57,63 +50,11 @@ Get Started
5750
</body>
5851
</html>
5952
""";
60-
61-
var preview = await service.ExecutePreviewAsync(
62-
new()
63-
{
64-
Name = "the name",
65-
Body = html,
66-
Subject = "subhect",
67-
Devices = ["microsoft_outlook_2016"],
68-
});
69-
const int maxAttempts = 30;
70-
var delay = TimeSpan.FromSeconds(2);
71-
72-
Stream streamAsync = null!;
73-
for (var i = 0; i < maxAttempts; i++)
74-
{
75-
var devicesPreview = await service.GetDevicePreviewAsync(preview.Id, "microsoft_outlook_2016");
76-
77-
if (devicesPreview.Status == DevicePreviewDataStatus.SUCCESSFUL)
78-
{
79-
streamAsync = await httpClient.GetStreamAsync(devicesPreview.Preview.Original);
80-
break;
81-
}
82-
83-
await Task.Delay(delay);
84-
}
85-
86-
87-
using var image =await Image.LoadAsync<Rgba32>(streamAsync);
88-
89-
var cropHeight = image.Height;
90-
for (var y = image.Height - 1; y >= 0; y--)
53+
var preview = new EmailPreview
9154
{
92-
var hasContent = false;
93-
for (var x = 0; x < image.Width; x++)
94-
{
95-
var pixel = image[x, y];
96-
if (pixel.R < 240 || pixel.G < 240 || pixel.B < 240)
97-
{
98-
hasContent = true;
99-
break;
100-
}
101-
}
102-
if (hasContent)
103-
{
104-
cropHeight = y + 1;
105-
break;
106-
}
107-
}
108-
109-
image.Mutate(ctx => ctx.Crop(image.Width, cropHeight));
110-
var memoryStream = new MemoryStream();
111-
await image.SaveAsPngAsync(memoryStream);
112-
memoryStream.Position = 0;
113-
await service.DeletePreviewAsync(preview.Id);
114-
await Verify(memoryStream, extension: "png");
115-
// await using var streamAsync = await httpClient.GetStreamAsync(preview.Body);
116-
// await using var fileStream = File.Create("temp.html");
117-
// await streamAsync.CopyToAsync(fileStream);
55+
Html = html,
56+
Devices = [Device.Outlook2016]
57+
};
58+
await Verify(preview);
11859
}
11960
}

src/Tests/Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<PackageReference Include="MarkdownSnippets.MsBuild" PrivateAssets="all" />
88
<PackageReference Include="NUnit" />
99
<PackageReference Include="NUnit3TestAdapter" />
10-
<PackageReference Include="SixLabors.ImageSharp" />
1110
<PackageReference Include="Verify.DiffPlex" />
11+
<PackageReference Include="Verify.ImageMagick" />
1212
<PackageReference Include="Verify.NUnit" />
1313
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1414
<ProjectReference Include="..\Verify.EmailPreviewServices\Verify.EmailPreviewServices.csproj" />

0 commit comments

Comments
 (0)