-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathHttpIPOSV1Tests.cs
139 lines (126 loc) · 5.43 KB
/
HttpIPOSV1Tests.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#if WCF
using fiskaltrust.ifPOS.Tests.Helpers;
using fiskaltrust.ifPOS.v1;
using fiskaltrust.Middleware.Interface.Tests.Helpers.Wcf;
using FluentAssertions;
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.Net.Http;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace fiskaltrust.ifPOS.Tests.v1.IPOS
{
// If these tests are failing you have to execute the following command as an Administrator
// netsh http add urlacl url=http://+:8008/ user=Everyone listen=yes
// To add the url that is used for binding
public class HttpIPOSV1Tests : IPOSV1Tests
{
private string _url;
private ServiceHost _serviceHost;
public HttpIPOSV1Tests()
{
_url = $"http://localhost:12080/pos/{Guid.NewGuid()}";
}
~HttpIPOSV1Tests()
{
_serviceHost.Close();
_serviceHost = null;
}
protected override ifPOS.v1.IPOS CreateClient() => WcfHelper.GetRestProxy<ifPOS.v1.IPOS>(_url);
protected override void StartHost() => _serviceHost = WcfHelper.StartRestHost<ifPOS.v1.IPOS>(_url, new DummyPOSV1());
protected override void StopHost() => _serviceHost.Close();
[Test]
public async Task SignV0_ShouldReturnSameQueueId_For_WebClient()
{
var queueId = Guid.NewGuid().ToString();
using (var httpClient = new HttpClient())
{
var json = JsonConvert.SerializeObject(new ReceiptRequest
{
ftQueueID = queueId,
ftCashBoxID = "",
cbTerminalID = "",
cbReceiptReference = "",
cbReceiptMoment = DateTime.Now,
cbChargeItems = new ChargeItem[] { },
cbPayItems = new PayItem[] { },
ftReceiptCase = 100
});
var result = await httpClient.PostAsync(new Uri(_url + "/v0/sign"), new StringContent(json, Encoding.UTF8, "application/json"));
result.EnsureSuccessStatusCode();
var content = await result.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ReceiptResponse>(content);
response.ftQueueID.Should().Be(queueId);
}
}
[Test]
public async Task SignV1_ShouldReturnSameQueueId_For_WebClient()
{
var queueId = Guid.NewGuid().ToString();
using (var httpClient = new HttpClient())
{
var json = JsonConvert.SerializeObject(new ReceiptRequest
{
ftQueueID = queueId,
ftCashBoxID = "",
cbTerminalID = "",
cbReceiptReference = "",
cbReceiptMoment = DateTime.Now,
cbChargeItems = new ChargeItem[] { },
cbPayItems = new PayItem[] { },
ftReceiptCase = 100
});
var result = await httpClient.PostAsync(new Uri(_url + "/v1/sign"), new StringContent(json, Encoding.UTF8, "application/json"));
result.EnsureSuccessStatusCode();
var content = await result.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ReceiptResponse>(content);
response.ftQueueID.Should().Be(queueId);
}
}
[Test]
public async Task EchoV0_ShouldReturnSameMessage_For_WebClient()
{
var inMessage = Guid.NewGuid().ToString();
using (var httpClient = new HttpClient())
{
var json = JsonConvert.SerializeObject(inMessage);
var result = await httpClient.PostAsync(new Uri(_url + "/v0/echo"), new StringContent(json, Encoding.UTF8, "application/json"));
result.EnsureSuccessStatusCode();
var content = await result.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<string>(content);
response.Should().Be(inMessage);
}
}
[Test]
public async Task Echov1_ShouldReturnSameMessage_For_WebClient()
{
var inMessage = Guid.NewGuid().ToString();
using (var httpClient = new HttpClient())
{
var json = JsonConvert.SerializeObject(new EchoRequest
{
Message = inMessage
});
var result = await httpClient.PostAsync(new Uri(_url + "/v1/echo"), new StringContent(json, Encoding.UTF8, "application/json"));
result.EnsureSuccessStatusCode();
var content = await result.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<EchoResponse>(content);
response.Message.Should().Be(inMessage);
}
}
[Test]
public async Task JournalV0_ShouldReturnSameMessage_For_WebClient()
{
using (var httpClient = new HttpClient())
{
var result = await httpClient.PostAsync(new Uri(_url + "/v0/journal?type=0&from=0&to=0"), new StringContent(""));
result.EnsureSuccessStatusCode();
var content = await result.Content.ReadAsStringAsync();
content.Should().Be("{\"ftJournalType\":0,\"from\":0,\"to\":0}");
}
}
}
}
#endif