From 197f4dbd9ae18acf89e24be58c41948de35f5fe7 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 25 Dec 2024 20:01:44 +0200 Subject: [PATCH] Add test and update dependencies (#23) * Add tests and update dependencies * Update dependencies --- .../RqliteClientTests.cs | 47 +++++++++++++++---- .../RqliteDotnet.IntegrationTest.csproj | 4 +- RqliteDotnet.Test/RqliteClientTests.cs | 2 +- RqliteDotnet.Test/RqliteDotnet.Test.csproj | 4 +- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/RqliteDotnet.IntegrationTest/RqliteClientTests.cs b/RqliteDotnet.IntegrationTest/RqliteClientTests.cs index f36477a..02da8ba 100644 --- a/RqliteDotnet.IntegrationTest/RqliteClientTests.cs +++ b/RqliteDotnet.IntegrationTest/RqliteClientTests.cs @@ -8,6 +8,7 @@ namespace RqliteDotnet.IntegrationTest; +[TestFixture] public class RqliteClientTests { private const int Port = 4001; @@ -21,12 +22,12 @@ public async Task Setup() .WithImage("rqlite/rqlite:8.36.1") .WithPortBinding(Port, true) .WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(Port)) - .UntilMessageIsLogged("is now Leader",o => o.WithTimeout(TimeSpan.FromSeconds(20)))) + .UntilMessageIsLogged("is now Leader", o => o.WithTimeout(TimeSpan.FromSeconds(20)))) .Build(); - + await _container.StartAsync().ConfigureAwait(false); } - + [Test] public async Task RqliteClientPing_Works() { @@ -34,7 +35,7 @@ public async Task RqliteClientPing_Works() var client = new RqliteClient(url); var version = await client.Ping(); - + Assert.That(version, Is.Not.Empty); Assert.That(Regex.IsMatch(version, @"v\d+.\d+\.*")); //v8.10.1 } @@ -45,16 +46,46 @@ public async Task RqliteClient_CanGetInsertData() var url = $"http://{_container.Hostname}:{_container.GetMappedPublicPort(Port)}"; _httpClient = new HttpClient() { BaseAddress = new Uri(url) }; var content = - new StringContent("[ \"CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT, age INTEGER)\" ]", Encoding.UTF8, "application/json"); + new StringContent("[ \"CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT, age INTEGER)\" ]", + Encoding.UTF8, "application/json"); var r = await _httpClient.PostAsync("/db/execute?timings", content); - + Assert.That(r.IsSuccessStatusCode); - + var client = new RqliteClient(url); - var result = await client.Execute("insert into foo(id, name, age) VALUES(1,\\\"john\\\", 42)"); Assert.That(result!.Results!.Count, Is.EqualTo(1)); Assert.That(result!.Results[0].RowsAffected, Is.EqualTo(1)); } + + [Test] + public async Task RqliteOrmClient_CanReadData() + { + var url = $"http://{_container.Hostname}:{_container.GetMappedPublicPort(Port)}"; + _httpClient = new HttpClient() { BaseAddress = new Uri(url) }; + var content = + new StringContent("[ \"CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT, age INTEGER)\" ]", + Encoding.UTF8, "application/json"); + var r = await _httpClient.PostAsync("/db/execute?timings", content); + Assert.That(r.IsSuccessStatusCode); + var insertContent = new StringContent("[ [\"INSERT INTO foo(name, age) VALUES(\\\"jane\\\", 42)\"] ]", + Encoding.UTF8, "application/json"); + var r1 = await _httpClient.PostAsync("/db/execute?timings", insertContent); + Assert.That(r1.IsSuccessStatusCode); + + var client = new RqliteOrmClient(url); + var result = await client.Query("select * from Foo"); + + Assert.That(result.Count, Is.EqualTo(1)); + Assert.That(result[0].Name, Is.EqualTo("jane")); + Assert.That(result[0].Age, Is.EqualTo(42)); + } + + record FooDto + { + public long Id { get; set; } + public string Name { get; set; } + public int Age { get; set; } + } } \ No newline at end of file diff --git a/RqliteDotnet.IntegrationTest/RqliteDotnet.IntegrationTest.csproj b/RqliteDotnet.IntegrationTest/RqliteDotnet.IntegrationTest.csproj index b0069a3..1b373b7 100644 --- a/RqliteDotnet.IntegrationTest/RqliteDotnet.IntegrationTest.csproj +++ b/RqliteDotnet.IntegrationTest/RqliteDotnet.IntegrationTest.csproj @@ -8,9 +8,9 @@ - + - + diff --git a/RqliteDotnet.Test/RqliteClientTests.cs b/RqliteDotnet.Test/RqliteClientTests.cs index ffa2f71..7d73a36 100644 --- a/RqliteDotnet.Test/RqliteClientTests.cs +++ b/RqliteDotnet.Test/RqliteClientTests.cs @@ -100,7 +100,7 @@ public async Task BasicQueryParam_Works() }); Assert.That(result!.Results!.Count, Is.EqualTo(1)); - Assert.That(result!.Results[0]!.Values[0]!.Count, Is.EqualTo(2)); + Assert.That(result!.Results[0]!.Values![0]!.Count, Is.EqualTo(2)); } } diff --git a/RqliteDotnet.Test/RqliteDotnet.Test.csproj b/RqliteDotnet.Test/RqliteDotnet.Test.csproj index 2d6c89d..51d5039 100644 --- a/RqliteDotnet.Test/RqliteDotnet.Test.csproj +++ b/RqliteDotnet.Test/RqliteDotnet.Test.csproj @@ -6,9 +6,9 @@ - + - + all