Skip to content

Commit 5d9d357

Browse files
committed
add client test case
1 parent c5c906e commit 5d9d357

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using SocketLabs.InjectionApi;
3+
using SocketLabs.InjectionApi.Message;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Net.Http;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
11+
namespace SocketLabs.InjectionApi.Tests
12+
{
13+
[TestClass()]
14+
public class SocketLabsClientTests
15+
{
16+
[TestMethod()]
17+
public async Task SendAsyncTest()
18+
{
19+
int serverId = 999;
20+
string bearerApiKey = "abcdefjhijklmnopqrst.uvwxyzabcdefghijklmnopqrstuvwxyz12345678";
21+
22+
var client = new SocketLabsClient(serverId, bearerApiKey);
23+
client.EndpointUrl = "https://example.local";
24+
client.NumberOfRetries = 1;
25+
26+
var message = new BasicMessage();
27+
message.To.Add("[email protected]");
28+
message.From = new EmailAddress("[email protected]");
29+
message.Subject = "Test";
30+
message.HtmlBody = "<p>This is a test!</p>";
31+
32+
await Assert.ThrowsExceptionAsync<HttpRequestException>(async () => await client.SendAsync(message, CancellationToken.None));
33+
34+
// The client should throw the same exception on subsequent calls.
35+
await Assert.ThrowsExceptionAsync<HttpRequestException>(async () => await client.SendAsync(message, CancellationToken.None));
36+
}
37+
}
38+
}

test/SocketLabs.Tests/SocketLabs.Tests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<RootNamespace>SocketLabs.Tests</RootNamespace>
44
<AssemblyName>SocketLabs.Tests</AssemblyName>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<AssemblyTitle>SocketLabs.Tests</AssemblyTitle>
77
<IsPackable>false</IsPackable>
88
<Product>SocketLabs.Tests</Product>
@@ -26,4 +26,7 @@
2626
<ItemGroup>
2727
<ProjectReference Include="..\..\src\SocketLabs\SocketLabs.csproj" />
2828
</ItemGroup>
29+
<ItemGroup>
30+
<Folder Include="ClientTests\" />
31+
</ItemGroup>
2932
</Project>

0 commit comments

Comments
 (0)