Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public ctor for SubscriptionValidationResponse #21975

Merged
merged 2 commits into from
Jun 18, 2021

Conversation

JoshLove-msft
Copy link
Member

Also, use this ctor in the Event Grid function extension

@@ -69,7 +70,8 @@ public HttpRequestProcessor(ILogger<HttpRequestProcessor> logger)
SubscriptionValidationResponse validationResponse = new(){ ValidationResponse = validationCode };
var returnMessage = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(JsonConvert.SerializeObject(validationResponse))
// use System.Text.Json to leverage the custom converter so that the casing is correct.
Content = new StringContent(STJ.JsonSerializer.Serialize(validationResponse))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the behavior of JsonConvert.SerializeObject(validationResponse) differs before and after this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, previously we were using a ValidationResponse model defined in the extension library which had a JsonProperty attribute to get camel casing.

Now, we are using STJ converter which uses camel casing. I couldn't continue to use NewtonSoft and use the Event Grid SDK model. It seemed worth using the SDK model here to validate that it works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I tested it out and both Pascal and camelCase work fine when adding a subscription, but in order to maintain the same behavior as before (and to make the tests pass) it seems better to use camel case.

/// <param name="validationResponse"> The validation response sent by the subscriber to Azure Event Grid to complete the validation of an event subscription. </param>
/// <returns> A new <see cref="SystemEvents.SubscriptionValidationResponse"/> instance for mocking. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public static SubscriptionValidationResponse SubscriptionValidationResponse(string validationResponse = default)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to hide the factory? I get that you can use the constructor directly but it feels nice to be able to create any model from the model factory.

Copy link
Member Author

@JoshLove-msft JoshLove-msft Jun 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to, but it would go against our pattern of only including factories for output models. Codegen no longer generates the model factory for this type, so I had to add it back manually.
/cc @tg-msft @KrzysztofCwalina

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - the model factory only exists for constructing the otherwise unconstructible per the guidelines today: https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-mocking-factory-builder

It would take nontrivial effort to design and implement this across all of Track 2 when there's already a way of accomplishing it now, so it's not a high priority to me.

Copy link
Member

@jsquire jsquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will come in handy for parity as well. The lack of public constructor came up in a couple of samples that are being converted.

@JoshLove-msft JoshLove-msft merged commit 088f548 into Azure:main Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants