Looking at Microsoft's code for example, they create a 'ModelFactory' class for constructing objects for use in tests: https://github.com/Azure/azure-sdk-for-net/blob/62f2223e46c33825628443d11b8267de4e72a1c6/sdk/servicebus/Azure.Messaging.ServiceBus/src/Primitives/ServiceBusModelFactory.cs
So if we need to mock a method on a service bus client which returns say, 'SubscriptionProperties', we need to obtain a new instance of this object with all the correct min/max values as the real code will run validation against those fields:
public static SubscriptionProperties SubscriptionProperties(
string topicName,
string subscriptionName,
TimeSpan lockDuration = default,
bool requiresSession = default,
TimeSpan defaultMessageTimeToLive = default,
TimeSpan autoDeleteOnIdle = default,
bool deadLetteringOnMessageExpiration = default,
int maxDeliveryCount = default,
bool enableBatchedOperations = default,
EntityStatus status = default,
string forwardTo = default,
string forwardDeadLetteredMessagesTo = default,
string userMetadata = default) =>
new SubscriptionProperties(topicName, subscriptionName)
{
LockDuration = lockDuration,
RequiresSession = requiresSession,
DefaultMessageTimeToLive = defaultMessageTimeToLive,
AutoDeleteOnIdle = autoDeleteOnIdle,
DeadLetteringOnMessageExpiration = deadLetteringOnMessageExpiration,
MaxDeliveryCount = maxDeliveryCount,
EnableBatchedOperations = enableBatchedOperations,
Status = status,
ForwardTo = forwardTo,
ForwardDeadLetteredMessagesTo = forwardDeadLetteredMessagesTo,
UserMetadata = userMetadata
};
If SubscriptionProperties instead implemented an interface with these properties, it would be extremely easy to mock the ones we care about without any real implementation executing.
What are some of the values which come with this 'real implementation' ModelFactory approach when it comes to unit testing?