|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.Collections.ObjectModel;
|
7 | 7 | using System.Collections.Specialized;
|
8 |
| -using System.ComponentModel.DataAnnotations; |
9 | 8 | using System.Globalization;
|
10 | 9 | using System.Linq;
|
11 | 10 | using System.Net;
|
@@ -44,20 +43,31 @@ public WebHookManagerTests()
|
44 | 43 | _response = new HttpResponseMessage();
|
45 | 44 | }
|
46 | 45 |
|
47 |
| - public static TheoryData<WebHook, string> WebHookValidationData |
| 46 | + public static TheoryData<string> WebHookSecretData |
48 | 47 | {
|
49 | 48 | get
|
50 | 49 | {
|
51 |
| - Uri webHookUri = new Uri("http://localhost"); |
52 |
| - string secret = new string('a', 32); |
53 |
| - return new TheoryData<WebHook, string> |
| 50 | + return new TheoryData<string> |
54 | 51 | {
|
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." }, |
| 52 | + null, |
| 53 | + string.Empty, |
| 54 | + new string('a', 31), |
| 55 | + new string('a', 65), |
| 56 | + }; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + public static TheoryData<string> WebHookUriData |
| 61 | + { |
| 62 | + get |
| 63 | + { |
| 64 | + return new TheoryData<string> |
| 65 | + { |
| 66 | + null, |
| 67 | + "ftp://localhost", |
| 68 | + "telnet://localhost", |
| 69 | + "htp://localhost", |
| 70 | + "invalid://localhost", |
61 | 71 | };
|
62 | 72 | }
|
63 | 73 | }
|
@@ -104,24 +114,23 @@ public static TheoryData<IEnumerable<WebHook>, IEnumerable<NotificationDictionar
|
104 | 114 | }
|
105 | 115 |
|
106 | 116 | [Theory]
|
107 |
| - [MemberData("WebHookValidationData")] |
108 |
| - public async Task VerifyWebHookAsync_Throws_IfInvalidWebHook(WebHook webHook, string expected) |
| 117 | + [MemberData("WebHookSecretData")] |
| 118 | + public async Task VerifyWebHookAsync_Throws_IfInvalidWebHookSecret(string secret) |
109 | 119 | {
|
110 | 120 | // Arrange
|
111 | 121 | _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient);
|
| 122 | + WebHook webHook = CreateWebHook(); |
| 123 | + webHook.Secret = secret; |
112 | 124 |
|
113 | 125 | // Act
|
114 |
| - ValidationException ex = await Assert.ThrowsAsync<ValidationException>(() => _manager.VerifyWebHookAsync(webHook)); |
| 126 | + InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); |
115 | 127 |
|
116 | 128 | // Assert
|
117 |
| - Assert.Equal(expected, ex.Message); |
| 129 | + Assert.Equal("The WebHook secret key parameter must be between 32 and 64 characters long.", ex.Message); |
118 | 130 | }
|
119 | 131 |
|
120 | 132 | [Theory]
|
121 |
| - [InlineData("ftp://localhost")] |
122 |
| - [InlineData("telnet://localhost")] |
123 |
| - [InlineData("htp://localhost")] |
124 |
| - [InlineData("invalid://localhost")] |
| 133 | + [MemberData("WebHookUriData")] |
125 | 134 | public async Task VerifyWebHookAsync_Throws_IfNotHttpOrHttpsUri(string webHookUri)
|
126 | 135 | {
|
127 | 136 | // Arrange
|
|
0 commit comments