azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[FEATURE REQ] Remove internal setters for result classes like in MessageCountDetails
Library name
Azure.ResourceManager.ServiceBus 1.0.0
Please describe the feature.
I'm using this library in my code to get the message count details from my service bus. I wrote a custom wrapper (called ServiceBusManagement) to extract this value per my needs which returns MessageCountDetails, let's call it GetMessageCountDetailsAsync. I have a class (let's call it BusinessLogicClass) that uses this wrapper and I want to unit test the BL class. For that I need to mock ServiceBusManagement.GetMessageCountDetailsAsync but the issue is that the setters are internals and this prevents me from mocking the return value.
var countDetails = new MessageCountDetails();
Gives:
Error CS1729 'MessageCountDetails' does not contain a constructor that takes 0 arguments
https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Management/MessageCountDetails.cs
I can work around by having a proxy class as suggested here https://stackoverflow.com/questions/34992582/c-sharp-mock-a-class-with-an-internal-property-setter but please consider removing the internal setters. Unless it's absolutely critical that only the lib will initiate them (which doesn't look like the case here) then it just makes working with lib less comfortable. I assume you took a similar approach in other areas as well.
Thank you for your feedback. Tagging and routing to the team member best able to assist.
We'll provide a model factory method to generate model classes: https://github.com/Azure/autorest.csharp/issues/2112 CC: @ArthurMa1978 @ArcturusZhang
We'll provide a model factory method to generate model classes: Azure/autorest.csharp#2112 CC: @ArthurMa1978 @ArcturusZhang
That would be great
Close it as this is tracked by feature https://github.com/Azure/autorest.csharp/issues/2112