NotificationService: Missing IEquatable<T> Implementation in NotificationMessage #1066

Closed
opened 2026-01-29 17:48:31 +00:00 by claunia · 2 comments
Owner

Originally created by @quicksln on GitHub (Dec 14, 2023).

Describe the bug
The Notification Service relies on distributing messages from an observable collection:

ObservableCollection<NotificationMessage> Messages

The Notification Service includes two 'Notify' methods that check whether the collection contains a specific instance of NotificationMessage and add messages to the collection.

However, it does not function correctly because NotificationMessage does not implement IEquatable.
This interface implementation is necessary to determine if specific object instances are equal when using the List.Contains method.

To Reproduce
Steps to reproduce the behavior:

Run unit test :

        [Fact]
        public void NotificationService_MessagesCount_AfterAddingMessages()
        {
            NotificationService notificationService = new NotificationService();

            //Messages are the same so only one should be added
            notificationService.Notify(NotificationSeverity.Info, "Info Summary", "Info Detail", 4000);
            notificationService.Notify(new NotificationMessage()
            {
                Severity = NotificationSeverity.Info,
                Summary = "Info Summary",
                Detail = "Info Detail",
                Duration = 4000
            });

            int expectedMessagesNumber = 1;

            Assert.Equal(expectedMessagesNumber, notificationService.Messages.Count);
        }

Screenshots
image

image

Desktop (please complete the following information):
• OS: all
• Browser: [edge, chrome, safari
• Version: 4.22.1

Additional context
If my assumption is correct, I’ll be happy to fix it.

Originally created by @quicksln on GitHub (Dec 14, 2023). **Describe the bug** The Notification Service relies on distributing messages from an observable collection: `ObservableCollection<NotificationMessage> Messages` The Notification Service includes two 'Notify' methods that check whether the collection contains a specific instance of NotificationMessage and add messages to the collection. However, it does not function correctly because NotificationMessage does not implement IEquatable<T>. This interface implementation is necessary to determine if specific object instances are equal when using the List<T>.Contains method. **To Reproduce** Steps to reproduce the behavior: Run unit test : ``` [Fact] public void NotificationService_MessagesCount_AfterAddingMessages() { NotificationService notificationService = new NotificationService(); //Messages are the same so only one should be added notificationService.Notify(NotificationSeverity.Info, "Info Summary", "Info Detail", 4000); notificationService.Notify(new NotificationMessage() { Severity = NotificationSeverity.Info, Summary = "Info Summary", Detail = "Info Detail", Duration = 4000 }); int expectedMessagesNumber = 1; Assert.Equal(expectedMessagesNumber, notificationService.Messages.Count); } ``` **Screenshots** ![image](https://github.com/radzenhq/radzen-blazor/assets/65227444/7a127a8e-a35a-4398-b351-87aa9d20bad5) ![image](https://github.com/radzenhq/radzen-blazor/assets/65227444/3ff14f15-d557-4cf7-bd4f-c725968e53c6) **Desktop (please complete the following information):** • OS: all • Browser: [edge, chrome, safari • Version: 4.22.1 **Additional context** If my assumption is correct, I’ll be happy to fix it.
Author
Owner

@enchev commented on GitHub (Dec 15, 2023):

Hi @quicksln ,

Yes, sure! We accept pull requests!

@enchev commented on GitHub (Dec 15, 2023): Hi @quicksln , Yes, sure! We accept pull requests!
Author
Owner

@quicksln commented on GitHub (Dec 15, 2023):

Pull request has been created. Please verify if everything is according to your development standards.
If I missed something, just let me know 😊

@quicksln commented on GitHub (Dec 15, 2023): Pull request has been created. Please verify if everything is according to your development standards. If I missed something, just let me know 😊
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1066