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

[QUERY] NotImplementedException when creating EventGridEvent for testing subscription validation event #35901

Open
seanjohnston-codurance opened this issue Apr 28, 2023 · 3 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Grid feature-request This issue requires a new behavior in the product in order be resolved. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team test-enhancement
Milestone

Comments

@seanjohnston-codurance
Copy link

Library name and version

Azure.Messaging.EventGrid 4.13.0

Query/Question

Trying to unit test an Azure Function to confirm that it correctly handles a SubscriptionValidationEvent (at least verify that it returns 200), but it seems to be impossible to create a real EventGridEvent with SubscriptionValidationEventData as there is a NotImplemented method Write() when trying to serialize the data during the EventGridEvent constructor.

It seems that the EventGridModelFactory allowing me to create the data model indicates that this sort of thing should be possible, but it doesn't then seem to be set up so that I can actually create a system event from that data.

Is this intended behaviour?

Environment

.NET SDK (reflecting any global.json):
Version: 6.0.400
Commit: 7771abd614

Runtime Environment:
OS Name: Mac OS X
OS Version: 13.3
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/6.0.400/

global.json file:
Not found

Host:
Version: 6.0.8
Architecture: arm64
Commit: 55fb7ef977

.NET SDKs installed:
6.0.400 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Grid needs-team-triage Workflow: This issue needs the team to triage. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Apr 28, 2023
@seanjohnston-codurance seanjohnston-codurance changed the title [QUERY] NotImplementedException when creating system event for testing [QUERY] NotImplementedException when creating EventGridEvent for testing subscription validation event Apr 28, 2023
@jsquire jsquire added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-team-triage Workflow: This issue needs the team to triage. labels Apr 28, 2023
@jsquire
Copy link
Member

jsquire commented Apr 28, 2023

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

@JoshLove-msft
Copy link
Member

The model factory is intended to allow creation of all output model types for testing. Because these types are considered output types, the code generator that generates the serialization code does not implement write methods. I agree that this does make it difficult to test the end-to-end scenario of having one of these data models wrapped in an EventGridEvent (or CloudEvent) envelope. We will look into improving the experience here.

@JoshLove-msft JoshLove-msft added test-enhancement and removed needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels May 1, 2023
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label May 1, 2023
@jsquire jsquire added feature-request This issue requires a new behavior in the product in order be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Jan 12, 2024
@jsquire jsquire added this to the Backlog milestone Jan 12, 2024
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Jan 12, 2024
@enioluwas
Copy link

Running into this as well on version 4.21.0. The only workaround I've found for unit testing is to write the JSON for the system event directly:

var eventJson = JsonDocument.Parse("""
{
    "validationCode": "512d38b6-c7b8-40c8-89fe-f46f9e9622b6",
    "validationUrl": "http://test.com"
}
""");

var request = new EventGridEvent(
    subject: "subject",
    eventType: SystemEventNames.EventGridSubscriptionValidation,
    dataVersion: "V3",
    BinaryData.FromObjectAsJson(eventJson.RootElement));

JSON serialization seems to be an issue with most EventGrid models. It makes unit testing code that uses this library a challenge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Grid feature-request This issue requires a new behavior in the product in order be resolved. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team test-enhancement
Projects
None yet
Development

No branches or pull requests

4 participants