Description
Library name and version
Azure.ResourceManager.Resources 1.7.1
Query/Question
I am utilizing ArmResourcesModelFactory
to create mock objects for my unit tests like so:
Properties = ArmResourcesModelFactory.ArmDeploymentOperationProperties(
...
targetResource: ArmResourcesModelFactory.TargetResource(
id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Test/providers/Microsoft.Compute/virtualMachineScaleSets/compute-1",
resourceName: "compute-1",
resourceType: "Microsoft.Compute/virtualMachineScaleSets"))
However the resourceType
property is actually a struct with an implicit operator that converts a string into a ResourceType
.
I have some code path that tests whether a raw string representation of the deployment operation is handled correctly. To do that, I need to serialize the object created above using the ArmResourcesModelFactory
, but doing that ends up with something like this:
"properties": {
"targetResource": {
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Test/providers/Microsoft.Compute/virtualMachineScaleSets/compute-1",
"resourceName": "FTTestService-WUS",
"resourceType": {
"type": "virtualMachineScaleSets",
"namespace": "Microsoft.Compute"
}
}
}
What I would like is to serialize it into this:
"properties": {
"targetResource": {
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Test/providers/Microsoft.Compute/virtualMachineScaleSets/compute-1",
"resourceName": "FTTestService-WUS",
"resourceType": "Microsoft.Compute/virtualMachineScaleSets"
}
}
An alternative I've considered is writing a custom ResourceTypeConverter
to do this, but it's not as clean, and I wondered if there was a better way to do this.
Environment
dotnet SDK version: 8.0.404
VS 2022 version: 17.14