-
Notifications
You must be signed in to change notification settings - Fork 449
Expand file tree
/
Copy pathSendGridSenderTests.cs
More file actions
168 lines (134 loc) · 5.45 KB
/
SendGridSenderTests.cs
File metadata and controls
168 lines (134 loc) · 5.45 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.IO;
using System.Threading.Tasks;
using FluentEmail.SendGrid;
using NUnit.Framework;
using Attachment = FluentEmail.Core.Models.Attachment;
namespace FluentEmail.Core.Tests
{
public class SendGridSenderTests
{
const string apiKey = "missing-credentials"; // TODO: Put your API key here
const string toEmail = "fluentEmail@mailinator.com";
const string toName = "FluentEmail Mailinator";
const string fromEmail = "test@fluentmail.com";
const string fromName = "SendGridSender Test";
[SetUp]
public void SetUp()
{
if (string.IsNullOrWhiteSpace(apiKey)) throw new ArgumentException("SendGrid Api Key needs to be supplied");
var sender = new SendGridSender(apiKey, true);
Email.DefaultSender = sender;
}
[Test, Ignore("No sendgrid credentials")]
public async Task CanSendEmail()
{
const string subject = "SendMail Test";
const string body = "This email is testing send mail functionality of SendGrid Sender.";
var email = Email
.From(fromEmail, fromName)
.To(toEmail, toName)
.Subject(subject)
.Body(body);
var response = await email.SendAsync();
Assert.IsTrue(response.Successful);
}
[Test, Ignore("No sendgrid credentials")]
public async Task CanSendTemplateEmail()
{
const string subject = "SendMail Test";
const string templateId = "123456-insert-your-own-id-here";
object templateData = new
{
Name = toName,
ArbitraryValue = "The quick brown fox jumps over the lazy dog."
};
var email = Email
.From(fromEmail, fromName)
.To(toEmail, toName)
.Subject(subject);
var response = await email.SendWithTemplateAsync(templateId, templateData);
Assert.IsTrue(response.Successful);
}
[Test, Ignore("No sendgrid credentials")]
public async Task CanSendEmailWithReplyTo()
{
const string subject = "SendMail Test";
const string body = "This email is testing send mail with ReplyTo functionality of SendGrid Sender.";
var email = Email
.From(fromEmail, fromName)
.To(toEmail, toName)
.ReplyTo(toEmail, toName)
.Subject(subject)
.Body(body);
var response = await email.SendAsync();
Assert.IsTrue(response.Successful);
}
[Test, Ignore("No sendgrid credentials")]
public async Task CanSendEmailWithCategory()
{
const string subject = "SendMail Test";
const string body = "This email is testing send mail with Categories functionality of SendGrid Sender.";
var email = Email
.From(fromEmail, fromName)
.To(toEmail, toName)
.ReplyTo(toEmail, toName)
.Subject(subject)
.Tag("TestCategory")
.Body(body);
var response = await email.SendAsync();
Assert.IsTrue(response.Successful);
}
[Test, Ignore("No sendgrid credentials")]
public async Task CanSendEmailWithAttachments()
{
const string subject = "SendMail With Attachments Test";
const string body = "This email is testing the attachment functionality of SendGrid Sender.";
using (var stream = File.OpenRead($"{Directory.GetCurrentDirectory()}/test-binary.xlsx"))
{
var attachment = new Attachment
{
Data = stream,
ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
Filename = "test-binary.xlsx"
};
var email = Email
.From(fromEmail, fromName)
.To(toEmail, toName)
.Subject(subject)
.Body(body)
.Attach(attachment);
var response = await email.SendAsync();
Assert.IsTrue(response.Successful);
}
}
[Test, Ignore("No sendgrid credentials")]
public async Task CanSendHighPriorityEmail()
{
const string subject = "SendMail Test";
const string body = "This email is testing send mail functionality of SendGrid Sender.";
var email = Email
.From(fromEmail, fromName)
.To(toEmail, toName)
.Subject(subject)
.Body(body)
.HighPriority();
var response = await email.SendAsync();
Assert.IsTrue(response.Successful);
}
[Test, Ignore("No sendgrid credentials")]
public async Task CanSendLowPriorityEmail()
{
const string subject = "SendMail Test";
const string body = "This email is testing send mail functionality of SendGrid Sender.";
var email = Email
.From(fromEmail, fromName)
.To(toEmail, toName)
.Subject(subject)
.Body(body)
.LowPriority();
var response = await email.SendAsync();
Assert.IsTrue(response.Successful);
}
}
}