-
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.
adds test suite for data-convert (#9)
- Loading branch information
1 parent
e8b5a43
commit d552f05
Showing
5 changed files
with
154 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace MsSqlCdc; | ||
|
||
public enum Operation : ushort | ||
public enum Operation | ||
{ | ||
Delete = 1, | ||
Insert = 2, | ||
|
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,105 @@ | ||
using Xunit; | ||
using FluentAssertions; | ||
using static FluentAssertions.FluentActions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Linq; | ||
using FluentAssertions.Execution; | ||
|
||
namespace MsSqlCdc.Tests; | ||
|
||
public class DataConverTest | ||
{ | ||
[Theory] | ||
[InlineData(25000L, 25002L, Operation.AfterUpdate, "ABB", 10, "Rune", 20000.00)] | ||
[InlineData(25L, 25202L, Operation.BeforeUpdate, "DSDFS", 2, "Simon", 0.00)] | ||
[InlineData(250000000L, 250021L, Operation.Delete, "DFS", 3, "Foo", 1000000000.00)] | ||
[InlineData(0L, 2L, Operation.Insert, "DFS", 3, "John", 1000000000.00)] | ||
public void ConvertCdcColumn_ShouldReturnChangeData_OnValidInput( | ||
long startLsn, | ||
long seqVal, | ||
Operation operation, | ||
string updateMask, | ||
int id, | ||
string name, | ||
double salary) | ||
{ | ||
var captureInstance = "dbo_Employee"; | ||
var columnFields = new List<Tuple<string, object>> | ||
{ | ||
new Tuple<string, object>("__$start_lsn", BitConverter.GetBytes(startLsn).Reverse().ToArray()), | ||
new Tuple<string, object>("__$seqval", BitConverter.GetBytes(seqVal).Reverse().ToArray()), | ||
new Tuple<string, object>("__$operation", (int)operation), | ||
new Tuple<string, object>("__$update_mask", Encoding.ASCII.GetBytes(updateMask)), | ||
new Tuple<string, object>("Id", id), | ||
new Tuple<string, object>("Name", name), | ||
new Tuple<string, object>("Salary", salary), | ||
}; | ||
|
||
var changeData = new ChangeData<dynamic>( | ||
startLsn, | ||
seqVal, | ||
operation, | ||
updateMask, | ||
"dbo_Employee", | ||
new | ||
{ | ||
Id = id, | ||
Name = name, | ||
Salary = salary, | ||
} | ||
); | ||
|
||
var result = DataConvert.ConvertCdcColumn(columnFields, captureInstance); | ||
|
||
using (var scope = new AssertionScope()) | ||
{ | ||
Assert.True(result.Body.Id == changeData.Body.Id); | ||
Assert.True(result.Body.Name == changeData.Body.Name); | ||
Assert.True(result.Body.Salary == changeData.Body.Salary); | ||
result.StartLineSequenceNumber.Should().Be(changeData.StartLineSequenceNumber); | ||
result.SequenceValue.Should().Be(changeData.SequenceValue); | ||
result.Operation.Should().Be(changeData.Operation); | ||
result.UpdateMask.Should().Be(changeData.UpdateMask); | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData(0)] | ||
[InlineData(1)] | ||
[InlineData(2)] | ||
[InlineData(3)] | ||
public void ConvertCdcColumn_ShouldThrowException_OnColumnFieldsBeingLessThanFour(int columnFieldsCount) | ||
{ | ||
var captureInstance = "dbo_Employee"; | ||
|
||
var columnFields = Enumerable.Range(0, columnFieldsCount) | ||
.Select(x => new Tuple<string, object>(x.ToString(), x)).ToList(); | ||
|
||
Invoking(() => DataConvert.ConvertCdcColumn(columnFields, captureInstance)).Should().Throw<Exception>(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1, Operation.Delete)] | ||
[InlineData(2, Operation.Insert)] | ||
[InlineData(3, Operation.BeforeUpdate)] | ||
[InlineData(4, Operation.AfterUpdate)] | ||
public void ConvertIntOperation_ShouldReturnCorrectEnumConvertion(int input, Operation expected) | ||
{ | ||
var operation = DataConvert.ConvertIntOperation(input); | ||
operation.Should().Be(expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-1)] | ||
[InlineData(-10)] | ||
[InlineData(0)] | ||
[InlineData(100)] | ||
[InlineData(int.MinValue)] | ||
[InlineData(int.MaxValue)] | ||
public void ConvertIntOperation_ShouldThrowException_OnInvalidIntRepresentation(int input) | ||
{ | ||
Invoking(() => DataConvert.ConvertIntOperation(input)).Should().Throw<ArgumentException>(); | ||
} | ||
} |
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,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.2.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\MsSqlCdc\MsSqlCdc.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |