Skip to content

Commit

Permalink
[ksqlDb.RestApi.Client]: added CreateEntity ModelBuilder DerivedType …
Browse files Browse the repository at this point in the history
…HasKey
  • Loading branch information
tomasfabian committed Apr 12, 2024
1 parent 2103f0d commit b79511b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PocoEx>()
.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<PocoEx>(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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit b79511b

Please sign in to comment.