-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from tomasfabian/82-enhancing-fluent-api-imple…
…menting-the-hascolumnname-method 82 enhancing fluent API implementing the HasColumnName method
- Loading branch information
Showing
50 changed files
with
1,057 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
Tests/ksqlDB.RestApi.Client.IntegrationTests/KSql/Linq/ModelBuilderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using System.Text.Json.Serialization; | ||
using FluentAssertions; | ||
using ksqlDb.RestApi.Client.FluentAPI.Builders; | ||
using ksqlDb.RestApi.Client.IntegrationTests.Helpers; | ||
using ksqlDb.RestApi.Client.IntegrationTests.Models; | ||
using ksqlDB.RestApi.Client.KSql.Linq; | ||
using ksqlDB.RestApi.Client.KSql.RestApi; | ||
using ksqlDB.RestApi.Client.KSql.RestApi.Enums; | ||
using ksqlDB.RestApi.Client.KSql.RestApi.Http; | ||
using ksqlDB.RestApi.Client.KSql.RestApi.Statements; | ||
using ksqlDB.RestApi.Client.KSql.RestApi.Statements.Properties; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using NUnit.Framework; | ||
|
||
namespace ksqlDb.RestApi.Client.IntegrationTests.KSql.Linq | ||
{ | ||
public class ModelBuilderTests : Infrastructure.IntegrationTests | ||
{ | ||
protected static string StreamName = nameof(ModelBuilderTests); | ||
private static readonly string TopicName = StreamName; | ||
private static KSqlDbRestApiClient kSqlDbRestApiClient = null!; | ||
private static ModelBuilder modelBuilder = null!; | ||
|
||
[OneTimeSetUp] | ||
public static async Task ClassInitialize() | ||
{ | ||
await InitializeDatabase(); | ||
} | ||
|
||
public record Tweet : Record | ||
{ | ||
public int Id { get; set; } | ||
[JsonPropertyName("MESSAGE")] | ||
public string Message { get; set; } = null!; | ||
public bool IsRobot { get; set; } | ||
public double Amount { get; set; } | ||
public decimal AccountBalance { get; set; } | ||
} | ||
|
||
public static readonly Tweet Tweet1 = new() | ||
{ | ||
Id = 1, | ||
Message = "Hello world", | ||
IsRobot = true, | ||
Amount = 0.00042, | ||
}; | ||
|
||
public static readonly Tweet Tweet2 = new() | ||
{ | ||
Id = 2, | ||
Message = "Wall-e", | ||
IsRobot = false, | ||
Amount = 1, | ||
}; | ||
|
||
protected static async Task InitializeDatabase() | ||
{ | ||
modelBuilder = new ModelBuilder(); | ||
modelBuilder.Entity<Tweet>() | ||
.Property(c => c.Id) | ||
.HasColumnName("TweetId"); | ||
modelBuilder.Entity<Tweet>() | ||
.Property(c => c.AccountBalance) | ||
.Ignore(); | ||
|
||
var httpClient = new HttpClient | ||
{ | ||
BaseAddress = new Uri(TestConfig.KSqlDbUrl) | ||
}; | ||
kSqlDbRestApiClient = new KSqlDbRestApiClient(new HttpClientFactory(httpClient), modelBuilder); | ||
|
||
var entityCreationMetadata = new EntityCreationMetadata(TopicName, 1) | ||
{ | ||
EntityName = StreamName, | ||
ShouldPluralizeEntityName = false, | ||
IdentifierEscaping = IdentifierEscaping.Always | ||
}; | ||
var result = await kSqlDbRestApiClient.CreateStreamAsync<Tweet>(entityCreationMetadata, true); | ||
result.IsSuccess().Should().BeTrue(); | ||
|
||
var insertProperties = new InsertProperties() | ||
{ | ||
EntityName = StreamName, | ||
IdentifierEscaping = IdentifierEscaping.Always | ||
}; | ||
result = await kSqlDbRestApiClient.InsertIntoAsync(Tweet1, insertProperties); | ||
result.IsSuccess().Should().BeTrue(); | ||
|
||
result = await kSqlDbRestApiClient.InsertIntoAsync(Tweet2, insertProperties); | ||
result.IsSuccess().Should().BeTrue(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public static async Task ClassCleanup() | ||
{ | ||
var dropFromItemProperties = new DropFromItemProperties | ||
{ | ||
IdentifierEscaping = IdentifierEscaping.Always, | ||
ShouldPluralizeEntityName = false, | ||
EntityName = StreamName, | ||
UseIfExistsClause = true, | ||
DeleteTopic = true, | ||
}; | ||
await kSqlDbRestApiClient.DropStreamAsync<Models.Tweet>(dropFromItemProperties); | ||
} | ||
|
||
[SetUp] | ||
public override void TestInitialize() | ||
{ | ||
base.TestInitialize(); | ||
|
||
Context = CreateKSqlDbContext(ksqlDB.RestApi.Client.KSql.Query.Options.EndpointType.QueryStream, modelBuilder); | ||
} | ||
|
||
protected virtual IQbservable<Tweet> QuerySource => | ||
Context.CreatePushQuery<Tweet>($"`{StreamName}`"); | ||
|
||
[Test] | ||
public async Task Select() | ||
{ | ||
//Arrange | ||
int expectedItemsCount = 2; | ||
|
||
var source = QuerySource | ||
.ToAsyncEnumerable(); | ||
|
||
//Act | ||
var actualValues = await CollectActualValues(source, expectedItemsCount); | ||
|
||
//Assert | ||
var expectedValues = new List<Tweet> | ||
{ | ||
Tweet1, Tweet2 | ||
}; | ||
|
||
expectedItemsCount.Should().Be(actualValues.Count); | ||
CollectionAssert.AreEqual(expectedValues, actualValues); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.