From 8906d8fad7a98c4129473c31682e41bffd803ef2 Mon Sep 17 00:00:00 2001 From: A Date: Mon, 28 Feb 2022 01:01:04 +0200 Subject: [PATCH] Add test for parametrized query --- RqliteDotnet.Test/HttpClientMock.cs | 19 +++++++++++++++++++ RqliteDotnet.Test/RqliteClientTests.cs | 16 ++++++++++++++++ RqliteDotnet/RqliteClient.cs | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/RqliteDotnet.Test/HttpClientMock.cs b/RqliteDotnet.Test/HttpClientMock.cs index 085a3e2..4adf72a 100644 --- a/RqliteDotnet.Test/HttpClientMock.cs +++ b/RqliteDotnet.Test/HttpClientMock.cs @@ -50,6 +50,25 @@ public static HttpClient GetExecuteMock() return client; } + + public static HttpClient GetParamQueryMock() + { + var fileContent = GetContents(); + var handlerMock = new Mock(); + handlerMock + .Protected() + .Setup>("SendAsync", + ItExpr.Is(s => s.Method == HttpMethod.Post), + ItExpr.IsAny()) + .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() { diff --git a/RqliteDotnet.Test/RqliteClientTests.cs b/RqliteDotnet.Test/RqliteClientTests.cs index a362e7f..16d5b08 100644 --- a/RqliteDotnet.Test/RqliteClientTests.cs +++ b/RqliteDotnet.Test/RqliteClientTests.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using NUnit.Framework; +using RqliteDotnet.Dto; namespace RqliteDotnet.Test; @@ -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("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 diff --git a/RqliteDotnet/RqliteClient.cs b/RqliteDotnet/RqliteClient.cs index ac48bd4..31c0664 100644 --- a/RqliteDotnet/RqliteClient.cs +++ b/RqliteDotnet/RqliteClient.cs @@ -8,7 +8,7 @@ namespace RqliteDotnet; public class RqliteClient { - protected readonly HttpClient _httpClient; + private readonly HttpClient _httpClient; public RqliteClient(string uri, HttpClient? client = null) {