我正在尝试测试传递到数据库的Dictionary的值。我要确保已考虑所有参数。由于某些原因,唯一通过的测试来自字符串数据类型。
(断言使用的是最小起订量)
课程数据
private class SaveData : IEnumerable<object[]> {
public IEnumerator<object[]> GetEnumerator() {
yield return new object[]{ "EventId", 7};
yield return new object[]{ "LineNumber", 1};
yield return new object[]{ "ItemNumber", 2 };
yield return new object[]{ "ItemDescription", "Fake Item Description" };
yield return new object[]{ "Quantity", 3 };
yield return new object[]{ "Price", 9.99m };
yield return new object[]{ "CreateDateTime", new DateTime(2019, 5, 1, 11, 45, 0) };
yield return new object[]{ "PaymentTransaction", "Fake Payment Transaction" };
yield return new object[]{ "PaymentDateTime", new DateTime(2019, 5, 1, 11, 45, 0) };
yield return new object[]{ "PaymentAmount", 199.98m };
yield return new object[]{ "IsAdjustment", true };
yield return new object[]{ "OrderDetailTypeId", 3 };
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
单元测试
[Theory]
[ClassData(typeof(SaveData))]
public void EveryCall_HasTheExpectedValue(string key, object value) {
// arrange
var db = MockDatabaseRepository();
var repo = MakeRepo(dbRepo: db.Object);
var model = MakeModel();
var guid = GOOD_GUID;
// act
repo.SaveOrderDetail(guid, model)
.GetAwaiter()
.GetResult();
// assert
db.Verify(r => r.ExecuteCommandAsync(It.IsAny<string>(),
It.Is<Dictionary<string, object>>(parms => parms[key] == value)),
Times.Once);
}