我正在使用Moq对单元课程进行单元测试。如何设置模拟的IProcessor以将CreateRequest参数上的成功属性设置为true?这有可能吗?我已经看过Moq框架提供的Callback功能,但不确定在这种情况下它能否满足我的需求。
Marker drMark=mMap.addMarker(new MarkerOptions().position(drLoc).title("Lahore").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Marker selfMark=mMap.addMarker(new MarkerOptions().position(curLocation).title("Lahore").icon(BitmapDescriptorFactory.fromResource(R.drawable.passengermarker)));
答案 0 :(得分:1)
您可以尝试
mock.Setup(x=>x.Process(It.IsAny<CreateRequest>()))
.Callback<CreateRequest>(cr => cr.Successful = true)
答案 1 :(得分:1)
使用回调并获得对传递的参数的访问权限
[TestMethod]
public void TheUnitTest() {
//Arrange
Mock<IProcessor> mock = new Mock<IProcessor>();
mock.Setup(_ => _.Process(It.IsAny<CreateRequest>()))
.Callback((CreateRequest arg) => arg.Successful = true)
.Verifiable();
var subject = new TheClassIAmUnitTesting(mock.Object);
//Act
subject.SomeMethod();
//Assert
mock.VerifyAll();
}