Skip to content

Commit c09bddd

Browse files
committed
[ksqlDb.RestApi.Client]: added the IgnoreInDDL function to the Fluent API tests #93
1 parent 6486b3f commit c09bddd

File tree

7 files changed

+109
-9
lines changed

7 files changed

+109
-9
lines changed

Tests/ksqlDB.RestApi.Client.IntegrationTests/KSql/Linq/JoinsTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public static async Task ClassInitialize()
3434

3535
moviesProvider = new MoviesProvider(RestApiProvider);
3636

37+
await ClassCleanup();
38+
3739
var response = await RestApiProvider.CreateStreamAsync<Order>(OrderEntityCreationMetadata, ifNotExists: true);
3840

3941
await moviesProvider.DropTablesAsync();
@@ -93,7 +95,7 @@ public async Task Join()
9395
public async Task LeftJoin()
9496
{
9597
//Arrange
96-
int expectedItemsCount = 2;
98+
int expectedItemsCount = 1;
9799

98100
var source = Context.CreatePushQuery<Movie>(MoviesTableName)
99101
.LeftJoin(
@@ -120,9 +122,9 @@ public async Task LeftJoin()
120122
Assert.AreEqual(MoviesProvider.Movie1.Title, actualValues[0].Title);
121123
Assert.AreEqual(MoviesProvider.LeadActor1.Title, actualValues[0].Title);
122124

123-
actualValues[1].Substr.Length.Should().Be(4);
124-
actualValues[1].Release_Year.Should().BeOneOf(MoviesProvider.Movie1.Release_Year, MoviesProvider.Movie2.Release_Year);
125-
actualValues[1].ActorTitle.Should().BeOneOf(null, MoviesProvider.Movie1.Title, MoviesProvider.Movie2.Title);
125+
actualValues[0].Substr.Length.Should().Be(4);
126+
actualValues[0].Release_Year.Should().BeOneOf(MoviesProvider.Movie1.Release_Year, MoviesProvider.Movie2.Release_Year);
127+
actualValues[0].ActorTitle.Should().BeOneOf(null, MoviesProvider.Movie1.Title, MoviesProvider.Movie2.Title);
126128
}
127129

128130
public record Movie2 : Record

Tests/ksqlDB.RestApi.Client.IntegrationTests/KSql/Linq/ModelBuilderTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using ksqlDB.RestApi.Client.KSql.Linq;
77
using ksqlDB.RestApi.Client.KSql.RestApi;
88
using ksqlDB.RestApi.Client.KSql.RestApi.Enums;
9+
using ksqlDB.RestApi.Client.KSql.RestApi.Extensions;
910
using ksqlDB.RestApi.Client.KSql.RestApi.Http;
1011
using ksqlDB.RestApi.Client.KSql.RestApi.Statements;
1112
using ksqlDB.RestApi.Client.KSql.RestApi.Statements.Properties;
@@ -42,6 +43,7 @@ public record Tweet : Record
4243
Message = "Hello world",
4344
IsRobot = true,
4445
Amount = 0.00042,
46+
RowTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
4547
};
4648

4749
public static readonly Tweet Tweet2 = new()
@@ -50,6 +52,7 @@ public record Tweet : Record
5052
Message = "Wall-e",
5153
IsRobot = false,
5254
Amount = 1,
55+
RowTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
5356
};
5457

5558
protected static async Task InitializeDatabase()
@@ -68,6 +71,8 @@ protected static async Task InitializeDatabase()
6871
};
6972
kSqlDbRestApiClient = new KSqlDbRestApiClient(new HttpClientFactory(httpClient), modelBuilder);
7073

74+
await ClassCleanup();
75+
7176
var entityCreationMetadata = new EntityCreationMetadata(TopicName, 1)
7277
{
7378
EntityName = StreamName,
@@ -135,5 +140,25 @@ public async Task Select()
135140
expectedItemsCount.Should().Be(actualValues.Count);
136141
CollectionAssert.AreEqual(expectedValues, actualValues);
137142
}
143+
144+
[Test]
145+
public async Task SelectPseudoColumns()
146+
{
147+
//Arrange
148+
int expectedItemsCount = 2;
149+
150+
var source = QuerySource
151+
.Select(c => new{ c.RowTime, c.RowOffset, c.Message })
152+
.ToAsyncEnumerable();
153+
154+
//Act
155+
var actualValues = await CollectActualValues(source, expectedItemsCount);
156+
157+
//Assert
158+
expectedItemsCount.Should().Be(actualValues.Count);
159+
actualValues[0].RowTime.Should().Be(Tweet1.RowTime);
160+
actualValues[0].RowTime.Should().BeGreaterOrEqualTo(0);
161+
actualValues[0].Message.Should().Be(Tweet1.Message);
162+
}
138163
}
139164
}

Tests/ksqlDB.RestApi.Client.IntegrationTests/KSql/Linq/MoviesProvider.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,30 @@ actor_name VARCHAR
5555
{
5656
Id = 1,
5757
Release_Year = 1986,
58-
Title = "Aliens"
58+
Title = "Aliens",
59+
RowTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
5960
};
6061

6162
public static readonly Movie Movie2 = new()
6263
{
6364
Id = 2,
6465
Release_Year = 1988,
65-
Title = "Die Hard"
66+
Title = "Die Hard",
67+
RowTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
6668
};
6769

