Skip to content

Commit

Permalink
[ksqlDB.RestApi.Client]: unit tests code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfabian committed Nov 26, 2023
1 parent 16193e2 commit 396f2a2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class ChangesCacheTests
{
private ChangesCache ClassUnderTest { get; set; } = null!;

private Mock<IKSqlDbRestApiClient> KSqlDbRestApiClientMock = null!;
private Mock<IKSqlDbRestApiClient> kSqlDbRestApiClientMock = null!;

[SetUp]
public void TestInitialize()
{
KSqlDbRestApiClientMock = new Mock<IKSqlDbRestApiClient>();
kSqlDbRestApiClientMock = new Mock<IKSqlDbRestApiClient>();

ClassUnderTest = new ChangesCache();
}
Expand All @@ -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<KSqlDbStatement>(c => c.Sql == expectedSql), It.IsAny<CancellationToken>()), Times.Once);
kSqlDbRestApiClientMock.Verify(c => c.ExecuteStatementAsync(It.Is<KSqlDbStatement>(c => c.Sql == expectedSql), It.IsAny<CancellationToken>()), Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(contextOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, int[]> Dictionary { get; set; } = null!;
public IDictionary<string, int> Dictionary2 { get; set; } = null!;
public IDictionary<string, QbservableGroupByExtensionsTests.City> Dictionary3 { get; set; } = null!;
public string[] Messages { get; init; } = null!;
public int[] Values { get; init; } = null!;
public IDictionary<string, int[]> Dictionary { get; init; } = null!;
public IDictionary<string, int> Dictionary2 { get; init; } = null!;
public IDictionary<string, QbservableGroupByExtensionsTests.City> Dictionary3 { get; init; } = null!;
}

#region Array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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; }
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void FromBytes_CapturedVariable()
Assert.Throws<NotSupportedException>(() =>
{
//Act
var _ = ClassUnderTest.BuildKSql(expression);
_ = ClassUnderTest.BuildKSql(expression);
});
}

Expand Down

0 comments on commit 396f2a2

Please sign in to comment.