如何为私有函数的输出参数创建单元测试?
我的服务层:
private int LoadProduct(string productId, out IProduct product)
{
product = this.Load(productId);
return ErrorCodes.Success;
}
测试用例:
[Test]
public void LoadProductTest()
{
var offerService = new OfferProcessor();
var privateOfferService = new PrivateObject(offerService);
IProduct myProduct = null;
var result = (int)privateOfferService.Invoke("LoadProduct",
new object[] {"AnId", myProduct });
Assert.That(result, Is.EqualTo(ErrorCodes.Success));
Assert.That(myProduct, Is.NotNull());
}
上面的测试用例无法编译。如何传递 Invoke 一个 out 参数,然后在调用后访问它?