Skip to content

Commit 6e9a86c

Browse files
committed
[ksqlDB.RestApi.Client]: added KSqlDbProvider.JsonPropertyNameModifier unit tests
1 parent 2f07eb8 commit 6e9a86c

File tree

1 file changed

+68
-5
lines changed

1 file changed

+68
-5
lines changed

Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/KSqlDbProviderTests.cs

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization.Metadata;
13
using FluentAssertions;
4+
using ksqlDb.RestApi.Client.FluentAPI.Builders;
5+
using ksqlDB.RestApi.Client.KSql.RestApi;
26
using ksqlDB.RestApi.Client.KSql.RestApi.Exceptions;
37
using ksqlDB.RestApi.Client.KSql.RestApi.Parameters;
48
using ksqlDb.RestApi.Client.Tests.Fakes.Logging;
@@ -34,7 +38,7 @@ public async Task Run_LogInformation()
3438
var queryParameters = new QueryStreamParameters();
3539

3640
//Act
37-
var tweets = await ClassUnderTest.Run<Tweet>(queryParameters).ToListAsync();
41+
await ClassUnderTest.Run<Tweet>(queryParameters).ToListAsync();
3842

3943
//Assert
4044
LoggerMock.VerifyLog(LogLevel.Information, Times.Once);
@@ -177,12 +181,11 @@ public async Task LogError()
177181
try
178182
{
179183
//Act
180-
var tweets = await ClassUnderTest.Run<Tweet>(queryParameters).ToListAsync();
181-
182-
//Assert
184+
await ClassUnderTest.Run<Tweet>(queryParameters).ToListAsync();
183185
}
184186
catch (Exception)
185187
{
188+
//Assert
186189
LoggerMock.VerifyLog(LogLevel.Error, Times.Once);
187190
}
188191
}
@@ -196,7 +199,7 @@ public async Task Run_Disposed_NothingWasReceived()
196199

197200
//Act
198201
IAsyncEnumerable<Tweet> tweets = ClassUnderTest.Run<Tweet>(queryParameters, cts.Token);
199-
cts.Cancel();
202+
await cts.CancelAsync();
200203

201204
//Assert
202205
var receivedTweets = new List<Tweet>();
@@ -237,4 +240,64 @@ public async Task Run_DonNotDisposeHttpClient()
237240
//Assert
238241
ClassUnderTest.LastUsedHttpClient.IsDisposed.Should().BeTrue();
239242
}
243+
244+
private class DomainObject
245+
{
246+
public int Id { get; set; }
247+
}
248+
249+
#region JsonPropertyNameModifier
250+
251+
[Test]
252+
public void JsonPropertyNameModifier()
253+
{
254+
//Arrange
255+
var modelBuilder = new ModelBuilder();
256+
var jsonTypeInfo = new DefaultJsonTypeInfoResolver().GetTypeInfo(typeof(DomainObject), new JsonSerializerOptions());
257+
258+
//Act
259+
KSqlDbProvider.JsonPropertyNameModifier(jsonTypeInfo, modelBuilder);
260+
261+
//Assert
262+
jsonTypeInfo.Properties[0].Name.Should().Be(nameof(DomainObject.Id));
263+
}
264+
265+
[Test]
266+
public void JsonPropertyNameModifier_ModelBuilder_HasColumnNameOverride()
267+
{
268+
//Arrange
269+
var idColumnName = "id";
270+
var modelBuilder = new ModelBuilder();
271+
modelBuilder.Entity<DomainObject>()
272+
.Property(c => c.Id)
273+
.HasColumnName(idColumnName);
274+
275+
var jsonTypeInfo = new DefaultJsonTypeInfoResolver().GetTypeInfo(typeof(DomainObject), new JsonSerializerOptions());
276+
277+
//Act
278+
KSqlDbProvider.JsonPropertyNameModifier(jsonTypeInfo, modelBuilder);
279+
280+
//Assert
281+
jsonTypeInfo.Properties[0].Name.Should().Be(idColumnName);
282+
}
283+
284+
[Test]
285+
public void JsonPropertyNameModifier_ModelBuilder_WithoutHasColumnNameOverride()
286+
{
287+
//Arrange
288+
var modelBuilder = new ModelBuilder();
289+
modelBuilder.Entity<DomainObject>()
290+
.Property(c => c.Id)
291+
.WithHeaders();
292+
293+
var jsonTypeInfo = new DefaultJsonTypeInfoResolver().GetTypeInfo(typeof(DomainObject), new JsonSerializerOptions());
294+
295+
//Act
296+
KSqlDbProvider.JsonPropertyNameModifier(jsonTypeInfo, modelBuilder);
297+
298+
//Assert
299+
jsonTypeInfo.Properties[0].Name.Should().Be(nameof(DomainObject.Id));
300+
}
301+
302+
#endregion
240303
}

0 commit comments

Comments
 (0)