5
5
using System . Collections . Generic ;
6
6
using System . Collections . ObjectModel ;
7
7
using System . Collections . Specialized ;
8
+ using System . ComponentModel . DataAnnotations ;
8
9
using System . Globalization ;
9
10
using System . Linq ;
10
11
using System . Net ;
@@ -43,6 +44,24 @@ public WebHookManagerTests()
43
44
_response = new HttpResponseMessage ( ) ;
44
45
}
45
46
47
+ public static TheoryData < WebHook , string > WebHookValidationData
48
+ {
49
+ get
50
+ {
51
+ Uri webHookUri = new Uri ( "http://localhost" ) ;
52
+ string secret = new string ( 'a' , 32 ) ;
53
+ return new TheoryData < WebHook , string >
54
+ {
55
+ { new WebHook ( ) , "The WebHookUri field is required." } ,
56
+ { new WebHook { WebHookUri = null , Secret = secret } , "The WebHookUri field is required." } ,
57
+ { new WebHook { WebHookUri = webHookUri , Secret = null } , "The Secret field is required." } ,
58
+ { new WebHook { WebHookUri = webHookUri , Secret = string . Empty } , "The Secret field is required." } ,
59
+ { new WebHook { WebHookUri = webHookUri , Secret = "a" } , "The WebHook secret key parameter must be between 32 and 64 characters long." } ,
60
+ { new WebHook { WebHookUri = webHookUri , Secret = new string ( 'a' , 65 ) } , "The WebHook secret key parameter must be between 32 and 64 characters long." } ,
61
+ } ;
62
+ }
63
+ }
64
+
46
65
public static TheoryData < IEnumerable < WebHook > , NotificationDictionary > FilterSingleNotificationData
47
66
{
48
67
get
@@ -84,6 +103,20 @@ public static TheoryData<IEnumerable<WebHook>, IEnumerable<NotificationDictionar
84
103
}
85
104
}
86
105
106
+ [ Theory ]
107
+ [ MemberData ( "WebHookValidationData" ) ]
108
+ public async Task VerifyWebHookAsync_Throws_IfInvalidWebHook ( WebHook webHook , string expected )
109
+ {
110
+ // Arrange
111
+ _manager = new WebHookManager ( _storeMock . Object , _senderMock . Object , _loggerMock . Object , _httpClient ) ;
112
+
113
+ // Act
114
+ ValidationException ex = await Assert . ThrowsAsync < ValidationException > ( ( ) => _manager . VerifyWebHookAsync ( webHook ) ) ;
115
+
116
+ // Assert
117
+ Assert . Equal ( expected , ex . Message ) ;
118
+ }
119
+
87
120
[ Theory ]
88
121
[ InlineData ( "ftp://localhost" ) ]
89
122
[ InlineData ( "telnet://localhost" ) ]
@@ -94,7 +127,7 @@ public async Task VerifyWebHookAsync_Throws_IfNotHttpOrHttpsUri(string webHookUr
94
127
// Arrange
95
128
_manager = new WebHookManager ( _storeMock . Object , _senderMock . Object , _loggerMock . Object , _httpClient ) ;
96
129
WebHook webHook = CreateWebHook ( ) ;
97
- webHook . WebHookUri = new Uri ( webHookUri ) ;
130
+ webHook . WebHookUri = webHookUri != null ? new Uri ( webHookUri ) : null ;
98
131
99
132
// Act
100
133
InvalidOperationException ex = await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _manager . VerifyWebHookAsync ( webHook ) ) ;
0 commit comments