Skip to content

Commit

Permalink
tested table creation
Browse files Browse the repository at this point in the history
  • Loading branch information
lsfera committed Jul 23, 2024
1 parent 2099dea commit 9e61609
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/Blumchen/IDictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Collections;
using Blumchen.Subscriber;

namespace Blumchen;

internal static class IDictionaryExtensions
Expand Down
1 change: 1 addition & 0 deletions src/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FsCheck.Xunit" Version="2.16.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.17">
Expand Down
51 changes: 51 additions & 0 deletions src/UnitTests/message_table_creation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Blumchen;
using FsCheck.Xunit;

namespace UnitTests
{
public class message_table_creation
{
[Fact]
public void default_table_descriptor()
{
const string sql = """
CREATE TABLE IF NOT EXISTS outbox (
id Bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
message_type Varchar(250) NOT NULL,
data Jsonb NOT NULL
);
""";

var implicitTableDescriptor = new TableDescriptorBuilder().Build();
var explicitTableDescriptor = new TableDescriptorBuilder().UseDefaults().Build();
Assert.Equal(implicitTableDescriptor.ToString(), explicitTableDescriptor.ToString());
Assert.Equal(sql, implicitTableDescriptor.ToString());
}

[Property]
public void with_varying_descriptor(
string tableName,
string idColName,
string messageTypeColName,
int messageTypeColDimension,
string dataColName)
{
var sql = $"""
CREATE TABLE IF NOT EXISTS {tableName} (
{idColName} Bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
{messageTypeColName} Varchar({messageTypeColDimension}) NOT NULL,
{dataColName} Jsonb NOT NULL
);
""";

var tableDescriptor = new TableDescriptorBuilder()
.Named(tableName)
.Id(idColName)
.MessageType(messageTypeColName, messageTypeColDimension)
.MessageData(dataColName)
.Build();

Assert.Equal(sql, tableDescriptor.ToString());
}
}
}

0 comments on commit 9e61609

Please sign in to comment.