Skip to content

Commit 8229ca4

Browse files
committed
Warning hunting
1 parent a43d126 commit 8229ca4

File tree

5 files changed

+48
-40
lines changed

5 files changed

+48
-40
lines changed

Tests/PowerSync/PowerSync.Common.Tests/Client/PowerSyncDatabaseTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ public async Task Watch_TriggerImmediately_True()
809809
Assert.True(await moveNext);
810810

811811
var current = enumerator.Current;
812-
Assert.Equal(1, current.Length);
812+
Assert.Single(current);
813813
Assert.Equal(3, current[0].count);
814814
}
815815

@@ -835,7 +835,7 @@ public async Task Watch_TriggerImmediately_False()
835835
Assert.True(await moveNext);
836836

837837
var current = enumerator.Current;
838-
Assert.Equal(1, current.Length);
838+
Assert.Single(current);
839839
Assert.Equal(3, current[0].count);
840840
}
841841

Tests/PowerSync/PowerSync.Common.Tests/Client/Sync/SyncTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ public class SyncTests : IAsyncLifetime
1414
MockSyncService syncService = null!;
1515
PowerSyncDatabase db = null!;
1616

17-
public async Task InitializeAsync()
17+
public Task InitializeAsync()
1818
{
1919
syncService = new MockSyncService();
2020
db = syncService.CreateDatabase();
21+
return Task.CompletedTask;
2122
}
2223

2324
public async Task DisposeAsync()

Tests/PowerSync/PowerSync.Common.Tests/DB/SchemaTests.cs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ private void TestParser(Type type, CompiledTable expected)
2929
]
3030
class Asset
3131
{
32-
public string id { get; set; }
32+
public string id { get; set; } = "";
3333

3434
public DateTime created_at { get; set; }
3535

36-
public string make { get; set; }
36+
public string make { get; set; } = "";
3737

38-
public string model { get; set; }
38+
public string model { get; set; } = "";
3939

4040
public int quantity { get; set; }
4141

4242
public string? description { get; set; }
4343

4444
[Ignored]
45-
public string non_table_field { get; set; }
45+
public string non_table_field { get; set; } = "";
4646
}
4747

4848
[Fact]
@@ -87,20 +87,20 @@ public void AttributeParser_Assets_Test()
8787
]
8888
class Product
8989
{
90-
public string id { get; set; }
90+
public string id { get; set; } = "";
9191

9292
[Column(ColumnType = ColumnType.Real)]
9393
public DateTime created_at { get; set; }
9494

95-
public string description { get; set; }
95+
public string description { get; set; } = "";
9696

9797
[Column(TrackPrevious = true)]
9898
public int quantity { get; set; }
9999

100100
[Column(TrackPrevious = true)]
101101
public decimal ppu { get; set; }
102102

103-
public string seller_id { get; set; }
103+
public string seller_id { get; set; } = "";
104104
}
105105

106106
[Fact]
@@ -158,10 +158,10 @@ enum LogLevel
158158
class Log
159159
{
160160
[Column("id")]
161-
public string LogId { get; set; }
161+
public string LogId { get; set; } = "";
162162

163163
[Column("description")]
164-
public string Description { get; set; }
164+
public string Description { get; set; } = "";
165165

166166
[Column("timestamp")]
167167
public DateTimeOffset Timestamp { get; set; }
@@ -199,13 +199,14 @@ public void AttributeParser_Logs_Test()
199199
TestParser(typeof(Log), expected);
200200
}
201201

202-
class Invalid1 { public string id { get; set; } }
202+
class Invalid1 { public string id { get; set; } = ""; }
203203
[Fact]
204204
public async void AttributeParser_InvalidSchema_1()
205205
{
206-
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
206+
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
207207
{
208208
new AttributeParser(typeof(Invalid1)).ParseTable();
209+
return Task.CompletedTask;
209210
});
210211
Assert.Contains("must be marked with TableAttribute", ex.Message);
211212
}
@@ -215,9 +216,10 @@ class Invalid2 { }
215216
[Fact]
216217
public async void AttributeParser_InvalidSchema_2()
217218
{
218-
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
219+
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
219220
{
220221
new AttributeParser(typeof(Invalid2)).ParseTable();
222+
return Task.CompletedTask;
221223
});
222224
Assert.Contains("'id' property is required", ex.Message);
223225
}
@@ -227,9 +229,10 @@ class Invalid3 { public int id { get; set; } }
227229
[Fact]
228230
public async void AttributeParser_InvalidSchema_3()
229231
{
230-
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
232+
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
231233
{
232234
new AttributeParser(typeof(Invalid3)).ParseTable();
235+
return Task.CompletedTask;
233236
});
234237
Assert.Contains("must be of type string", ex.Message);
235238
}
@@ -238,66 +241,70 @@ public async void AttributeParser_InvalidSchema_3()
238241
class Invalid4
239242
{
240243
[Column(ColumnType = ColumnType.Real)]
241-
public string id { get; set; }
244+
public string id { get; set; } = "";
242245
}
243246
[Fact]
244247
public async void AttributeParser_InvalidSchema_4()
245248
{
246-
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
249+
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
247250
{
248251
new AttributeParser(typeof(Invalid4)).ParseTable();
252+
return Task.CompletedTask;
249253
});
250254
Assert.Contains("must have ColumnType set to ColumnType.Text or ColumnType.Inferred", ex.Message);
251255
}
252256

253257
[Table("invalid")]
254258
class Invalid5
255259
{
256-
public string id { get; set; }
257-
public Invalid1 invalid_type { get; set; }
260+
public string id { get; set; } = "";
261+
public Invalid1 invalid_type { get; set; } = default!;
258262
}
259263
[Fact]
260264
public async void AttributeParser_InvalidSchema_5()
261265
{
262-
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
266+
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
263267
{
264268
new AttributeParser(typeof(Invalid5)).ParseTable();
269+
return Task.CompletedTask;
265270
});
266271
Assert.Contains("Unable to automatically infer ColumnType", ex.Message);
267272
}
268273

