-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAwsRestServiceTest.cs
More file actions
88 lines (76 loc) · 2.72 KB
/
Copy pathAwsRestServiceTest.cs
File metadata and controls
88 lines (76 loc) · 2.72 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
using System.Linq;
using System.Net;
using System.Net.Http;
using Cucumber.SimpleDb.Test.Fakes;
using NUnit.Framework;
using System.Collections.Specialized;
using Cucumber.SimpleDb.Transport;
namespace Cucumber.SimpleDb.Test
{
[TestFixture ()]
public class AwsRestServiceTest
{
private HttpRequestMessage _requestMessage;
private HttpClient _httpClient;
[SetUp]
public void Setup()
{
var responseMessage = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("<All><Ok/></All>")
};
_httpClient = new HttpClient(new FakeHttpMessageHandler(responseMessage, req => _requestMessage = req));
}
[Test]
public void ExecuteRequest_ShouldSerializeArgumentsToRequest ()
{
var service = new AwsRestService("myPublicKey", "myPrivateKey", _httpClient);
var arguments = new NameValueCollection {
{ "Item.0.ItemName", "TestItem1" },
{ "Item.0.Attribute.0.Name", "TestAtt1" },
{ "Item.0.Attribute.0.Value", "123" }
};
service.ExecuteRequest(arguments);
Assert.NotNull(_requestMessage);
var requestData = _requestMessage.RequestUri.ToNameValueCollection();
Assert.NotNull(requestData);
Assert.IsTrue(requestData.Count > 0);
foreach(string key in arguments)
{
Assert.AreEqual(arguments[key], requestData[key]);
}
}
[Test]
public void ExecuteRequest_ShouldAddStandardArgumentsToRequest()
{
var service = new AwsRestService("myPublicKey", "myPrivateKey", _httpClient);
service.ExecuteRequest(new NameValueCollection());
Assert.NotNull(_requestMessage);
var requestData = _requestMessage.RequestUri.ToNameValueCollection();
Assert.NotNull(requestData);
Assert.IsTrue(requestData.Count > 0);
new[]
{
"AWSAccessKeyId",
"SignatureVersion",
"SignatureMethod",
"Timestamp",
"Version"
}.ToList()
.ForEach(key => Assert.IsNotNullOrEmpty(requestData[key]));
Assert.AreEqual("myPublicKey", requestData["AWSAccessKeyId"]);
}
[Test]
public void ExecuteRequest_ShouldAddSignatureToRequest()
{
var service = new AwsRestService("myPublicKey", "myPrivateKey", _httpClient);
service.ExecuteRequest(new NameValueCollection());
Assert.NotNull(_requestMessage);
var requestData = _requestMessage.RequestUri.ToNameValueCollection();
Assert.NotNull(requestData);
Assert.IsTrue(requestData.Count > 0);
Assert.IsNotNullOrEmpty(requestData["Signature"]);
//TODO: (CV) Should assert the actual signature. Need to move the signature generation logic out of the AwsRequestService class
}
}
}