Skip to content

Commit cb153b9

Browse files
committed
[ksqlDb.RestApi.Client]: added EntityTypeBuilder unit tests
1 parent 40a3628 commit cb153b9

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using FluentAssertions;
2+
using ksqlDb.RestApi.Client.FluentAPI.Builders;
3+
using ksqlDb.RestApi.Client.Metadata;
4+
using ksqlDb.RestApi.Client.Tests.Models;
5+
using NUnit.Framework;
6+
7+
namespace ksqlDb.RestApi.Client.Tests.FluentAPI.Builders
8+
{
9+
public class EntityTypeBuilderTests
10+
{
11+
private EntityTypeBuilder<Tweet> builder = null!;
12+
13+
[SetUp]
14+
public void TestInitialize()
15+
{
16+
builder = new();
17+
}
18+
19+
[Test]
20+
public void HasKey()
21+
{
22+
//Arrange
23+
24+
//Act
25+
var entityTypeBuilder = builder.HasKey(c => c.Id);
26+
27+
//Assert
28+
entityTypeBuilder.Should().NotBeNull();
29+
((EntityTypeBuilder)entityTypeBuilder).Metadata.PrimaryKeyMemberInfo.Should().NotBeNull();
30+
}
31+
32+
[Test]
33+
public void Property()
34+
{
35+
//Arrange
36+
37+
//Act
38+
var fieldTypeBuilder = builder.Property(c => c.Id);
39+
40+
//Assert
41+
fieldTypeBuilder.Should().NotBeNull();
42+
builder.Metadata.FieldsMetadata.Count().Should().Be(2);
43+
}
44+
45+
[Test]
46+
public void RowTime_Property_ShouldBeIgnoredInDDL()
47+
{
48+
//Arrange
49+
50+
//Act
51+
var fieldTypeBuilder = builder.Property(c => c.Id);
52+
53+
//Assert
54+
fieldTypeBuilder.Should().NotBeNull();
55+
builder.Metadata.FieldsMetadata.First(c => c.MemberInfo.Name == nameof(Tweet.RowTime)).IgnoreInDDL.Should().BeTrue();
56+
}
57+
58+
public class Foo
59+
{
60+
public long RowTime;
61+
}
62+
63+
[Test]
64+
public void RowTime_Field_ShouldBeIgnoredInDDL()
65+
{
66+
//Arrange
67+
68+
//Act
69+
EntityTypeBuilder<Foo> fooBuilder = new();
70+
71+
//Assert
72+
fooBuilder.Metadata.FieldsMetadata.First(c => c.MemberInfo.Name == nameof(Foo.RowTime)).IgnoreInDDL.Should().BeTrue();
73+
}
74+
75+
[Test]
76+
public void DecimalType_ShouldHaveDecimalFieldMetadata()
77+
{
78+
//Arrange
79+
80+
//Act
81+
var fieldTypeBuilder = builder.Property(c => c.AccountBalance);
82+
83+
//Assert
84+
fieldTypeBuilder.Should().NotBeNull();
85+
builder.Metadata.FieldsMetadata
86+
.OfType<DecimalFieldMetadata>()
87+
.First(c => c.MemberInfo.Name == nameof(Tweet.AccountBalance))
88+
.Should().NotBeNull();
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)