You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some code that is calling into a COM library in which arrays are passed by reference. Our internal API which requires testing takes in an object and is responsible for creating the array which is passed in by reference. I am trying to test that our function given an object calls the COM API with the appropriate values. I can do this for any argument which is not passed by ref, but can not do the same for ref arguments. The problem is that in my test method I cannot create the array in which to test as this is compared by reference and is therefore not the same as the array generated by our API.
I'm thinking of something which is similar to It.Is(Func<T, bool> predicate) for It.Ref. My understanding is that moq checks whether the argument is ref and if the verify method is It.Ref.IsAny is used for comparison then treats it as a special case otherwise it requires a constant value.
The problem
publicstaticintMyMethodToTest(COMLibrarylib,MyObjectobj){varvalues= obj.ToArray();return lib.Function(ref values);}[Fact]publicvoidMyTest(){// ArrangevarcomLib=newMock<COMLibrary>();varobj= MyObject();varexpected=new[]{0}// Act
MyMethodToTest(obj);// Assert
comLib.Verify(f => f.Function(ref expected), Times.Once);// Fails as expected is not equal by reference}
Suggestion
Either
a) when a ref argument uses It and It defines the compare predicate the RefMatcher should match with the predicate
b) same but use It.Ref with a predicate, which may be more inline with how ref agruments are treated in other scenarios (i.e. it's expected that If.Ref is used in combination wtih ref arguments
The text was updated successfully, but these errors were encountered:
I would like to see this enhancement as well. The new version of Autofac uses in parameters and we mock some Autofac functions in our tests where we can now only use It.Ref<>.IsAny, but we would like to use It.Ref<>.Is(p => p.Name == "Test") to support multiple setups with different results.
Due to lack of recent activity, this issue has been labeled as 'stale'.
It will be closed if no further activity occurs within 30 more days.
Any new comment will remove the label.
I have some code that is calling into a COM library in which arrays are passed by reference. Our internal API which requires testing takes in an object and is responsible for creating the array which is passed in by reference. I am trying to test that our function given an object calls the COM API with the appropriate values. I can do this for any argument which is not passed by ref, but can not do the same for ref arguments. The problem is that in my test method I cannot create the array in which to test as this is compared by reference and is therefore not the same as the array generated by our API.
I'm thinking of something which is similar to It.Is(Func<T, bool> predicate) for It.Ref. My understanding is that moq checks whether the argument is ref and if the verify method is It.Ref.IsAny is used for comparison then treats it as a special case otherwise it requires a constant value.
The problem
Suggestion
Either
a) when a ref argument uses It and It defines the compare predicate the RefMatcher should match with the predicate
b) same but use It.Ref with a predicate, which may be more inline with how ref agruments are treated in other scenarios (i.e. it's expected that If.Ref is used in combination wtih ref arguments
The text was updated successfully, but these errors were encountered: