forked from lukencode/FluentEmail
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBootstrapTests.cs
More file actions
113 lines (100 loc) · 3.26 KB
/
BootstrapTests.cs
File metadata and controls
113 lines (100 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// ReSharper disable StringLiteralTypo
// ReSharper disable UnusedAutoPropertyAccessor.Local
using System;
using System.Threading.Tasks;
using FluentEmail.Core;
using FluentEmail.Core.Interfaces;
using FluentEmail.Liquid;
using Fluid;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Options;
using Xunit;
using VerifyTests;
using VerifyXunit;
namespace FluentEmail.Bootstrap.Tests;
public class BootstrapTests
{
private const string ToEmail = "bob@test.com";
private const string FromEmail = "johno@test.com";
private const string Subject = "sup dawg";
private readonly VerifySettings _settings = new();
public BootstrapTests()
{
_settings.ScrubLinesContaining("Compiled with Bootstrap Email DotNet");
_settings.DisableDiff();
}
private static ITemplateRenderer SetupRenderer(
IFileProvider fileProvider = null,
Action<TemplateContext, object> configureTemplateContext = null)
{
var options = new LiquidRendererOptions
{
FileProvider = fileProvider,
ConfigureTemplateContext = configureTemplateContext,
};
return new LiquidRenderer(Options.Create(options));
}
[Fact]
public Task CompileBootstrap_Compiles()
{
var template = """
<html>
<body class="bg-light">
Hi {{ Name }} here is a list {% for i in Numbers %}{{ i }}{% endfor %}
</body>
</html>
""";
var email = new Email(FromEmail)
{
Renderer = SetupRenderer()
}
.To(ToEmail)
.Subject(Subject)
.UsingTemplate(template, new ViewModel { Name = "LUKE", Numbers = ["1", "2", "3"] })
.CompileBootstrap();
return Verifier.Verify(email.Data.Body, _settings);
}
[Fact]
public Task UsingBootstrapBody_Compiles()
{
var body = """
<html>
<body class="bg-light">
This is simple text, no templating
</body>
</html>
""";
var email = new Email(FromEmail)
{
Renderer = SetupRenderer()
}
.To(ToEmail)
.Subject(Subject)
.UsingBootstrapBody(body);
return Verifier.Verify(email.Data.Body, _settings);
}
[Fact]
public Task UsingBootstrapTemplate_Compiles()
{
var template = """
<html>
<body class="bg-light">
Hi {{ Name }} here is a list {% for i in Numbers %}{{ i }}{% endfor %}
</body>
</html>
""";
var email = new Email(FromEmail)
{
Renderer = SetupRenderer()
}
.To(ToEmail)
.Subject(Subject)
.UsingBootstrapTemplate(template, new ViewModel { Name = "LUKE", Numbers = ["1", "2", "3"] });
return Verifier.Verify(email.Data.Body, _settings);
}
private class ViewModel
{
public string Name { get; set; }
public string[] Numbers { get; set; }
}
}