This is a migrated thread and some comments may be shown as answers.

Arg.Any<Nullable<T>> and Arg.Any<T?> throws a null argument exception

2 Answers 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Imaji
Top achievements
Rank 1
Imaji asked on 30 Jun 2010, 11:15 PM
I'm trying to mock out a call that takes in nullable GUIDs, unfortunately when I try arranging the call:

Mock.Arrange(() => myStubInstance.DoSomthing(Arg.Any<Nullable<GUID>>()) or
Mock.Arrange(() => myStubInstance.DoSomthing(Arg.Any<GUID?>())

I get a null reference exception being thrown.  I then tried change the Arrange to use just GUID as the Arg type which works, but when the call is made in the code under test with a null value, the null reference is thrown again.

How can I get around this?

Ta,
J

2 Answers, 1 is accepted

Sort by
0
Accepted
Ricky
Telerik team
answered on 02 Jul 2010, 02:34 PM
Hi John,

Unfortunately, the issue is more internal of how the argument is matched for nullable types. But i fixed it and it will be shipping with next build.

With the new build you will be able to do it like [as expected]:
[TestMethod]
public void ShouldMatchNullableArgument()
{
    var foo = Mock.Create<Foo>();
    Mock.Arrange(() => foo.Echo(Arg.IsAny<int?>())).Returns(10);
    int ret = foo.Echo(4);
    Assert.Equal(10, ret);
}
 
Thanks a lot for reporting it :-)

Regards,
Mehfuz.

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Imaji
Top achievements
Rank 1
answered on 02 Jul 2010, 04:57 PM
Rocking, thanks Mehfuz :)
Tags
General Discussions
Asked by
Imaji
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Imaji
Top achievements
Rank 1
Share this question
or