Sometimes, the default values provided by Moq might not be suitable for some test scenarios and you need to create a custom default value generation approach to complement what Moq currently provides, which are DefaultValue.Empty and DefaultValue.Mock. This can be done through extending DefaultValueProvider or LookupOrFallbackDefaultValueProvider, which are available in Moq 4.8 and higher:
public class TestDefaultValueProvider : LookupOrFallbackDefaultValueProvider{ public TestDefaultValueProvider() { base.Register(typeof(string), (type, mock) => string.empty); base.Register(typeof(List<>), (type, mock) => Activator.CreateInstance(type)); }}
The TestDefaultValueProvider class created the sub-classes LookupOrFallbackDefaultValueProvider ...