diff --git a/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs b/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs index ce059b3e..b21eb1ff 100644 --- a/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs @@ -106,8 +106,21 @@ public async Task GetAsync() public async Task GetAllAsync() { // Arrange + var limit = 50; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT); + + // This is what the endpoint URL should be but we don't support limit and offset yet. + // See: https://github.com/Jericho/StrongGrid/issues/368 + // var endpoint = Utils.GetSendGridApiUri(ENDPOINT) + $"?limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT)).Respond("application/json", MULTIPLE_API_KEY_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_API_KEY_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var apiKeys = new ApiKeys(client); diff --git a/Source/StrongGrid.UnitTests/Resources/BlocksTests.cs b/Source/StrongGrid.UnitTests/Resources/BlocksTests.cs index fea4d070..f8ab84a1 100644 --- a/Source/StrongGrid.UnitTests/Resources/BlocksTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/BlocksTests.cs @@ -55,8 +55,17 @@ public void Parse_json() public async Task GetAllAsync() { // Arrange + var limit = 25; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT) + $"?limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT) + $"?limit=25&offset=0").Respond("application/json", MULTIPLE_BLOCKS_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_BLOCKS_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var blocks = new Blocks(client); diff --git a/Source/StrongGrid.UnitTests/Resources/GlobalSuppressionTests.cs b/Source/StrongGrid.UnitTests/Resources/GlobalSuppressionTests.cs index dd1c9d46..818a504a 100644 --- a/Source/StrongGrid.UnitTests/Resources/GlobalSuppressionTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/GlobalSuppressionTests.cs @@ -35,11 +35,14 @@ public class GlobalSuppressionTests public async Task GetAll() { // Arrange + var limit = 50; + var endpoint = Utils.GetSendGridApiUri("suppression/unsubscribes") + $"?limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri("suppression/unsubscribes")).Respond((HttpRequestMessage request) => + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => { var response = new HttpResponseMessage(HttpStatusCode.OK); - response.Headers.Add("link", "; rel=\"next\"; title=\"1\", ; rel=\"prev\"; title=\"1\", ; rel=\"last\"; title=\"1\", ; rel=\"first\"; title=\"1\""); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); response.Content = new StringContent(GLOBALLY_UNSUBSCRIBED); return response; }); @@ -48,7 +51,7 @@ public async Task GetAll() var globalSuppressions = new GlobalSuppressions(client); // Act - var result = await globalSuppressions.GetAllAsync(null, null, null, 50, 0, null, CancellationToken.None); + var result = await globalSuppressions.GetAllAsync(null, null, null, limit, 0, null, CancellationToken.None); // Assert mockHttp.VerifyNoOutstandingExpectation(); diff --git a/Source/StrongGrid.UnitTests/Resources/InvalidEmailsTests.cs b/Source/StrongGrid.UnitTests/Resources/InvalidEmailsTests.cs index c2bbe4d5..3847cac4 100644 --- a/Source/StrongGrid.UnitTests/Resources/InvalidEmailsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/InvalidEmailsTests.cs @@ -60,9 +60,16 @@ public async Task GetAllAsync() // Arrange var limit = 25; var offset = 0; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT) + $"?limit={limit}&offset={offset}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT) + $"?limit={limit}&offset={offset}").Respond("application/json", MULTIPLE_INVALID_EMAILS_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_INVALID_EMAILS_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var invalidEmails = new InvalidEmails(client); diff --git a/Source/StrongGrid.UnitTests/Resources/IpAddressesTests.cs b/Source/StrongGrid.UnitTests/Resources/IpAddressesTests.cs index 98ec83ee..1355a6fd 100644 --- a/Source/StrongGrid.UnitTests/Resources/IpAddressesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/IpAddressesTests.cs @@ -168,14 +168,24 @@ public async Task GetRemainingCountAsync() public async Task GetAllAsync() { // Arrange + var limit = 10; + var offset = 0; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT) + $"?limit={limit}&offset={offset}"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT)).Respond("application/json", MULTIPLE_IPADDRESSES_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_IPADDRESSES_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var ipAddresses = new IpAddresses(client); // Act - var result = await ipAddresses.GetAllAsync(false, null, 10, 0, CancellationToken.None); + var result = await ipAddresses.GetAllAsync(false, null, limit, offset, CancellationToken.None); // Assert mockHttp.VerifyNoOutstandingExpectation(); @@ -212,8 +222,17 @@ public async Task GetAssignedAsync() public async Task GetUnassignedAsync() { // Arrange + var limit = 10; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT) + $"?limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT) + $"?exclude_whitelabels=false&limit=500&offset=0&sort_by_direction=asc").Respond("application/json", MULTIPLE_IPADDRESSES_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_IPADDRESSES_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var ipAddresses = new IpAddresses(client); diff --git a/Source/StrongGrid.UnitTests/Resources/SenderAuthenticationTests.cs b/Source/StrongGrid.UnitTests/Resources/SenderAuthenticationTests.cs index c7f8d7fd..d49a265f 100644 --- a/Source/StrongGrid.UnitTests/Resources/SenderAuthenticationTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/SenderAuthenticationTests.cs @@ -343,8 +343,17 @@ public void Parse_AuthenticatedDomain_json() public async Task GetAllDomainsAsync_include_subusers() { // Arrange + var limit = 50; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT, "domains") + $"?exclude_subusers=false&limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, "domains?exclude_subusers=false&limit=50&offset=0")).Respond("application/json", MULTIPLE_DOMAINS_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_DOMAINS_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var senderAuthentication = new SenderAuthentication(client); @@ -363,8 +372,17 @@ public async Task GetAllDomainsAsync_include_subusers() public async Task GetAllDomainsAsync_exclude_subusers() { // Arrange + var limit = 50; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT, "domains") + $"?exclude_subusers=true&limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, "domains?exclude_subusers=true&limit=50&offset=0")).Respond("application/json", MULTIPLE_DOMAINS_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_DOMAINS_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var senderAuthentication = new SenderAuthentication(client); @@ -636,8 +654,17 @@ public async Task AssociateDomainAsync() public async Task GetAllReverseDnsAsync() { // Arrange + var limit = 50; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT, "ips") + $"?limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, "ips?limit=50&offset=0")).Respond("application/json", MULTIPLE_IPS_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_IPS_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var senderAuthentication = new SenderAuthentication(client); @@ -968,8 +995,17 @@ public async Task AssociateLinkAsync() public async Task GetAllLinksAsync() { // Arrange + var limit = 50; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT, "links") + $"?limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, "links?limit=50&offset=0")).Respond("application/json", MULTIPLE_LINKS_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_LINKS_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var senderAuthentication = new SenderAuthentication(client); diff --git a/Source/StrongGrid.UnitTests/Resources/SpamReportsTests.cs b/Source/StrongGrid.UnitTests/Resources/SpamReportsTests.cs index df184600..20710423 100644 --- a/Source/StrongGrid.UnitTests/Resources/SpamReportsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/SpamReportsTests.cs @@ -61,8 +61,17 @@ public void Parse_json() public async Task GetAllAsync() { // Arrange + var limit = 25; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT) + $"?limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT) + $"?limit=25&offset=0").Respond("application/json", MULTIPLE_SPAM_REPORTS_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_SPAM_REPORTS_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var spamReports = new SpamReports(client); diff --git a/Source/StrongGrid.UnitTests/Resources/TeammatesTests.cs b/Source/StrongGrid.UnitTests/Resources/TeammatesTests.cs index df7c0acc..09edbe0c 100644 --- a/Source/StrongGrid.UnitTests/Resources/TeammatesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/TeammatesTests.cs @@ -235,8 +235,21 @@ public async Task ResendInvitationAsync() public async Task GetAllPendingInvitationsAsync() { // Arrange + var limit = 50; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT, "pending"); + + // This is what the endpoint URL should be but we don't support limit and offset yet. + // See: https://github.com/Jericho/StrongGrid/issues/368 + // var endpoint = Utils.GetSendGridApiUri(ENDPOINT, "pending") + $"?limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, "pending")).Respond("application/json", MULTIPLE_INVITATIONS_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_INVITATIONS_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var teammates = new Teammates(client); @@ -318,14 +331,23 @@ public async Task InviteTeammateAsAdminAsync() public async Task GetAllTeammatesAsync() { // Arrange + var limit = 50; + var endpoint = Utils.GetSendGridApiUri(ENDPOINT) + $"?limit={limit}&offset=0"; + var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT)).Respond("application/json", MULTIPLE_TEAMMATES_JSON); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent(MULTIPLE_TEAMMATES_JSON); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var teammates = new Teammates(client); // Act - var result = await teammates.GetAllTeammatesAsync(10, 0, CancellationToken.None); + var result = await teammates.GetAllTeammatesAsync(limit, 0, CancellationToken.None); // Assert mockHttp.VerifyNoOutstandingExpectation(); diff --git a/Source/StrongGrid.UnitTests/Resources/WebhookSettingsTests.cs b/Source/StrongGrid.UnitTests/Resources/WebhookSettingsTests.cs index 1b6ef2f8..0d49ddfc 100644 --- a/Source/StrongGrid.UnitTests/Resources/WebhookSettingsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/WebhookSettingsTests.cs @@ -228,13 +228,25 @@ public async Task GetInboundParseWebhookSettings() public async Task GetAllInboundParseWebhookSettings() { // Arrange - var apiResponse = "{\"result\":[" + - SINGLE_INBOUNDPARSE_WEBHOOK_SETTING_JSON + "," + - SINGLE_INBOUNDPARSE_WEBHOOK_SETTING_JSON + - "]}"; + var limit = 25; + var endpoint = Utils.GetSendGridApiUri(INBOUNDPARSE_ENDPOINT, "settings"); + + // This is what the endpoint URL should be but we don't support limit and offset yet. + // See: https://github.com/Jericho/StrongGrid/issues/368 + // var endpoint = Utils.GetSendGridApiUri(INBOUNDPARSE_ENDPOINT, "settings") + $"?limit={limit}&offset=0"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(INBOUNDPARSE_ENDPOINT, "settings")).Respond("application/json", apiResponse); + mockHttp.Expect(HttpMethod.Get, endpoint).Respond((HttpRequestMessage request) => + { + var response = new HttpResponseMessage(HttpStatusCode.OK); + response.Headers.Add("Link", $"<{endpoint}>; rel=\"next\"; title=\"1\", <{endpoint}>; rel=\"prev\"; title=\"1\", <{endpoint}>; rel=\"last\"; title=\"1\", <{endpoint}>; rel=\"first\"; title=\"1\""); + response.Content = new StringContent( + "{\"result\":[" + + SINGLE_INBOUNDPARSE_WEBHOOK_SETTING_JSON + "," + + SINGLE_INBOUNDPARSE_WEBHOOK_SETTING_JSON + + "]}"); + return response; + }); var client = Utils.GetFluentClient(mockHttp); var webhooks = new WebhookSettings(client);