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
Hi @ggirard07, IIRC the code behind DefaultValue.Empty performs a strict type check and doesn't take type inheritance into account.
Before you ask: yes, of course this could be changed. We've had similar requests in the past. (If I find the time, I'll link to some of them later.) However, I have been hesitant to change the behavior of DefaultValue.Empty because it is a core part of Moq and functional changes to it it could affect much pre-existing user code.
Now that Moq vNext has been shelved (for the time being) and we're free to do a new major version, perhaps we'll be able to change that behavior in v5.
The following (partially) works as long as the signature of the method being invoked clearly uses ILookup<> (i.e. won't work with IServiceProvider since the return type isn't known):
using Moq;using Xunit;varmock=newMock<ILookupProvider>();
mock.SetReturnsDefault(newDictionary<string,string>().ToLookup(x => x.Key,x => x.Value));varlookup= mock.Object.GetLookup<string,string>();
Assert.NotNull(lookup);publicinterfaceILookupProvider{ILookup<TKey,TValue>GetLookup<TKey,TValue>();}
Based on wiki, and as
ILookup<>
inherits fromIEnumerable<>
, I would expect the default value in loose mode to be an empty lookup, notnull
.Am I missing something here?
The text was updated successfully, but these errors were encountered: