From 396f2a2a093e52c14bf7fbb24f0ed2ce15de3908 Mon Sep 17 00:00:00 2001 From: Tomas Fabian Date: Sun, 26 Nov 2023 10:20:39 +0100 Subject: [PATCH] [ksqlDB.RestApi.Client]: unit tests code improvements --- .../KSql/Query/Context/ChangesCacheTests.cs | 8 ++++---- .../KSql/Query/Context/KSqlDBContextTests.cs | 9 +++++++-- .../Query/Functions/KSqlInvocationFunctionsTests.cs | 10 +++++----- .../KSql/Query/KSqlQueryLanguageVisitorTests.cs | 12 ++++++------ .../Query/Visitors/KSqlFunctionVisitorStringTests.cs | 2 +- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/ChangesCacheTests.cs b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/ChangesCacheTests.cs index 08518ce8..94f6a9e9 100644 --- a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/ChangesCacheTests.cs +++ b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/ChangesCacheTests.cs @@ -10,12 +10,12 @@ public class ChangesCacheTests { private ChangesCache ClassUnderTest { get; set; } = null!; - private Mock KSqlDbRestApiClientMock = null!; + private Mock kSqlDbRestApiClientMock = null!; [SetUp] public void TestInitialize() { - KSqlDbRestApiClientMock = new Mock(); + kSqlDbRestApiClientMock = new Mock(); ClassUnderTest = new ChangesCache(); } @@ -28,12 +28,12 @@ public async Task AddTwice_SaveChangesAsyncWasNotCalled() ClassUnderTest.Enqueue(new KSqlDbStatement("Insert 2;")); //Act - var result = await ClassUnderTest.SaveChangesAsync(KSqlDbRestApiClientMock.Object, new CancellationToken()); + var result = await ClassUnderTest.SaveChangesAsync(kSqlDbRestApiClientMock.Object, new CancellationToken()); //Assert string expectedSql = @"Insert 1; Insert 2; "; - KSqlDbRestApiClientMock.Verify(c => c.ExecuteStatementAsync(It.Is(c => c.Sql == expectedSql), It.IsAny()), Times.Once); + kSqlDbRestApiClientMock.Verify(c => c.ExecuteStatementAsync(It.Is(c => c.Sql == expectedSql), It.IsAny()), Times.Once); } } diff --git a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/KSqlDBContextTests.cs b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/KSqlDBContextTests.cs index aa8797e2..15d6a0d2 100644 --- a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/KSqlDBContextTests.cs +++ b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/KSqlDBContextTests.cs @@ -125,8 +125,13 @@ public void CreateStreamSet_CalledMultipleTimes_KSqlQueryGeneratorBuildKSqlWasNo public void CreateStreamSet_Subscribe_KSqlQueryGenerator() { //Arrange - var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); - contextOptions.QueryStreamParameters["auto.offset.reset"] = "latest"; + var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl) + { + QueryStreamParameters = + { + ["auto.offset.reset"] = "latest" + } + }; var context = new TestableDbProvider(contextOptions); diff --git a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Functions/KSqlInvocationFunctionsTests.cs b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Functions/KSqlInvocationFunctionsTests.cs index 90b28f13..403c222f 100644 --- a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Functions/KSqlInvocationFunctionsTests.cs +++ b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Functions/KSqlInvocationFunctionsTests.cs @@ -27,11 +27,11 @@ public override void TestInitialize() class Tweets { public int Id { get; set; } - public string[] Messages { get; set; } = null!; - public int[] Values { get; set; } = null!; - public IDictionary Dictionary { get; set; } = null!; - public IDictionary Dictionary2 { get; set; } = null!; - public IDictionary Dictionary3 { get; set; } = null!; + public string[] Messages { get; init; } = null!; + public int[] Values { get; init; } = null!; + public IDictionary Dictionary { get; init; } = null!; + public IDictionary Dictionary2 { get; init; } = null!; + public IDictionary Dictionary3 { get; init; } = null!; } #region Array diff --git a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/KSqlQueryLanguageVisitorTests.cs b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/KSqlQueryLanguageVisitorTests.cs index 9b6798aa..7098ccc9 100644 --- a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/KSqlQueryLanguageVisitorTests.cs +++ b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/KSqlQueryLanguageVisitorTests.cs @@ -623,7 +623,7 @@ public void WhereSelect_BuildKSql_PrintsSelectFromWhere() class OrderData { public int OrderType { get; set; } - public string Category { get; set; } = null!; + public string Category { get; init; } = null!; } [Test] @@ -1160,7 +1160,7 @@ public void SelectDictionaryElementProjected_BuildKSql_PrintsMapElementAccess() private struct Point { - public int X { get; set; } + public int X { get; init; } public int Y { get; set; } } @@ -1833,14 +1833,14 @@ private static string SwitchExpressionProvider() { var location = new Location(); - var case_result = location.Longitude switch + var caseResult = location.Longitude switch { - var value when value < 2.0 => "small", - var value when (value <= 4.0) => "medium", + < 2.0 => "small", + <= 4.0 => "medium", _ => "large" }; - return case_result; + return caseResult; } //TODO:IfElse diff --git a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Visitors/KSqlFunctionVisitorStringTests.cs b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Visitors/KSqlFunctionVisitorStringTests.cs index 025a31f6..a566c3e3 100644 --- a/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Visitors/KSqlFunctionVisitorStringTests.cs +++ b/Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Visitors/KSqlFunctionVisitorStringTests.cs @@ -233,7 +233,7 @@ public void FromBytes_CapturedVariable() Assert.Throws(() => { //Act - var _ = ClassUnderTest.BuildKSql(expression); + _ = ClassUnderTest.BuildKSql(expression); }); }