Skip to content

Commit

Permalink
Add test and update dependencies (#23)
Browse files Browse the repository at this point in the history
* Add tests and update dependencies

* Update dependencies
  • Loading branch information
arthrp authored Dec 25, 2024
1 parent 5c15a7e commit 197f4db
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
47 changes: 39 additions & 8 deletions RqliteDotnet.IntegrationTest/RqliteClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace RqliteDotnet.IntegrationTest;

[TestFixture]
public class RqliteClientTests
{
private const int Port = 4001;
Expand All @@ -21,20 +22,20 @@ 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()
{
var url = $"http://{_container.Hostname}:{_container.GetMappedPublicPort(Port)}";
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
}
Expand All @@ -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<FooDto>("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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit" Version="4.3.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Testcontainers" Version="4.0.0" />
<PackageReference Include="Testcontainers" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion RqliteDotnet.Test/RqliteClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
4 changes: 2 additions & 2 deletions RqliteDotnet.Test/RqliteDotnet.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit" Version="4.3.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 197f4db

Please sign in to comment.