Skip to content

Conversation

@jonfuller
Copy link
Contributor

refers to issue #14 .

- added new service
- added configuration
- added tests
- created eventgrid wrapper
- added additional payload tests
@jonfuller
Copy link
Contributor Author

@arktronic-sep - I'm unsure the best way to test and validate the work that I did.

Would love to chat about it sometime! Let me know best way to move forward.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces Azure Event Grid integration as a notification service for the sama monitoring application. The service sends structured events to Azure Event Grid when endpoint status changes occur or management operations are performed.

  • Adds EventGridNotificationService that implements INotificationService to send events to Azure Event Grid
  • Integrates the new service with dependency injection and configuration system
  • Includes comprehensive unit tests covering all notification scenarios

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
unit-tests/Services/EventGridNotificationServiceTests.cs Comprehensive test suite covering all notification methods and event payload validation
sama/sama.csproj Adds Azure.Messaging.EventGrid package dependency
sama/Startup.cs Registers EventGridNotificationService and wrapper in DI container
sama/Services/SettingsService.cs Adds configuration properties for Event Grid topic endpoint and access key
sama/Services/EventGridPublisherClientWrapper.cs Testable wrapper around Azure EventGridPublisherClient
sama/Services/EventGridNotificationService.cs Main service implementing INotificationService for Event Grid notifications

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 248 to 249
// Avoid async warning by not awaiting the result since we're testing the call was made
_ = result2;
Copy link

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

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

The comment and discard pattern is unnecessary. The variable assignment can be removed entirely since the verification is already complete in the Received() call.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not entirely wrong. We should be awaiting rather than assigning to a result variable, though. (Why is it named result2 when there isn't a result1?)

@jonfuller
Copy link
Contributor Author

also, add place to configure settings for event grid.

jonfuller and others added 3 commits October 31, 2025 07:47
use file scoped namespace
make endpoint subjects consistent
@jonfuller
Copy link
Contributor Author

@arktronic-sep - I think I'm all set.

I made the suggested changes, and added the settings fields.

Here is a screenshot showing that messages are flowing into the Azure Event Grid topic:
image

Please take a look when you can so we can get this sent over to IT.

Thanks!

@jonfuller jonfuller marked this pull request as ready for review November 4, 2025 14:55

namespace sama.Services;

public class EventGridNotificationService : INotificationService
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: spacing was not reformatted after switching namespace style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will def fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed an update.

_eventGridWrapper = eventGridWrapper;
}

private static class EventTypes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why a class here? It just contains const strings, so couldn't they exist in the parent class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just to collect them all together. just how my brain wanted to organize them. no pref either way for me.

Comment on lines 37 to 38
private static string Subject(string path) => $"Sama/{path}";
private static string EndpointSubject(string path) => Subject($"endpoints/{path}");
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Is Subject used anymore (aside from in EndpointSubject)?
  • Minor: spacing inconsistency
  • Minor: as these are methods, they should be verbified

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another minor question: why does the Subject capitalize the first letter in sama? Is this an Event Grid convention?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hehe - that's a good question! no, I don't think it's an EventGrid convention. I think I'll switch it to all lowercase sama.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Subject isn't used outside of EndpointSubject. That said, I still like the separation of concepts, if that makes sense.

Comment on lines 116 to 137
[TestMethod]
public void NotifyMiscShouldExecuteInBackgroundForEndpointReconfigured()
{
var endpoint = CreateTestHttpEndpoint();

_service.NotifyMisc(endpoint, NotificationType.EndpointReconfigured);

_bgExec.Received(1).Execute(Arg.Any<Action>());
}

[TestMethod]
public void ShouldNotExecuteWhenTopicEndpointIsNotConfigured()
{
_settings.Notifications_EventGrid_TopicEndpoint.Returns((string)null);
var endpoint = CreateTestHttpEndpoint();
var result = new EndpointCheckResult { Success = true };

_service.NotifySingleResult(endpoint, result);

// Should still call Execute, but the async function inside should return early
_bgExec.Received(1).Execute(Arg.Any<Action>());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused about these tests... they aren't validating the data received, which seems like it'd be important. And the tests named ShouldNotExecute* all expect that Execute is, in fact, called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first one - I would personally not validate the data, just verify that it executed. There are other tests that verify the payload.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the rest of the ShouldNotExecute* tests. Good find!

)
);

// Avoid async warning by not awaiting the result since we're testing the call was made
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe, verifying async calls is generally done with await. Not sure what warning this would be. For some examples, take a look at SlackNotificationServiceTests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it was confused a bit. The warning shows up I think when you don't mark the method async. I marked them async and changed it back to await. All seems well!

- update sama subject name
- remove result variables
- update "shouldnotexecute..." tests
@jonfuller
Copy link
Contributor Author

Alright - one more round if you want to take another look! Thanks!

@arktronic-sep arktronic-sep merged commit 38b55bd into main Nov 12, 2025
1 check passed
@arktronic-sep arktronic-sep deleted the 14-azure-event-grid branch November 12, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants