我计划使用Moq对我的Azure服务面向单元测试的应用程序进行测试。 我在这里看到了一些示例 https://github.com/Azure-Samples/service-fabric-dotnet-web-reference-app/blob/master/ReferenceApp/Inventory.UnitTests/InventoryServiceTests.cs 。我看到的测试似乎实际上是写入可靠字典,而不是模拟。 有没有办法模拟从可靠字典中添加/删除?如何对类似下面的内容进行单元测试?
public async Task<bool> AddItem(MyItem item)
{
var items = await StateManager.GetOrAddAsync<IReliableDictionary<int, MyItem>>("itemDict");
using (ITransaction tx = this.StateManager.CreateTransaction())
{
await items.AddAsync(tx, item.Id, item);
await tx.CommitAsync();
}
return true;
}
IReliableStateManagerReplica
添加到我的服务构造函数的情况下完成这个操作?我是否可以将一些数据添加到StatefulServiceContext
中?基本上,EntryPoints.CreateReliableStateManager(context)
期望在StatefulServiceContext
中包含什么内容? - Philip Pittle