Skip to content

Commit caa9e0f

Browse files
blehnenclaude
andcommitted
test: repoint relational unit tests to new read/purge semantics
The initial commit removed the EnableHistory guard from the relational read/purge handlers but missed four unit tests in DotNetWorkQueue.Transport.RelationalDatabase.Tests that still asserted the old behavior ("factory.DidNotReceive().Create()" when EnableHistory=false). Convert them to assert the new behavior: when the history table does not exist (simulated via DbException), the handlers return empty / null / 0 gracefully. - Get_When_Disabled_Returns_Empty_List -> Get_When_History_Table_Missing_Returns_Empty_List - GetByQueueId_When_Disabled_Returns_Null -> GetByQueueId_When_History_Table_Missing_Returns_Null - GetCount_When_Disabled_Returns_Zero -> GetCount_When_History_Table_Missing_Returns_Zero - Purge_When_Disabled_Returns_Zero -> Purge_When_History_Table_Missing_Returns_Zero 216/216 tests pass locally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d991b3c commit caa9e0f

2 files changed

Lines changed: 43 additions & 12 deletions

File tree

Source/DotNetWorkQueue.Transport.RelationalDatabase.Tests/Basic/PurgeMessageHistoryHandlerTests.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Data;
3+
using System.Data.Common;
34
using DotNetWorkQueue.Transport.RelationalDatabase.Basic;
45
using Microsoft.VisualStudio.TestTools.UnitTesting;
56
using NSubstitute;
@@ -10,12 +11,18 @@ namespace DotNetWorkQueue.Transport.RelationalDatabase.Tests.Basic
1011
public class PurgeMessageHistoryHandlerTests
1112
{
1213
[TestMethod]
13-
public void Purge_When_Disabled_Returns_Zero()
14+
public void Purge_When_History_Table_Missing_Returns_Zero()
1415
{
15-
var (handler, factory, _) = Create(enabled: false);
16+
// After the EnableHistory read-path guard was removed, Purge relies on a
17+
// DbException catch to handle the case where the history table was never
18+
// created. Simulate that with a thrown DbException from ExecuteNonQuery.
19+
var (handler, factory, _) = Create(enabled: true);
20+
var (_, command) = SetupConnection(factory);
21+
command.When(c => c.ExecuteNonQuery()).Do(_ => throw new FakeDbException());
22+
1623
var result = handler.Purge(DateTime.UtcNow.AddDays(-30));
24+
1725
Assert.AreEqual(0L, result);
18-
factory.DidNotReceive().Create();
1926
}
2027

2128
[TestMethod]
@@ -68,5 +75,10 @@ private static (IDbConnection connection, IDbCommand command) SetupConnection(ID
6875
factory.Create().Returns(connection);
6976
return (connection, command);
7077
}
78+
79+
private sealed class FakeDbException : DbException
80+
{
81+
public FakeDbException() : base("simulated: history table does not exist") { }
82+
}
7183
}
7284
}

Source/DotNetWorkQueue.Transport.RelationalDatabase.Tests/Basic/QueryMessageHistoryHandlerTests.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Data;
2+
using System.Data.Common;
23
using DotNetWorkQueue.Configuration;
34
using DotNetWorkQueue.Transport.RelationalDatabase.Basic;
45
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -9,31 +10,44 @@ namespace DotNetWorkQueue.Transport.RelationalDatabase.Tests.Basic
910
[TestClass]
1011
public class QueryMessageHistoryHandlerTests
1112
{
13+
// After the EnableHistory read-path guard was removed, these methods rely on a
14+
// DbException catch to handle the case where the history table was never created.
15+
// We simulate that by throwing DbException from ExecuteReader / ExecuteScalar.
16+
1217
[TestMethod]
13-
public void Get_When_Disabled_Returns_Empty_List()
18+
public void Get_When_History_Table_Missing_Returns_Empty_List()
1419
{
15-
var (handler, factory, _) = Create(enabled: false);
20+
var (handler, factory, _) = Create(enabled: true);
21+
var (_, command) = SetupConnection(factory);
22+
command.When(c => c.ExecuteReader()).Do(_ => throw new FakeDbException());
23+
1624
var result = handler.Get(0, 10, null);
25+
1726
Assert.AreEqual(0, result.Count);
18-
factory.DidNotReceive().Create();
1927
}
2028

2129
[TestMethod]
22-
public void GetByQueueId_When_Disabled_Returns_Null()
30+
public void GetByQueueId_When_History_Table_Missing_Returns_Null()
2331
{
24-
var (handler, factory, _) = Create(enabled: false);
32+
var (handler, factory, _) = Create(enabled: true);
33+
var (_, command) = SetupConnection(factory);
34+
command.When(c => c.ExecuteReader()).Do(_ => throw new FakeDbException());
35+
2536
var result = handler.GetByQueueId("q1");
37+
2638
Assert.IsNull(result);
27-
factory.DidNotReceive().Create();
2839
}
2940

3041
[TestMethod]
31-
public void GetCount_When_Disabled_Returns_Zero()
42+
public void GetCount_When_History_Table_Missing_Returns_Zero()
3243
{
33-
var (handler, factory, _) = Create(enabled: false);
44+
var (handler, factory, _) = Create(enabled: true);
45+
var (_, command) = SetupConnection(factory);
46+
command.When(c => c.ExecuteScalar()).Do(_ => throw new FakeDbException());
47+
3448
var result = handler.GetCount(null);
49+
3550
Assert.AreEqual(0L, result);
36-
factory.DidNotReceive().Create();
3751
}
3852

3953
[TestMethod]
@@ -122,5 +136,10 @@ private static (IDbConnection connection, IDbCommand command) SetupConnection(ID
122136
factory.Create().Returns(connection);
123137
return (connection, command);
124138
}
139+
140+
private sealed class FakeDbException : DbException
141+
{
142+
public FakeDbException() : base("simulated: history table does not exist") { }
143+
}
125144
}
126145
}

0 commit comments

Comments
 (0)