-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathParametersTests.cs
More file actions
66 lines (49 loc) · 2.24 KB
/
ParametersTests.cs
File metadata and controls
66 lines (49 loc) · 2.24 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
namespace RestSharp.Tests;
public class ParametersTests {
const string BaseUrl = "http://localhost:8888/";
[Fact]
public void AddDefaultHeadersUsingDictionary() {
var headers = new Dictionary<string, string> {
{ KnownHeaders.ContentType, ContentType.Json },
{ KnownHeaders.Accept, ContentType.Json },
{ KnownHeaders.ContentEncoding, "gzip, deflate" }
};
var expected = headers.Select(x => new HeaderParameter(x.Key, x.Value));
using var client = new RestClient(BaseUrl);
client.AddDefaultHeaders(headers);
var actual = client.DefaultParameters.Select(x => x as HeaderParameter);
expected.Should().BeSubsetOf(actual);
}
[Fact]
public void AddUrlSegmentWithInt() {
const string name = "foo";
var request = new RestRequest().AddUrlSegment(name, 1);
var actual = request.Parameters.FirstOrDefault(x => x.Name == name);
var expected = new UrlSegmentParameter(name, "1");
expected.Should().BeEquivalentTo(actual);
}
[Fact]
public void AddUrlSegmentModifiesUrlSegmentWithInt() {
const string name = "foo";
const string pathTemplate = "/{0}/resource";
const int urlSegmentValue = 1;
var path = string.Format(pathTemplate, $"{{{name}}}");
var request = new RestRequest(path).AddUrlSegment(name, urlSegmentValue);
var expected = string.Format(pathTemplate, urlSegmentValue);
using var client = new RestClient(BaseUrl);
var actual = client.BuildUri(request).AbsolutePath;
actual.Should().Be(expected);
}
[Fact]
public void AddUrlSegmentModifiesUrlSegmentWithString() {
const string name = "foo";
const string pathTemplate = "/{0}/resource";
const string urlSegmentValue = "bar";
var path = string.Format(pathTemplate, $"{{{name}}}");
var request = new RestRequest(path).AddUrlSegment(name, urlSegmentValue);
var expected = string.Format(pathTemplate, urlSegmentValue);
using var client = new RestClient(BaseUrl);
var actual = client.BuildUri(request).AbsolutePath;
expected.Should().BeEquivalentTo(actual);
}
}