/
ClientServerInformationTests.cs
119 lines (103 loc) · 5.42 KB
/
ClientServerInformationTests.cs
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
using Xunit;
using PostmarkDotNet;
using System;
using System.Threading.Tasks;
using System.Linq;
using PostmarkDotNet.Model;
namespace Postmark.Tests
{
public class ClientServerInformationTests : ClientBaseFixture
{
private string _serverBaseName;
private string _name;
private string _color;
private string _inboundHookUrl;
private string _bounceHookUrl;
private string _openHookUrl;
private string _clickHookUrl;
private string _deliveryHookUrl;
protected override void Setup()
{
_client = new PostmarkClient(WRITE_TEST_SERVER_TOKEN);
var id = Guid.NewGuid().ToString("n");
_serverBaseName = "dotnet-integration-test-server";
_name = $"{_serverBaseName}-{id}";
_color = ServerColors.Purple;
_inboundHookUrl = "http://www.example.com/inbound/" + id;
_bounceHookUrl = "http://www.example.com/bounce/" + id;
_openHookUrl = "http://www.example.com/opened/" + id;
_clickHookUrl = "http://www.example.com/click/" + id;
_deliveryHookUrl = "http://www.example.com/delivery/" + id;
//_inboundDomain = "inbound-" + id + ".exmaple.com";
}
[Fact]
public async void Client_CanGetServerInformation()
{
var server = await _client.GetServerAsync();
Assert.True(server.ApiTokens.Any());
Assert.NotNull(server.Name);
Assert.True(server.ID > 0);
Assert.NotNull(server.Color);
}
[Fact]
public async void ClientCanUpdateServerName()
{
var client = new PostmarkClient(WRITE_TEST_SERVER_TOKEN);
var serverName = _serverBaseName + DateTime.Now.ToString("o");
var nonModifiedServer = await client.GetServerAsync();
var updatedServer = await client.EditServerAsync(name: serverName);
var modifiedServer = await client.GetServerAsync();
Assert.False(nonModifiedServer.Name == updatedServer.Name, "Updated server name should be different than current name");
Assert.True(serverName == updatedServer.Name, "Updated server name returned from EditServer should be the same as the value passed in.");
Assert.True(serverName == modifiedServer.Name, "Updated server name returned from subsequent call to GetServer should show new name.");
}
[Fact]
public async void Client_CanGetEditAServerInformation()
{
var existingServer = await _client.GetServerAsync();
var updatedAffix = "updated";
var updatedServer = await _client.EditServerAsync(
_name + updatedAffix, ServerColors.Purple,
!existingServer.RawEmailEnabled, !existingServer.SmtpApiActivated,
_inboundHookUrl + updatedAffix, _bounceHookUrl + updatedAffix,
_openHookUrl + updatedAffix, !existingServer.PostFirstOpenOnly,
!existingServer.TrackOpens, null, 10, LinkTrackingOptions.HtmlOnly,
_clickHookUrl + updatedAffix, _deliveryHookUrl + updatedAffix);
//go get a fresh copy from the API.
var retrievedServer = await _client.GetServerAsync();
//reset this server
await _client.EditServerAsync(
existingServer.Name, ServerColors.Yellow,
existingServer.RawEmailEnabled, existingServer.SmtpApiActivated,
existingServer.InboundHookUrl, existingServer.BounceHookUrl,
existingServer.OpenHookUrl, existingServer.PostFirstOpenOnly,
existingServer.TrackOpens, null,
existingServer.InboundSpamThreshold,
LinkTrackingOptions.None, existingServer.ClickHookUrl, existingServer.DeliveryHookUrl);
Assert.Equal(_name + updatedAffix, retrievedServer.Name);
Assert.Equal(ServerColors.Purple, retrievedServer.Color);
Assert.NotEqual(existingServer.Color, retrievedServer.Color);
Assert.NotEqual(existingServer.RawEmailEnabled, retrievedServer.RawEmailEnabled);
Assert.NotEqual(existingServer.SmtpApiActivated, retrievedServer.SmtpApiActivated);
Assert.Equal(_inboundHookUrl + updatedAffix, retrievedServer.InboundHookUrl);
Assert.Equal(_bounceHookUrl + updatedAffix, retrievedServer.BounceHookUrl);
Assert.Equal(_openHookUrl + updatedAffix, retrievedServer.OpenHookUrl);
Assert.Equal(_clickHookUrl + updatedAffix, retrievedServer.ClickHookUrl);
Assert.Equal(_deliveryHookUrl + updatedAffix, retrievedServer.DeliveryHookUrl);
Assert.NotEqual(existingServer.PostFirstOpenOnly, retrievedServer.PostFirstOpenOnly);
Assert.NotEqual(existingServer.TrackOpens, retrievedServer.TrackOpens);
Assert.Equal(10, retrievedServer.InboundSpamThreshold);
Assert.NotEqual(existingServer.InboundSpamThreshold, retrievedServer.InboundSpamThreshold);
Assert.Equal(LinkTrackingOptions.HtmlOnly, retrievedServer.TrackLinks);
}
void Dispose(){
Task.Run(async () =>
{
try
{
await _client.EditServerAsync(name: _serverBaseName);
}catch{}
}).Wait();
}
}
}