-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSendAsyncTests.cs
More file actions
82 lines (72 loc) · 2.49 KB
/
SendAsyncTests.cs
File metadata and controls
82 lines (72 loc) · 2.49 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using FluentAssertions;
using Moq;
using System.Xml.Linq;
namespace PSWinCom.Gateway.Client.Tests
{
[TestFixture]
public class SendAsyncTests
{
[Test]
public void Should_throw_exception_when_trying_to_call_async_send_with_no_async_transport()
{
var mockTransport = new Mock<ITransport>();
var client = new PSWinCom.Gateway.Client.GatewayClient(mockTransport.Object);
try
{
var result = client.SendAsync(new[] { new Sms { Text = "Test", ReceiverNumber = "4790871951" } }).Result;
}
catch (AggregateException ex)
{
ex.InnerExceptions.Where(e => e is ApplicationException).Count().Should().Be(1);
}
}
[Test]
public async Task Should_be_able_to_send_with_async_transport()
{
var client = new PSWinCom.Gateway.Client.GatewayClient(mockAsyncTransport.Object);
Async_transport_returns(message_result("1", "OK"));
var response = await client.SendAsync(new[] {
new Sms {
Text = "Test",
ReceiverNumber = "4790871951"
}
});
response.Results.First().UserReference.Should().Be("1");
response.Results.First().Status.Should().Be(MessageStatus.Ok);
}
[SetUp]
public void Setup()
{
mockAsyncTransport = new Mock<IAsyncTransport>();
}
private void Async_transport_returns(params XElement[] results)
{
mockAsyncTransport
.Setup((t) => t.SendAsync(It.IsAny<XDocument>()))
.Returns(Task.FromResult<TransportResult>(new TransportResult
{
Content = new XDocument(
new XElement("SESSION",
new XElement("MSGLST",
results
)
)
)
}));
}
private static XElement message_result(string numInSession, string status)
{
return new XElement("MSG",
new XElement("ID", numInSession),
new XElement("STATUS", status)
);
}
private Mock<IAsyncTransport> mockAsyncTransport;
}
}