-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
3 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
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()); | ||
} | ||
} | ||
} |