Skip to content

Commit

Permalink
Add test for parametrized query
Browse files Browse the repository at this point in the history
  • Loading branch information
arthrp committed Feb 27, 2022
1 parent 960ffd9 commit 8906d8f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
19 changes: 19 additions & 0 deletions RqliteDotnet.Test/HttpClientMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ public static HttpClient GetExecuteMock()

return client;
}

public static HttpClient GetParamQueryMock()
{
var fileContent = GetContents();
var handlerMock = new Mock<HttpMessageHandler>();
handlerMock
.Protected()
.Setup<Task<HttpResponseMessage>>("SendAsync",
ItExpr.Is<HttpRequestMessage>(s => s.Method == HttpMethod.Post),
ItExpr.IsAny<CancellationToken>())
.ReturnsAsync(new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(fileContent)
});
var client = new HttpClient(handlerMock.Object){ BaseAddress = new Uri(BASE_URL) };

return client;
}

private static string GetContents()
{
Expand Down
16 changes: 16 additions & 0 deletions RqliteDotnet.Test/RqliteClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using NUnit.Framework;
using RqliteDotnet.Dto;

namespace RqliteDotnet.Test;

Expand Down Expand Up @@ -46,6 +47,21 @@ public async Task BasicExecute_Works()
Assert.AreEqual(1, result.Results[0].RowsAffected);
Assert.AreEqual(2, result.Results[0].LastInsertId);
}

[Test]
public async Task BasicQueryParam_Works()
{
var client = HttpClientMock.GetParamQueryMock();

var rqClient = new RqliteClient("http://localhost:6000", client);
var result = await rqClient.QueryParams<QueryParameter>("select * from foo where name = ?", new QueryParameter()
{
ParamType = QueryParamType.String, Value = "john"
});

Assert.AreEqual(1, result.Results.Count);
Assert.AreEqual(2, result.Results[0].Values[0].Count);
}
}

public class FooResultDto
Expand Down
2 changes: 1 addition & 1 deletion RqliteDotnet/RqliteClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RqliteDotnet;

public class RqliteClient
{
protected readonly HttpClient _httpClient;
private readonly HttpClient _httpClient;

public RqliteClient(string uri, HttpClient? client = null)
{
Expand Down

0 comments on commit 8906d8f

Please sign in to comment.