Skip to content

Commit

Permalink
[ksqlDB.RestApi.Client]: RowValueJsonSerializer enum value deserializ…
Browse files Browse the repository at this point in the history
…ation unit tests
  • Loading branch information
tomasfabian committed Feb 20, 2024
1 parent b661194 commit 0215a2b
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NUnit.Framework;
using UnitTests;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using ksqlDb.RestApi.Client.Tests.KSql.RestApi.Generators;

namespace ksqlDb.RestApi.Client.Tests.KSql.RestApi;

Expand Down Expand Up @@ -340,4 +341,52 @@ public void DifferentLengthOfColumnNamesAndTypes_ThrowsInvalidOperationException
ClassUnderTest = new RowValueJsonSerializer(queryStreamHeader);
});
}

[Test]
public void Deserialize_VarcharAsEnum()
{
//Arrange
var queryStreamHeader = new QueryStreamHeader()
{
ColumnTypes = [KSqlTypes.Varchar],
ColumnNames = ["KSQL_COL_0"],
};

ClassUnderTest = new RowValueJsonSerializer(queryStreamHeader);

var value = "Snowflake";

string rawJson = $"[\"{value}\"]";
var jsonSerializationOptions = KSqlDbJsonSerializerOptions.CreateInstance();

//Act
var rowValue = ClassUnderTest.Deserialize<StatementGeneratorTests.PortType>(rawJson, jsonSerializationOptions);

//Assert
rowValue.Value.Should().Be(StatementGeneratorTests.PortType.Snowflake);
}

[Test]
public void Deserialize_IntoClass_VarcharAsEnumProperty()
{
//Arrange
var queryStreamHeader = new QueryStreamHeader()
{
ColumnTypes = [KSqlTypes.Int, KSqlTypes.Varchar],
ColumnNames = [nameof(StatementGeneratorTests.Port.Id).ToUpper(), nameof(StatementGeneratorTests.Port.PortType).ToUpper()],
};

ClassUnderTest = new RowValueJsonSerializer(queryStreamHeader);

var value = "Snowflake";

string rawJson = $"[42,\"{value}\"]";
var jsonSerializationOptions = KSqlDbJsonSerializerOptions.CreateInstance();

//Act
var rowValue = ClassUnderTest.Deserialize<StatementGeneratorTests.Port>(rawJson, jsonSerializationOptions);

//Assert
rowValue.Value.PortType.Should().Be(StatementGeneratorTests.PortType.Snowflake);
}
}

0 comments on commit 0215a2b

Please sign in to comment.