Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Issue #60 TargetTable Initial Commit * Issue #60 Add GetFullQualifiedTableName * Issue #60 Add Test for scenario no schema set * Issue #60 Cleanup The TargetTable / TargetColumn setters are now protected for internal use only. The Columns are now a IReadOnlyList, so they cannot be changed in further control flows. * Issue #60 Add ClrType to TargetTable * Issue #60 Rename to GetFullQualified... to GetFullyQualified * Issue #60 Update to 2.6.3 * Add Changelog * Issue #60 Add nupg Binaries * Update Changelog for 2.6.2 Release Notes
- Loading branch information
Showing
11 changed files
with
198 additions
and
12 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
Binary file not shown.
Binary file not shown.
101 changes: 101 additions & 0 deletions
101
src/PostgreSQLCopyHelper.Test/Issues/Issue60_TargetTableTest.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,101 @@ | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using NpgsqlTypes; | ||
using NUnit.Framework; | ||
|
||
namespace PostgreSQLCopyHelper.Test.Issues | ||
{ | ||
[TestFixture] | ||
public class Issue60_TargetTableTest | ||
{ | ||
private class User | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
} | ||
|
||
[Test] | ||
public void Test_TargetTable_ColumnsEmpty() | ||
{ | ||
var subject = new PostgreSQLCopyHelper<User>("sample", "TestUsers"); | ||
|
||
var targetTable = subject.TargetTable; | ||
|
||
Assert.AreEqual("sample", targetTable.SchemaName); | ||
Assert.AreEqual("TestUsers", targetTable.TableName); | ||
|
||
Assert.AreEqual(0, targetTable.Columns.Count); | ||
} | ||
|
||
[Test] | ||
public void Test_TargetTable_SchemaEmpty_ColumnsEmpty() | ||
{ | ||
var subject = new PostgreSQLCopyHelper<User>("TestUsers"); | ||
|
||
var targetTable = subject.TargetTable; | ||
|
||
Assert.AreEqual(string.Empty, targetTable.SchemaName); | ||
Assert.AreEqual("TestUsers", targetTable.TableName); | ||
|
||
Assert.AreEqual(0, targetTable.Columns.Count); | ||
} | ||
|
||
[Test] | ||
public void Test_TargetTable_NotEmpty() | ||
{ | ||
var subject = new PostgreSQLCopyHelper<User>("sample", "TestUsers") | ||
.MapInteger("Id", x => x.Id) | ||
.MapText("Name", x => x.Name); | ||
|
||
var targetTable = subject.TargetTable; | ||
|
||
Assert.AreEqual("sample", targetTable.SchemaName); | ||
Assert.AreEqual("TestUsers", targetTable.TableName); | ||
|
||
Assert.AreEqual(2, targetTable.Columns.Count); | ||
|
||
Assert.AreEqual("Id", targetTable.Columns[0].ColumnName); | ||
Assert.AreEqual(typeof(int), targetTable.Columns[0].ClrType); | ||
Assert.AreEqual(NpgsqlDbType.Integer, targetTable.Columns[0].DbType); | ||
|
||
Assert.AreEqual("Name", targetTable.Columns[1].ColumnName); | ||
Assert.AreEqual(typeof(string), targetTable.Columns[1].ClrType); | ||
Assert.AreEqual(NpgsqlDbType.Text, targetTable.Columns[1].DbType); | ||
} | ||
|
||
[Test] | ||
public void Test_TargetTable_FullQualifiedTableName_NoPostgresQuoting() | ||
{ | ||
var subject = new PostgreSQLCopyHelper<User>("sample", "TestUsers") | ||
.UsePostgresQuoting(false); | ||
|
||
var targetTable = subject.TargetTable; | ||
|
||
Assert.AreEqual("sample.TestUsers", targetTable.GetFullyQualifiedTableName()); | ||
} | ||
|
||
[Test] | ||
public void Test_TargetTable_FullQualifiedTableName_WithPostgresQuoting() | ||
{ | ||
var subject = new PostgreSQLCopyHelper<User>("Sample", "TestUsers") | ||
.UsePostgresQuoting(); | ||
|
||
var targetTable = subject.TargetTable; | ||
|
||
Assert.AreEqual("\"Sample\".\"TestUsers\"", targetTable.GetFullyQualifiedTableName()); | ||
} | ||
|
||
|
||
[Test] | ||
public void Test_TargetTable_FullQualifiedTableName_WithPostgresQuoting_NoSchema() | ||
{ | ||
var subject = new PostgreSQLCopyHelper<User>("TestUsers") | ||
.UsePostgresQuoting(); | ||
|
||
var targetTable = subject.TargetTable; | ||
|
||
Assert.AreEqual("\"TestUsers\"", targetTable.GetFullyQualifiedTableName()); | ||
} | ||
} | ||
} |
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,16 @@ | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using NpgsqlTypes; | ||
|
||
namespace PostgreSQLCopyHelper.Model | ||
{ | ||
public class TargetColumn | ||
{ | ||
public string ColumnName { get; internal set; } | ||
|
||
public Type ClrType { get; internal set; } | ||
|
||
public NpgsqlDbType DbType { get; internal set; } | ||
} | ||
} |
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,23 @@ | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
using PostgreSQLCopyHelper.Utils; | ||
|
||
namespace PostgreSQLCopyHelper.Model | ||
{ | ||
public class TargetTable | ||
{ | ||
public string SchemaName { get; internal set; } | ||
|
||
public string TableName { get; internal set; } | ||
|
||
public bool UsePostgresQuoting { get; internal set; } | ||
|
||
public IReadOnlyList<TargetColumn> Columns { get; internal set; } | ||
|
||
public string GetFullyQualifiedTableName() | ||
{ | ||
return NpgsqlUtils.GetFullyQualifiedTableName(SchemaName, TableName, UsePostgresQuoting); | ||
} | ||
} | ||
} |
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