|
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace Radzen.Blazor.Tests |
| 6 | +{ |
| 7 | + public class NotificationServiceTests |
| 8 | + { |
| 9 | + [Fact] |
| 10 | + public void NotificationService_IsMessageIsNull_ExceptionExpected() |
| 11 | + { |
| 12 | + NotificationService notificationService = new NotificationService(); |
| 13 | + NotificationMessage notificationMessage = null; |
| 14 | + |
| 15 | + var exception = Record.Exception(() => notificationService.Notify(notificationMessage)); |
| 16 | + |
| 17 | + Assert.IsType<ArgumentNullException>(exception); |
| 18 | + } |
| 19 | + |
| 20 | + [Fact] |
| 21 | + public void NotificationService_CheckAreTwoMessages_Equals() |
| 22 | + { |
| 23 | + var messageOne = new NotificationMessage() |
| 24 | + { |
| 25 | + Severity = NotificationSeverity.Info, |
| 26 | + Summary = "Info Summary", |
| 27 | + Detail = "Info Detail", |
| 28 | + Duration = 4000 |
| 29 | + }; |
| 30 | + |
| 31 | + var messageTwo = new NotificationMessage() |
| 32 | + { |
| 33 | + Severity = NotificationSeverity.Info, |
| 34 | + Summary = "Info Summary", |
| 35 | + Detail = "Info Detail", |
| 36 | + Duration = 4000 |
| 37 | + }; |
| 38 | + |
| 39 | + Assert.True(messageOne.Equals(messageTwo)); |
| 40 | + } |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void NotificationService_CheckAreTwoMessages_NotEquals() |
| 44 | + { |
| 45 | + var messageOne = new NotificationMessage() |
| 46 | + { |
| 47 | + Severity = NotificationSeverity.Info, |
| 48 | + Summary = "Info Summary", |
| 49 | + Detail = "Info Detail", |
| 50 | + Duration = 4000 |
| 51 | + }; |
| 52 | + |
| 53 | + var messageTwo = new NotificationMessage() |
| 54 | + { |
| 55 | + Severity = NotificationSeverity.Info, |
| 56 | + Summary = "Info Summary Two", |
| 57 | + Detail = "Info Detail Two", |
| 58 | + Duration = 6000 |
| 59 | + }; |
| 60 | + |
| 61 | + Assert.False(messageOne.Equals(messageTwo)); |
| 62 | + } |
| 63 | + |
| 64 | + [Fact] |
| 65 | + public void NotificationService_CheckAreTwoMessages_EqualsByReference() |
| 66 | + { |
| 67 | + var messageOne = new NotificationMessage() |
| 68 | + { |
| 69 | + Severity = NotificationSeverity.Info, |
| 70 | + Summary = "Info Summary", |
| 71 | + Detail = "Info Detail", |
| 72 | + Duration = 4000 |
| 73 | + }; |
| 74 | + |
| 75 | + var messageTwo = messageOne; |
| 76 | + |
| 77 | + Assert.True(messageOne.Equals(messageTwo)); |
| 78 | + } |
| 79 | + |
| 80 | + [Fact] |
| 81 | + public void NotificationService_CheckAreTwoMessages_EqualsByOperator() |
| 82 | + { |
| 83 | + var messageOne = new NotificationMessage() |
| 84 | + { |
| 85 | + Severity = NotificationSeverity.Info, |
| 86 | + Summary = "Info Summary", |
| 87 | + Detail = "Info Detail", |
| 88 | + Duration = 4000 |
| 89 | + }; |
| 90 | + |
| 91 | + var messageTwo = new NotificationMessage() |
| 92 | + { |
| 93 | + Severity = NotificationSeverity.Info, |
| 94 | + Summary = "Info Summary", |
| 95 | + Detail = "Info Detail", |
| 96 | + Duration = 4000 |
| 97 | + }; |
| 98 | + |
| 99 | + Assert.True(messageOne == messageTwo); |
| 100 | + } |
| 101 | + |
| 102 | + [Fact] |
| 103 | + public void NotificationService_CheckAreTwoMessages_NotEqualsByOperator() |
| 104 | + { |
| 105 | + var messageOne = new NotificationMessage() |
| 106 | + { |
| 107 | + Severity = NotificationSeverity.Info, |
| 108 | + Summary = "Info Summary", |
| 109 | + Detail = "Info Detail", |
| 110 | + Duration = 4000 |
| 111 | + }; |
| 112 | + |
| 113 | + var messageTwo = new NotificationMessage() |
| 114 | + { |
| 115 | + Severity = NotificationSeverity.Info, |
| 116 | + Summary = "Info Summary Two", |
| 117 | + Detail = "Info Detail Two", |
| 118 | + Duration = 6000 |
| 119 | + }; |
| 120 | + |
| 121 | + Assert.True(messageOne != messageTwo); |
| 122 | + } |
| 123 | + |
| 124 | + [Fact] |
| 125 | + public void NotificationService_CheckAreTwoMessages_EqualsByHashCode() |
| 126 | + { |
| 127 | + var messageOne = new NotificationMessage() |
| 128 | + { |
| 129 | + Severity = NotificationSeverity.Info, |
| 130 | + Summary = "Info Summary", |
| 131 | + Detail = "Info Detail", |
| 132 | + Duration = 4000 |
| 133 | + }; |
| 134 | + |
| 135 | + var messageTwo = new NotificationMessage() |
| 136 | + { |
| 137 | + Severity = NotificationSeverity.Info, |
| 138 | + Summary = "Info Summary", |
| 139 | + Detail = "Info Detail", |
| 140 | + Duration = 4000 |
| 141 | + }; |
| 142 | + |
| 143 | + var messageOneHashCode = messageOne.GetHashCode(); |
| 144 | + var messageTwoHashCode = messageTwo.GetHashCode(); |
| 145 | + |
| 146 | + Assert.Equal(messageOneHashCode, messageTwoHashCode); |
| 147 | + } |
| 148 | + |
| 149 | + [Fact] |
| 150 | + public void NotificationService_CheckAreTwoMessages_NotEqualsByHashCode() |
| 151 | + { |
| 152 | + var messageOne = new NotificationMessage() |
| 153 | + { |
| 154 | + Severity = NotificationSeverity.Info, |
| 155 | + Summary = "Info Summary", |
| 156 | + Detail = "Info Detail", |
| 157 | + Duration = 4000 |
| 158 | + }; |
| 159 | + |
| 160 | + var messageTwo = new NotificationMessage() |
| 161 | + { |
| 162 | + Severity = NotificationSeverity.Info, |
| 163 | + Summary = "Info Summary Two", |
| 164 | + Detail = "Info Detail Tow", |
| 165 | + Duration = 5000 |
| 166 | + }; |
| 167 | + |
| 168 | + var messageOneHashCode = messageOne.GetHashCode(); |
| 169 | + var messageTwoHashCode = messageTwo.GetHashCode(); |
| 170 | + |
| 171 | + Assert.NotEqual(messageOneHashCode, messageTwoHashCode); |
| 172 | + } |
| 173 | + |
| 174 | + [Fact] |
| 175 | + public void NotificationService_MessagesCount_AfterAddingMessages() |
| 176 | + { |
| 177 | + NotificationService notificationService = new NotificationService(); |
| 178 | + |
| 179 | + //Messages are the same so only one should be added |
| 180 | + notificationService.Notify(NotificationSeverity.Info, "Info Summary", "Info Detail", 4000); |
| 181 | + notificationService.Notify(new NotificationMessage() |
| 182 | + { |
| 183 | + Severity = NotificationSeverity.Info, |
| 184 | + Summary = "Info Summary", |
| 185 | + Detail = "Info Detail", |
| 186 | + Duration = 4000 |
| 187 | + }); |
| 188 | + |
| 189 | + int expectedMessagesNumber = 1; |
| 190 | + |
| 191 | + Assert.Equal(expectedMessagesNumber, notificationService.Messages.Count); |
| 192 | + } |
| 193 | + |
| 194 | + [Fact] |
| 195 | + public void NotificationService_MessagesCount_AfterAddingTwoDifferentMessages() |
| 196 | + { |
| 197 | + NotificationService notificationService = new NotificationService(); |
| 198 | + |
| 199 | + //Messages are the same so only one should be added |
| 200 | + notificationService.Notify(NotificationSeverity.Info, "Info Summary 2", "Info Detail 2", 6000); |
| 201 | + notificationService.Notify(new NotificationMessage() |
| 202 | + { |
| 203 | + Severity = NotificationSeverity.Info, |
| 204 | + Summary = "Info Summary", |
| 205 | + Detail = "Info Detail", |
| 206 | + Duration = 4000 |
| 207 | + }); |
| 208 | + |
| 209 | + int expectedMessagesNumber = 2; |
| 210 | + |
| 211 | + Assert.Equal(expectedMessagesNumber, notificationService.Messages.Count); |
| 212 | + } |
| 213 | + } |
| 214 | +} |
0 commit comments