Skip to content

Commit bf31869

Browse files
committed
Added a few adapter tests.
Bumped core extension version used.
1 parent 7576512 commit bf31869

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

Tests/PowerSync/PowerSync.Common.Tests/Client/PowerSyncDatabaseTransactionTests.cs renamed to Tests/PowerSync/PowerSync.Common.Tests/Client/PowerSyncDatabaseTests.cs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
namespace PowerSync.Common.Tests.Client;
22

3+
using Microsoft.Data.Sqlite;
4+
35
using System.Diagnostics;
46
using PowerSync.Common.Client;
57

6-
public class PowerSyncDatabaseTransactionTests : IAsyncLifetime
8+
public class PowerSyncDatabaseTests : IAsyncLifetime
79
{
810
private PowerSyncDatabase db = default!;
911

@@ -27,6 +29,63 @@ private record IdResult(string id);
2729
private record AssetResult(string id, string description, string? make = null);
2830
private record CountResult(int count);
2931

32+
[Fact]
33+
public async Task QueryWithoutParamsTest()
34+
{
35+
var name = "Test User";
36+
var age = 30;
37+
38+
await db.Execute(
39+
"INSERT INTO assets(id, description, make) VALUES(?, ?, ?)",
40+
[Guid.NewGuid().ToString(), name, age.ToString()]
41+
);
42+
43+
var result = await db.GetAll<AssetResult>("SELECT id, description, make FROM assets");
44+
45+
Assert.Single(result);
46+
var row = result.First();
47+
Assert.Equal(name, row.description);
48+
Assert.Equal(age.ToString(), row.make);
49+
}
50+
51+
[Fact]
52+
public async Task QueryWithParamsTest()
53+
{
54+
var id = Guid.NewGuid().ToString();
55+
var name = "Test User";
56+
var age = 30;
57+
58+
await db.Execute(
59+
"INSERT INTO assets(id, description, make) VALUES(?, ?, ?)",
60+
[id, name, age.ToString()]
61+
);
62+
63+
var result = await db.GetAll<AssetResult>("SELECT id, description, make FROM assets WHERE id = ?", [id]);
64+
65+
Assert.Single(result);
66+
var row = result.First();
67+
Assert.Equal(id, row.id);
68+
Assert.Equal(name, row.description);
69+
Assert.Equal(age.ToString(), row.make);
70+
}
71+
72+
[Fact]
73+
public async Task FailedInsertTest()
74+
{
75+
var name = "Test User";
76+
var age = 30;
77+
78+
var exception = await Assert.ThrowsAsync<SqliteException>(async () =>
79+
{
80+
await db.Execute(
81+
"INSERT INTO assetsfail (id, description, make) VALUES(?, ?, ?)",
82+
[Guid.NewGuid().ToString(), name, age.ToString()]
83+
);
84+
});
85+
86+
Assert.Contains("no such table", exception.Message);
87+
}
88+
3089
[Fact]
3190
public async Task SimpleReadTransactionTest()
3291
{
@@ -334,7 +393,7 @@ public async Task Insert1000Records_CompleteWithinTimeLimitTest()
334393
int n = random.Next(0, 100000);
335394
await db.Execute(
336395
"INSERT INTO assets(id, description) VALUES(?, ?)",
337-
[i + 1, n]
396+
[(i + 1).ToString(), n]
338397
);
339398
}
340399

Tools/Setup/Setup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Setup
88
{
99
static async Task Main(string[] args)
1010
{
11-
const string baseUrl = "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v0.3.8";
11+
const string baseUrl = "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v0.3.14";
1212
string powersyncCorePath = Path.Combine(AppContext.BaseDirectory, "../../../../..", "PowerSync/PowerSync.Common/");
1313

1414
var runtimeIdentifiers = new Dictionary<string, (string originalFile, string newFile)>

0 commit comments

Comments
 (0)