azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[FEATURE REQ] Remove internal setters for result classes like in MessageCountDetails

Open ilankhirin opened this issue 3 years ago • 2 comments
trafficstars

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.

ilankhirin avatar Nov 10 '22 10:11 ilankhirin

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire avatar Nov 10 '22 13:11 jsquire

We'll provide a model factory method to generate model classes: https://github.com/Azure/autorest.csharp/issues/2112 CC: @ArthurMa1978 @ArcturusZhang

xboxeer avatar Nov 11 '22 08:11 xboxeer

We'll provide a model factory method to generate model classes: Azure/autorest.csharp#2112 CC: @ArthurMa1978 @ArcturusZhang

That would be great

ilankhirin avatar Nov 13 '22 08:11 ilankhirin

Close it as this is tracked by feature https://github.com/Azure/autorest.csharp/issues/2112

ArthurMa1978 avatar Nov 24 '22 14:11 ArthurMa1978