Skip to content

Commit

Permalink
Make sure boolean mappings work
Browse files Browse the repository at this point in the history
  • Loading branch information
Arve Hansen committed Jun 26, 2024
1 parent b79f418 commit c7023ce
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 19 deletions.
19 changes: 0 additions & 19 deletions src/CrossRDBMS.Tests/CopyFromMssToPg/CopyDateTimes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,4 @@ private void MapAllDateTimesToTimestampTz()
" \"datetime2\": \"timestamp with time zone\",\r\n" +
" \"datetimeoffset\": \"timestamp with time zone\"\r\n"));
}

private static MockFileData GetMappingFile(string typeConversions)
{
return new MockFileData(
"{\r\n" +
" \"Schemas\": {\r\n" +
" \"\": \"public\",\r\n" +
" \"dbo\": \"public\",\r\n" +
" \"my_mss_schema\": \"my_pg_schema\"\r\n" +
" },\r\n" +
" \"Collations\": {\r\n" +
" \"SQL_Latin1_General_CP1_CI_AI\": \"en_ci_ai\",\r\n" +
" \"SQL_Latin1_General_CP1_CI_AS\": \"en_ci_as\"\r\n" +
" },\r\n" +
" \"ColumnTypes\": {\r\n" +
typeConversions +
" }\r\n" +
"}");
}
}
60 changes: 60 additions & 0 deletions src/CrossRDBMS.Tests/CopyFromMssToPg/CopyMisc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace CrossRDBMS.Tests.CopyFromMssToPg;

[Collection(nameof(DatabaseCollection))]
public class CopyMisc : CopyMssToPgBase
{
public CopyMisc(DatabaseFixture fixture, ITestOutputHelper output) : base(fixture, output)
{
PgArguments = ParamHelper.GetInPg(
fixture.PgConnectionString,
mappingsFile: "mymappings.json");
}

[Fact]
public async Task CopyBit_To_Boolean()
{
var tableName = GetName(nameof(CopyFromMssToPg));
var colValue = 1;
var col = new SqlServerBit(101, "col1", false);
MapTo("boolean");

await TestSingleTypeAsync(
tableName, col, colValue.ToString(), "boolean");

await ValidateValueAsync(("public", tableName), true);
}

[Fact]
public async Task CopyBit_To_SmallInt()
{
var tableName = GetName(nameof(CopyFromMssToPg));
var colValue = 1;
var col = new SqlServerBit(101, "col1", false);
MapTo("smallint");

await TestSingleTypeAsync(
tableName, col, colValue.ToString(), "smallint");

await ValidateValueAsync(("public", tableName), (short)colValue);
}

[Fact]
public async Task CopyBit_To_Int()
{
var tableName = GetName(nameof(CopyFromMssToPg));
var colValue = 1;
var col = new SqlServerBit(101, "col1", false);
MapTo("int");

await TestSingleTypeAsync(
tableName, col, colValue.ToString(), "integer");

await ValidateValueAsync(("public", tableName), colValue);
}

private void MapTo(string mapTo)
{
DummyFileSystem.AddFile(@"c:\mymappings.json", GetMappingFile(
$" \"bit\": \"{mapTo}\"\r\n"));
}
}
19 changes: 19 additions & 0 deletions src/CrossRDBMS.Tests/CopyFromMssToPg/CopyMssToPgBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,23 @@ protected void VerifyExpectedLength(NpgsqlDataReader reader, int? expectedLength
$"because the length should be {expectedLength.Value}");
}
}

protected static MockFileData GetMappingFile(string typeConversions)
{
return new MockFileData(
"{\r\n" +
" \"Schemas\": {\r\n" +
" \"\": \"public\",\r\n" +
" \"dbo\": \"public\",\r\n" +
" \"my_mss_schema\": \"my_pg_schema\"\r\n" +
" },\r\n" +
" \"Collations\": {\r\n" +
" \"SQL_Latin1_General_CP1_CI_AI\": \"en_ci_ai\",\r\n" +
" \"SQL_Latin1_General_CP1_CI_AS\": \"en_ci_as\"\r\n" +
" },\r\n" +
" \"ColumnTypes\": {\r\n" +
typeConversions +
" }\r\n" +
"}");
}
}

0 comments on commit c7023ce

Please sign in to comment.