From b79511bc14d63bec3f2cef0265f5cd8cbfd01627 Mon Sep 17 00:00:00 2001 From: Tomas Fabian Date: Fri, 12 Apr 2024 17:04:09 +0200 Subject: [PATCH] [ksqlDb.RestApi.Client]: added CreateEntity ModelBuilder DerivedType HasKey --- .../RestApi/Statements/CreateEntityTests.cs | 32 +++++++++++++++++++ .../Statements/KSqlTypeTranslatorTests.cs | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Statements/CreateEntityTests.cs b/Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Statements/CreateEntityTests.cs index d57c342c..f6019df6 100644 --- a/Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Statements/CreateEntityTests.cs +++ b/Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Statements/CreateEntityTests.cs @@ -602,6 +602,38 @@ public void ModelBuilder_EntityHasKey() ) WITH ( KAFKA_TOPIC='{nameof(Poco)}', VALUE_FORMAT='Json', PARTITIONS='1', REPLICAS='1' );".ReplaceLineEndings()); } + private class PocoEx : Poco + { + public int IdEx { get; init; } + } + + [Test] + public void ModelBuilder_DerivedTypeHasKey() + { + //Arrange + modelBuilder.Entity() + .HasKey(x => x.IdEx) + .Property(c => c.Id) + .Ignore(); + + var statementContext = new StatementContext + { + CreationType = CreationType.CreateOrReplace, + KSqlEntityType = KSqlEntityType.Table, + }; + + creationMetadata.KafkaTopic = nameof(PocoEx); + + //Act + string statement = new CreateEntity(modelBuilder).Print(statementContext, creationMetadata, null); + + //Assert + statement.Should().Be($@"CREATE OR REPLACE TABLE {nameof(PocoEx)}es ( + {nameof(PocoEx.IdEx)} INT PRIMARY KEY, + {nameof(Poco.Description)} VARCHAR +) WITH ( KAFKA_TOPIC='{nameof(PocoEx)}', VALUE_FORMAT='Json', PARTITIONS='1', REPLICAS='1' );".ReplaceLineEndings()); + } + [Test] public void ModelBuilder_IgnoreProperty() { diff --git a/Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Statements/KSqlTypeTranslatorTests.cs b/Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Statements/KSqlTypeTranslatorTests.cs index 44ec4340..58c4075c 100644 --- a/Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Statements/KSqlTypeTranslatorTests.cs +++ b/Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Statements/KSqlTypeTranslatorTests.cs @@ -419,7 +419,7 @@ public void Translate_UseModelBuilderConvention() [Struct] private record PocoEx : Poco { - public string Description { get; set; } = null!; + public string Description { get; init; } = null!; } [Test]