Skip to content

Commit d2846af

Browse files
committed
wrote a really quick test for the newly generated raw client, many more to follow
1 parent fd87bda commit d2846af

File tree

7 files changed

+2372
-1342
lines changed

7 files changed

+2372
-1342
lines changed

src/Nest.Tests.Integration/ConnectionTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,19 @@ public void construct_client_with_null_uri()
100100
var settings = new ConnectionSettings(uri);
101101
});
102102
}
103+
104+
[Test]
105+
public void ConnectUsingRawClient()
106+
{
107+
var result = this._client.Raw.InfoHead();
108+
Assert.IsTrue(result.Success);
109+
StringAssert.EndsWith(":9200/?pretty=true", result.RequestUrl);
110+
111+
112+
var resultWithQueryString = this._client.Raw.InfoHead(qs => qs.Add("hello", "world"));
113+
Assert.IsTrue(resultWithQueryString.Success);
114+
115+
StringAssert.EndsWith(":9200/?hello=world&pretty=true", resultWithQueryString.RequestUrl);
116+
}
103117
}
104118
}

src/Nest/IRawElasticClient.Generated.cs

Lines changed: 334 additions & 334 deletions
Large diffs are not rendered by default.

src/Nest/QueryStringParameters/FluentQueryString.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ namespace Nest
1111
/// You can always pass a simple NameValueCollection if you want.
1212
/// </summary>
1313
/// <typeparam name="T"></typeparam>
14-
public abstract class FluentQueryString<T> : NameValueCollection where T : FluentQueryString<T>
14+
public abstract class FluentQueryString<T> where T : FluentQueryString<T>
1515
{
16-
public new T Add(string name, string value)
16+
internal readonly NameValueCollection NameValueCollection = new NameValueCollection();
17+
18+
public T Add(string name, string value)
1719
{
18-
base.Add(name, value);
20+
NameValueCollection.Add(name, value);
1921
return (T)this;
2022
}
2123

src/Nest/RawElasticClient.Generated.cs

Lines changed: 2004 additions & 1002 deletions
Large diffs are not rendered by default.

src/Nest/RawElasticClient.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public string Serialize(object @object)
4040

4141
protected ConnectionStatus DoRequest(string method, string path, object data = null, NameValueCollection queryString = null)
4242
{
43+
if (queryString != null)
44+
path += queryString.ToQueryString();
45+
4346
var postData = string.Empty;
4447
var s = data as string;
4548
if (s != null)
@@ -58,11 +61,17 @@ protected ConnectionStatus DoRequest(string method, string path, object data = n
5861
case "head": return this.Connection.HeadSync(path);
5962
case "get": return this.Connection.GetSync(path);
6063
}
64+
65+
66+
6167
throw new DslException("Unknown HTTP method " + method);
6268
}
6369

6470
protected Task<ConnectionStatus> DoRequestAsync(string method, string path, object data = null, NameValueCollection queryString = null)
6571
{
72+
if (queryString != null)
73+
path += queryString.ToQueryString();
74+
6675
var postData = string.Empty;
6776
var s = data as string;
6877
if (s != null)

src/RawClientGenerator/Domain/ApiEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public IEnumerable<CsharpMethod> CsharpMethods
7777

7878
args = args.Concat(new[]
7979
{
80-
"Func<"+queryStringParamName+", NameValueCollection> queryString = null"
80+
"Func<"+queryStringParamName+", FluentQueryString> queryString = null"
8181
});
8282

8383
var apiMethod = new CsharpMethod

src/RawClientGenerator/Views/RawElasticClient.Generated.cshtml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ namespace Nest
4949
}
5050
NameValueCollection nv = null;
5151
if (queryString != null)
52-
nv = queryString(new @(method.QueryStringParamName)());
52+
{
53+
var qs = queryString(new @(method.QueryStringParamName)());
54+
if (qs != null) nv = qs.NameValueCollection;
55+
}
5356
@{
5457
string requestMethod = method.ReturnType.StartsWith("Task<") ? "DoRequestAsync" : "DoRequest";
5558
}
56-
return this.@(requestMethod)("@method.HttpMethod", url@(method.Parts.Any(pp=>pp.Name == "body") ? ", body" : string.Empty), nv);
59+
return this.@(requestMethod)("@method.HttpMethod", url@(method.Parts.Any(pp=>pp.Name == "body") ? ", body" : ", data: null"), queryString: nv);
5760
}</text>
5861

5962
}

0 commit comments

Comments
 (0)