-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
9 changed files
with
278 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
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,22 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace FluentCommand.Entities; | ||
|
||
[Table("member_user", Schema = "dbo")] | ||
public class Member | ||
{ | ||
[Column("Id")] | ||
public Guid Id { get; set; } | ||
|
||
[Column("email_address")] | ||
public string EmailAddress { get; set; } | ||
|
||
[Column("display_name")] | ||
public string DisplayName { get; set; } | ||
|
||
[Column("first_name")] | ||
public string FirstName { get; set; } | ||
|
||
[Column("last_name")] | ||
public string LastName { get; 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 |
---|---|---|
|
@@ -61,7 +61,7 @@ public void QuoteIdentifier() | |
} | ||
|
||
[Fact] | ||
public void BuildMergeTests() | ||
public async System.Threading.Tasks.Task BuildMergeTests() | ||
{ | ||
var definition = new DataMergeDefinition(); | ||
|
||
|
@@ -79,13 +79,15 @@ public void BuildMergeTests() | |
var sql = DataMergeGenerator.BuildMerge(definition); | ||
sql.Should().NotBeNullOrEmpty(); | ||
|
||
Output.WriteLine("MergeStatement:"); | ||
Output.WriteLine(sql); | ||
await Verifier | ||
.Verify(sql) | ||
.UseDirectory("Snapshots") | ||
.AddScrubber(scrubber => scrubber.Replace(definition.TemporaryTable, "#MergeTable")); | ||
} | ||
|
||
|
||
[Fact] | ||
public void BuildMergeDataTests() | ||
public async System.Threading.Tasks.Task BuildMergeDataTests() | ||
{ | ||
var definition = new DataMergeDefinition(); | ||
|
||
|
@@ -123,8 +125,9 @@ public void BuildMergeDataTests() | |
var sql = DataMergeGenerator.BuildMerge(definition, listDataReader); | ||
sql.Should().NotBeNullOrEmpty(); | ||
|
||
Output.WriteLine("MergeStatement:"); | ||
Output.WriteLine(sql); | ||
await Verifier | ||
.Verify(sql) | ||
.UseDirectory("Snapshots"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -248,7 +251,7 @@ await Verifier | |
} | ||
|
||
[Fact] | ||
public void BuildMergeDataOutputTests() | ||
public async System.Threading.Tasks.Task BuildMergeDataOutputTests() | ||
{ | ||
var definition = new DataMergeDefinition(); | ||
|
||
|
@@ -282,7 +285,7 @@ public void BuildMergeDataOutputTests() | |
}, | ||
new UserImport | ||
{ | ||
EmailAddress = $"random.{DateTime.Now.Ticks}@email.com", | ||
EmailAddress = $"[email protected]", | ||
DisplayName = "Random User", | ||
FirstName = "Random", | ||
LastName = "User" | ||
|
@@ -294,8 +297,57 @@ public void BuildMergeDataOutputTests() | |
var sql = DataMergeGenerator.BuildMerge(definition, dataTable); | ||
sql.Should().NotBeNullOrEmpty(); | ||
|
||
Output.WriteLine("MergeStatement:"); | ||
Output.WriteLine(sql); | ||
await Verifier | ||
.Verify(sql) | ||
.UseDirectory("Snapshots"); | ||
} | ||
|
||
[Fact] | ||
public async System.Threading.Tasks.Task BuildMergeDataMismatchTests() | ||
{ | ||
var definition = new DataMergeDefinition(); | ||
|
||
DataMergeDefinition.AutoMap<Member>(definition); | ||
definition.Columns.Should().NotBeNullOrEmpty(); | ||
|
||
var column = definition.Columns.Find(c => c.SourceColumn == "email_address"); | ||
column.Should().NotBeNull(); | ||
|
||
column.IsKey = true; | ||
column.CanUpdate = false; | ||
|
||
var users = new List<Member> | ||
{ | ||
new Member | ||
{ | ||
EmailAddress = "[email protected]", | ||
DisplayName = "Test User", | ||
FirstName = "Test", | ||
LastName = "User" | ||
}, | ||
new Member | ||
{ | ||
EmailAddress = "[email protected]", | ||
DisplayName = "Blah User", | ||
FirstName = "Blah", | ||
LastName = "User" | ||
}, | ||
new Member | ||
{ | ||
EmailAddress = $"[email protected]", | ||
DisplayName = "Random User", | ||
FirstName = "Random", | ||
LastName = "User" | ||
} | ||
}; | ||
|
||
var dataTable = new ListDataReader<Member>(users); | ||
|
||
var mergeDataStatement = DataMergeGenerator.BuildMerge(definition, dataTable); | ||
mergeDataStatement.Should().NotBeNullOrEmpty(); | ||
|
||
await Verifier | ||
.Verify(mergeDataStatement) | ||
.UseDirectory("Snapshots"); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...qlServer.Tests/Snapshots/DataMergeGeneratorTests.BuildMergeDataMismatchTests.verified.txt
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,40 @@ | ||
MERGE INTO [dbo].[member_user] AS t | ||
USING | ||
( | ||
VALUES | ||
('00000000-0000-0000-0000-000000000000', '[email protected]', 'Test User', 'Test', 'User'), | ||
('00000000-0000-0000-0000-000000000000', '[email protected]', 'Blah User', 'Blah', 'User'), | ||
('00000000-0000-0000-0000-000000000000', '[email protected]', 'Random User', 'Random', 'User') | ||
) | ||
AS s | ||
( | ||
[Id], [email_address], [display_name], [first_name], [last_name] | ||
) | ||
ON | ||
( | ||
t.[email_address] = s.[email_address] | ||
) | ||
WHEN NOT MATCHED BY TARGET THEN | ||
INSERT | ||
( | ||
[Id], | ||
[email_address], | ||
[display_name], | ||
[first_name], | ||
[last_name] | ||
) | ||
VALUES | ||
( | ||
s.[Id], | ||
s.[email_address], | ||
s.[display_name], | ||
s.[first_name], | ||
s.[last_name] | ||
) | ||
WHEN MATCHED THEN | ||
UPDATE SET | ||
t.[Id] = s.[Id], | ||
t.[display_name] = s.[display_name], | ||
t.[first_name] = s.[first_name], | ||
t.[last_name] = s.[last_name] | ||
; |
56 changes: 56 additions & 0 deletions
56
....SqlServer.Tests/Snapshots/DataMergeGeneratorTests.BuildMergeDataOutputTests.verified.txt
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,56 @@ | ||
MERGE INTO [dbo].[User] AS t | ||
USING | ||
( | ||
VALUES | ||
('[email protected]', 'Test User', 'Test', 'User', NULL, NULL), | ||
('[email protected]', 'Blah User', 'Blah', 'User', NULL, NULL), | ||
('[email protected]', 'Random User', 'Random', 'User', NULL, NULL) | ||
) | ||
AS s | ||
( | ||
[EmailAddress], [DisplayName], [FirstName], [LastName], [LockoutEnd], [LastLogin] | ||
) | ||
ON | ||
( | ||
t.[EmailAddress] = s.[EmailAddress] | ||
) | ||
WHEN NOT MATCHED BY TARGET THEN | ||
INSERT | ||
( | ||
[EmailAddress], | ||
[DisplayName], | ||
[FirstName], | ||
[LastName], | ||
[LockoutEnd], | ||
[LastLogin] | ||
) | ||
VALUES | ||
( | ||
s.[EmailAddress], | ||
s.[DisplayName], | ||
s.[FirstName], | ||
s.[LastName], | ||
s.[LockoutEnd], | ||
s.[LastLogin] | ||
) | ||
WHEN MATCHED THEN | ||
UPDATE SET | ||
t.[DisplayName] = s.[DisplayName], | ||
t.[FirstName] = s.[FirstName], | ||
t.[LastName] = s.[LastName], | ||
t.[LockoutEnd] = s.[LockoutEnd], | ||
t.[LastLogin] = s.[LastLogin] | ||
OUTPUT | ||
$action as [Action], | ||
DELETED.[EmailAddress] as [OriginalEmailAddress], | ||
INSERTED.[EmailAddress] as [CurrentEmailAddress], | ||
DELETED.[DisplayName] as [OriginalDisplayName], | ||
INSERTED.[DisplayName] as [CurrentDisplayName], | ||
DELETED.[FirstName] as [OriginalFirstName], | ||
INSERTED.[FirstName] as [CurrentFirstName], | ||
DELETED.[LastName] as [OriginalLastName], | ||
INSERTED.[LastName] as [CurrentLastName], | ||
DELETED.[LockoutEnd] as [OriginalLockoutEnd], | ||
INSERTED.[LockoutEnd] as [CurrentLockoutEnd], | ||
DELETED.[LastLogin] as [OriginalLastLogin], | ||
INSERTED.[LastLogin] as [CurrentLastLogin]; |
42 changes: 42 additions & 0 deletions
42
...ommand.SqlServer.Tests/Snapshots/DataMergeGeneratorTests.BuildMergeDataTests.verified.txt
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,42 @@ | ||
MERGE INTO [dbo].[User] AS t | ||
USING | ||
( | ||
VALUES | ||
('[email protected]', 'Test User', 'Test', 'User', NULL, NULL), | ||
('[email protected]', 'Blah User', 'Blah', 'User', NULL, NULL) | ||
) | ||
AS s | ||
( | ||
[EmailAddress], [DisplayName], [FirstName], [LastName], [LockoutEnd], [LastLogin] | ||
) | ||
ON | ||
( | ||
t.[EmailAddress] = s.[EmailAddress] | ||
) | ||
WHEN NOT MATCHED BY TARGET THEN | ||
INSERT | ||
( | ||
[EmailAddress], | ||
[DisplayName], | ||
[FirstName], | ||
[LastName], | ||
[LockoutEnd], | ||
[LastLogin] | ||
) | ||
VALUES | ||
( | ||
s.[EmailAddress], | ||
s.[DisplayName], | ||
s.[FirstName], | ||
s.[LastName], | ||
s.[LockoutEnd], | ||
s.[LastLogin] | ||
) | ||
WHEN MATCHED THEN | ||
UPDATE SET | ||
t.[DisplayName] = s.[DisplayName], | ||
t.[FirstName] = s.[FirstName], | ||
t.[LastName] = s.[LastName], | ||
t.[LockoutEnd] = s.[LockoutEnd], | ||
t.[LastLogin] = s.[LastLogin] | ||
; |
44 changes: 44 additions & 0 deletions
44
...entCommand.SqlServer.Tests/Snapshots/DataMergeGeneratorTests.BuildMergeTests.verified.txt
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,44 @@ | ||
MERGE INTO [dbo].[User] AS t | ||
USING | ||
( | ||
SELECT | ||
[EmailAddress], | ||
[DisplayName], | ||
[FirstName], | ||
[LastName], | ||
[LockoutEnd], | ||
[LastLogin] | ||
FROM [#MergeTable] | ||
) | ||
AS s | ||
ON | ||
( | ||
t.[EmailAddress] = s.[EmailAddress] | ||
) | ||
WHEN NOT MATCHED BY TARGET THEN | ||
INSERT | ||
( | ||
[EmailAddress], | ||
[DisplayName], | ||
[FirstName], | ||
[LastName], | ||
[LockoutEnd], | ||
[LastLogin] | ||
) | ||
VALUES | ||
( | ||
s.[EmailAddress], | ||
s.[DisplayName], | ||
s.[FirstName], | ||
s.[LastName], | ||
s.[LockoutEnd], | ||
s.[LastLogin] | ||
) | ||
WHEN MATCHED THEN | ||
UPDATE SET | ||
t.[DisplayName] = s.[DisplayName], | ||
t.[FirstName] = s.[FirstName], | ||
t.[LastName] = s.[LastName], | ||
t.[LockoutEnd] = s.[LockoutEnd], | ||
t.[LastLogin] = s.[LastLogin] | ||
; |