I would like to verify that the parameter idStatus
is assigned to the myObj
instance. How can I do this with NSubstitute? I thought that if I somehow could verify the parameter to UpdateObject
this would be a good test of the method, but not sure how to do this. Any thoughts?
public void SetObjectStatus(int id, int? idStatus)
{
var myObj = GetObject(id);
myObj.IdStatus = idStatus;
UpdateObject(myObj);
}
[TestMethod]
public void SetObjectStatus_Verify()
{
//Arrange
int id = 1;
int? newStatus = 10;
//Act
test.SetObjectStatus(id, newStatus);
//Assert
//?? I would like to check that myObj.IdStatus equals newStatus (10).
}
It depends whether you want to test the internals ( white box testing ) or just the result ( black box testing ).
For the first: does your code give you the flexibility that GetObject(id)
can be set up so that it actually returns a mock? If so, you can set up a mock with var mock = Substitute.For<IYourObject>()
and call mock.Received().IdStatus
( see here ).
For the second: you need to call GetObject(id)
within your test method and see whether the expected value is present.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.