6870
public static readonly Lead_Actor LeadActor1 = new()
6971
{
7072
Actor_Name = "Sigourney Weaver",
71-
Title = "Aliens"
73+
Title = "Aliens",
74+
RowTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
7275
};
7376

7477
public static readonly Lead_Actor LeadActor2 = new()
7578
{
7679
Actor_Name = "Al Pacino",
77-
Title = "The Godfather"
80+
Title = "The Godfather",
81+
RowTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
7882
};
7983

8084
public async Task<bool> InsertMovieAsync(Movie movie)

Tests/ksqlDB.RestApi.Client.IntegrationTests/Models/Record.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ namespace ksqlDb.RestApi.Client.IntegrationTests.Models;
44

55
public record Record
66
{
7-
[ksqlDB.RestApi.Client.KSql.RestApi.Statements.Annotations.Ignore]
87
[PseudoColumn]
8+
[IgnoreInDDL]
99
public long RowTime { get; set; }
10+
11+
[ksqlDB.RestApi.Client.KSql.RestApi.Statements.Annotations.Ignore]
12+
[PseudoColumn]
13+
public long? RowOffset { get; set; }
1014
}

Tests/ksqlDB.RestApi.Client.Tests/FluentAPI/Builders/ModelBuilderTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ public void Property_IgnoreInDML()
8484
entityMetadata!.FieldsMetadata.First(c => c.MemberInfo.Name == nameof(Payment.Description)).IgnoreInDML.Should().BeTrue();
8585
}
8686

87+
[Test]
88+
public void Property_IgnoreInDDL()
89+
{
90+
//Arrange
91+
92+
//Act
93+
var fieldTypeBuilder = builder.Entity<Payment>()
94+
.Property(b => b.Description)
95+
.IgnoreInDDL();
96+
97+
//Assert
98+
fieldTypeBuilder.Should().NotBeNull();
99+
var entityMetadata = ((IMetadataProvider)builder).GetEntities().FirstOrDefault(c => c.Type == typeof(Payment));
100+
entityMetadata.Should().NotBeNull();
101+
entityMetadata!.FieldsMetadata.First(c => c.MemberInfo.Name == nameof(Payment.Description)).IgnoreInDDL.Should().BeTrue();
102+
}
103+
87104
[Test]
88105
public void Property_HasColumnName()
89106
{

Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Generators/TypeGeneratorTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ public void CreateType_ModelBuilder_HasColumnName()
6868
.Be($"CREATE TYPE {nameof(Address)} AS STRUCT<{columnName} INT, Street VARCHAR, City VARCHAR>;");
6969
}
7070

71+
[Test]
72+
public void CreateType_ModelBuilder_IgnoreInDDL()
73+
{
74+
//Arrange
75+
modelBuilder.Entity<Address>()
76+
.Property(b => b.Number)
77+
.IgnoreInDDL();
78+
79+
//Act
80+
var statement = new TypeGenerator(modelBuilder).Print<Address>(new TypeProperties());
81+
82+
//Assert
83+
statement.Should()
84+
.Be($"CREATE TYPE {nameof(Address)} AS STRUCT<Street VARCHAR, City VARCHAR>;");
85+
}
86+
7187
[Test]
7288
public void CreateType_WithTypeName()
7389
{
@@ -146,6 +162,8 @@ public record Address
146162
public int Number { get; set; }
147163
public string Street { get; set; } = null!;
148164
public string City { get; set; } = null!;
165+
[IgnoreInDDL]
166+
public string Secret { get; set; } = null!;
149167
}
150168

151169
public class Person

Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/Statements/CreateEntityTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,4 +758,34 @@ public void ModelBuilder_IgnoreProperty()
758758
{nameof(Poco.Id)} INT PRIMARY KEY
759759
) WITH ( KAFKA_TOPIC='{nameof(Poco)}', VALUE_FORMAT='Json', PARTITIONS='1', REPLICAS='1' );".ReplaceLineEndings());
760760
}
761+
762+
internal class IgnoreInDDL
763+
{
764+
[Key]
765+
public int Id { get; set; }
766+
[IgnoreInDDL]
767+
[PseudoColumn]
768+
public string RowTime { get; set; }
769+
}
770+
771+
[Test]
772+
public void Print_IgnoreInDDLAttribute()
773+
{
774+
//Arrange
775+
var statementContext = new StatementContext
776+
{
777+
CreationType = CreationType.CreateOrReplace,
778+
KSqlEntityType = KSqlEntityType.Table,
779+
};
780+
781+
creationMetadata.KafkaTopic = nameof(IgnoreInDDL);
782+
783+
//Act
784+
string statement = new CreateEntity(modelBuilder).Print<IgnoreInDDL>(statementContext, creationMetadata, null);
785+
786+
//Assert
787+
statement.Should().Be($@"CREATE OR REPLACE TABLE {nameof(IgnoreInDDL)}s (
788+
{nameof(IgnoreInDDL.Id)} INT PRIMARY KEY
789+
) WITH ( KAFKA_TOPIC='{nameof(IgnoreInDDL)}', VALUE_FORMAT='Json', PARTITIONS='1', REPLICAS='1' );".ReplaceLineEndings());
790+
}
761791
}

0 commit comments

Comments
 (0)