Skip to content

Commit

Permalink
cleaner assertion statements for get all (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen authored Jan 16, 2022
1 parent f7c08a7 commit 051c267
Showing 1 changed file with 61 additions and 56 deletions.
117 changes: 61 additions & 56 deletions test/MsSqlCdc.Tests/CdcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,37 @@ public async Task Get_all_changes_rowfilter_all()
var minLsn = await Cdc.GetMinLsn(connection, captureInstance);
var maxLsn = await Cdc.GetMaxLsn(connection);

var netChanges = (await Cdc.GetAllChanges(
var netChanges = await Cdc.GetAllChanges(
connection,
captureInstance,
minLsn,
maxLsn,
AllChangesRowFilterOption.All)).ToArray();

var insert = netChanges[0];
var afterUpdate = netChanges[1];

using (var scope = new AssertionScope())
{
netChanges.Length.Should().Be(2);
insert.CaptureInstance.Should().Be(captureInstance);
insert.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
insert.SequenceValue.Should().BeGreaterThan(default(BigInteger));
insert.Operation.Should().Be(Operation.Insert);
insert.Fields["id"].Should().NotBeNull();
insert.Fields["first_name"].Should().Be("Rune");
insert.Fields["last_name"].Should().Be("Nielsen");

afterUpdate.CaptureInstance.Should().Be(captureInstance);
afterUpdate.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
afterUpdate.SequenceValue.Should().BeGreaterThan(default(BigInteger));
afterUpdate.Operation.Should().Be(Operation.AfterUpdate);
afterUpdate.Fields["id"].Should().NotBeNull();
afterUpdate.Fields["first_name"].Should().Be("Rune");
afterUpdate.Fields["last_name"].Should().Be("Jensen");
}
AllChangesRowFilterOption.All);

netChanges
.Should()
.HaveCount(2).And
.SatisfyRespectively(
insert =>
{
insert.CaptureInstance.Should().Be(captureInstance);
insert.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
insert.SequenceValue.Should().BeGreaterThan(default(BigInteger));
insert.Operation.Should().Be(Operation.Insert);
insert.Fields["id"].Should().NotBeNull();
insert.Fields["first_name"].Should().Be("Rune");
insert.Fields["last_name"].Should().Be("Nielsen");
},
afterUpdate =>
{
afterUpdate.CaptureInstance.Should().Be(captureInstance);
afterUpdate.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
afterUpdate.SequenceValue.Should().BeGreaterThan(default(BigInteger));
afterUpdate.Operation.Should().Be(Operation.AfterUpdate);
afterUpdate.Fields["id"].Should().NotBeNull();
afterUpdate.Fields["first_name"].Should().Be("Rune");
afterUpdate.Fields["last_name"].Should().Be("Jensen");
});
}

[Fact]
Expand All @@ -160,37 +162,40 @@ public async Task Get_all_changes_rowfilter_all_update_old()
maxLsn,
AllChangesRowFilterOption.AllUpdateOld)).ToArray();

var insert = netChanges[0];
var beforeUpdate = netChanges[1];
var afterUpdate = netChanges[2];

using (var scope = new AssertionScope())
{
netChanges.Length.Should().Be(3);
insert.CaptureInstance.Should().Be(captureInstance);
insert.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
insert.SequenceValue.Should().BeGreaterThan(default(BigInteger));
insert.Operation.Should().Be(Operation.Insert);
insert.Fields["id"].Should().NotBeNull();
insert.Fields["first_name"].Should().Be("Rune");
insert.Fields["last_name"].Should().Be("Nielsen");

beforeUpdate.CaptureInstance.Should().Be(captureInstance);
beforeUpdate.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
beforeUpdate.SequenceValue.Should().BeGreaterThan(default(BigInteger));
beforeUpdate.Operation.Should().Be(Operation.BeforeUpdate);
beforeUpdate.Fields["id"].Should().NotBeNull();
beforeUpdate.Fields["first_name"].Should().Be("Rune");
beforeUpdate.Fields["last_name"].Should().Be("Nielsen");

afterUpdate.CaptureInstance.Should().Be(captureInstance);
afterUpdate.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
afterUpdate.SequenceValue.Should().BeGreaterThan(default(BigInteger));
afterUpdate.Operation.Should().Be(Operation.AfterUpdate);
afterUpdate.Fields["id"].Should().NotBeNull();
afterUpdate.Fields["first_name"].Should().Be("Rune");
afterUpdate.Fields["last_name"].Should().Be("Jensen");
}
netChanges
.Should()
.HaveCount(3).And
.SatisfyRespectively(
insert =>
{
insert.CaptureInstance.Should().Be(captureInstance);
insert.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
insert.SequenceValue.Should().BeGreaterThan(default(BigInteger));
insert.Operation.Should().Be(Operation.Insert);
insert.Fields["id"].Should().NotBeNull();
insert.Fields["first_name"].Should().Be("Rune");
insert.Fields["last_name"].Should().Be("Nielsen");
},
beforeUpdate =>
{
beforeUpdate.CaptureInstance.Should().Be(captureInstance);
beforeUpdate.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
beforeUpdate.SequenceValue.Should().BeGreaterThan(default(BigInteger));
beforeUpdate.Operation.Should().Be(Operation.BeforeUpdate);
beforeUpdate.Fields["id"].Should().NotBeNull();
beforeUpdate.Fields["first_name"].Should().Be("Rune");
beforeUpdate.Fields["last_name"].Should().Be("Nielsen");
},
afterUpdate =>
{
afterUpdate.CaptureInstance.Should().Be(captureInstance);
afterUpdate.StartLineSequenceNumber.Should().BeGreaterThan(default(BigInteger));
afterUpdate.SequenceValue.Should().BeGreaterThan(default(BigInteger));
afterUpdate.Operation.Should().Be(Operation.AfterUpdate);
afterUpdate.Fields["id"].Should().NotBeNull();
afterUpdate.Fields["first_name"].Should().Be("Rune");
afterUpdate.Fields["last_name"].Should().Be("Jensen");
});
}

private async Task<SqlConnection> CreateOpenSqlConnection()
Expand Down

0 comments on commit 051c267

Please sign in to comment.