269274
[Table("invalid", TrackPreviousValues = TrackPrevious.Columns | TrackPrevious.Table)]
270275
class Invalid6
271276
{
272-
public string id { get; set; }
277+
public string id { get; set; } = "";
273278
}
274279
[Fact]
275280
public async void AttributeParser_InvalidSchema_6()
276281
{
277-
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
282+
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
278283
{
279284
new AttributeParser(typeof(Invalid6)).ParseTable();
285+
return Task.CompletedTask;
280286
});
281287
Assert.Contains("Cannot specify both TrackPrevious.Columns and TrackPrevious.Table", ex.Message);
282288
}
283289

284290
[Table("invalid", TrackPreviousValues = TrackPrevious.OnlyWhenChanged)]
285291
class Invalid7
286292
{
287-
public string id { get; set; }
293+
public string id { get; set; } = "";
288294
}
289295
[Fact]
290296
public async void AttributeParser_InvalidSchema_7()
291297
{
292-
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
298+
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
293299
{
294300
new AttributeParser(typeof(Invalid7)).ParseTable();
301+
return Task.CompletedTask;
295302
});
296303
Assert.Contains("Cannot specify TrackPrevious.OnlyWhenChanged without also specifying", ex.Message);
297304
}
298305

299306
[Fact]
300-
public async void AttributeParser_TypeMap_CustomRegistered()
307+
public void AttributeParser_TypeMap_CustomRegistered()
301308
{
302309
// Log has Column aliases
303310
new AttributeParser(typeof(Log)).RegisterDapperTypeMap();
@@ -306,7 +313,7 @@ public async void AttributeParser_TypeMap_CustomRegistered()
306313
}
307314

308315
[Fact]
309-
public async void AttributeParser_TypeMap_DefaultRegistered()
316+
public void AttributeParser_TypeMap_DefaultRegistered()
310317
{
311318
// Asset has no Column aliases
312319
new AttributeParser(typeof(Asset)).RegisterDapperTypeMap();

Tests/PowerSync/PowerSync.Common.Tests/EventStreamTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public async Task EventStream_ShouldReceiveTwoMessages_Sync()
110110
}
111111

112112
[Fact]
113-
public async Task EventManager_RegistersStreamsCorrectly()
113+
public void EventManager_RegistersStreamsCorrectly()
114114
{
115115
var manager = new EventManager();
116116
var stream1 = new EventStream<bool>();
@@ -126,13 +126,13 @@ public async Task EventManager_RegistersStreamsCorrectly()
126126

127127
Assert.Equal(stream1, obtainedStream1);
128128
Assert.Equal(stream2, obtainedStream2);
129-
Assert.Equal(null, obtainedStream3);
129+
Assert.Null(obtainedStream3);
130130

131131
manager.Close();
132132
}
133133

134134
[Fact]
135-
public async Task EventManager_CloseRemovesAndClosesStreams()
135+
public void EventManager_CloseRemovesAndClosesStreams()
136136
{
137137
var manager = new EventManager();
138138
var stream1 = new EventStream<bool>();
@@ -148,9 +148,9 @@ public async Task EventManager_CloseRemovesAndClosesStreams()
148148
Assert.False(manager.TryGetStream<string>(out var obtainedStream2));
149149
Assert.False(manager.TryGetStream<int>(out var obtainedStream3));
150150

151-
Assert.Equal(null, obtainedStream1);
152-
Assert.Equal(null, obtainedStream2);
153-
Assert.Equal(null, obtainedStream3);
151+
Assert.Null(obtainedStream1);
152+
Assert.Null(obtainedStream2);
153+
Assert.Null(obtainedStream3);
154154

155155
Assert.True(stream1.Closed);
156156
Assert.True(stream2.Closed);

Tests/PowerSync/PowerSync.Common.Tests/Utils/Sync/MockSyncService.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public MockRemote(
154154
this.connectedListeners = connectedListeners;
155155
}
156156

157-
public override async Task<Stream> PostStreamRaw(SyncStreamOptions options)
157+
public override Task<Stream> PostStreamRaw(SyncStreamOptions options)
158158
{
159159
connectedListeners.Add(options.Data);
160160

@@ -181,27 +181,27 @@ public override async Task<Stream> PostStreamRaw(SyncStreamOptions options)
181181
}
182182
});
183183

184-
return pipe.Reader.AsStream();
184+
return Task.FromResult(pipe.Reader.AsStream());
185185
}
186186

187-
public override async Task<T> Get<T>(string path, Dictionary<string, string>? headers = null)
187+
public override Task<T> Get<T>(string path, Dictionary<string, string>? headers = null)
188188
{
189189
var response = new StreamingSyncImplementation.ApiResponse(
190190
new StreamingSyncImplementation.ResponseData("1")
191191
);
192192

193-
return (T)(object)response;
193+
return Task.FromResult((T)(object)response);
194194
}
195195
}
196196

197197
public class TestConnector : IPowerSyncBackendConnector
198198
{
199-
public async Task<PowerSyncCredentials?> FetchCredentials()
199+
public Task<PowerSyncCredentials?> FetchCredentials()
200200
{
201-
return new PowerSyncCredentials(
201+
return Task.FromResult<PowerSyncCredentials?>(new PowerSyncCredentials(
202202
endpoint: "https://powersync.example.org",
203203
token: "test"
204-
);
204+
));
205205
}
206206

207207
public async Task UploadData(IPowerSyncDatabase database)

0 commit comments

Comments
 (0)