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
Which obviously throws NRE as-is, because IntegerContainer is null by default. If I understand the docs correctly, I can address this issue by implementing a custom DefaultValueProvider as follows:
publicclassContainerAwareDefaultValueProvider:DefaultValueProvider{protectedoverrideobjectGetDefaultValue(Typetype,Mockmock){if(Utils.IsContainerType(type)){return Utils.MakeFakeContainer(type);}returnnewobject();// TODO What to return here?}}
I can even make a MockRepository instance in order to reuse this DefaultValueProvider implementation across the whole test suite. But question arises - what should I return in case the condition under the if evaluates to false (e.g. we're trying to instantiate an arbitrary type, unrelated to IContainer<T>)?
I can't directly pass control to neither DefaultValueProvider.Empty.GetDefaultValue(type, mock) nor DefaultValueProvider.Mock.GetDefaultValue(type, mock), because the method is protected internal
I can't inherit from neither EmptyDefaultValueProvider nor MockDefaultValueProvider and call base.GetDefaultValue(type, mock), because both classes are sealed with internal constructors
Is my only option to duplicate the implementation of one of existing DefaultValueProviders? Or am I missing on the intended way to do what I'm seeking to do?
The text was updated successfully, but these errors were encountered:
Imagine I have
Somewhere in my codebase. For unit-testing purposes I would also have a basic hand-mocked version:
Now I want to be able to do stuff like this:
Which obviously throws NRE as-is, because
IntegerContainer
is null by default. If I understand the docs correctly, I can address this issue by implementing a customDefaultValueProvider
as follows:I can even make a
MockRepository
instance in order to reuse thisDefaultValueProvider
implementation across the whole test suite. But question arises - what should I return in case the condition under theif
evaluates to false (e.g. we're trying to instantiate an arbitrary type, unrelated toIContainer<T>
)?DefaultValueProvider.Empty.GetDefaultValue(type, mock)
norDefaultValueProvider.Mock.GetDefaultValue(type, mock)
, because the method isprotected internal
EmptyDefaultValueProvider
norMockDefaultValueProvider
and callbase.GetDefaultValue(type, mock)
, because both classes aresealed
withinternal
constructorsIs my only option to duplicate the implementation of one of existing
DefaultValueProvider
s? Or am I missing on the intended way to do what I'm seeking to do?The text was updated successfully, but these errors were encountered: