Skip to content

Commit db7dc90

Browse files
author
Jonny Bekkum
committed
Updated unit tests and samples
1 parent 6106afb commit db7dc90

File tree

5 files changed

+1596
-1915
lines changed

5 files changed

+1596
-1915
lines changed

ExampleCoreProject/Example.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static async Task Execute()
3131
Console.WriteLine(msg.Serialize());
3232
Console.WriteLine(response.StatusCode);
3333
Console.WriteLine(response.Headers);
34-
Console.WriteLine("\n\nPress any key to continue.");
34+
Console.WriteLine("\n\nPress <Enter> to continue.");
3535
Console.ReadLine();
3636

3737
// Send a Single Email using the Mail Helper with convenience methods and initialized SendGridMessage object
@@ -48,7 +48,7 @@ static async Task Execute()
4848
Console.WriteLine(msg.Serialize());
4949
Console.WriteLine(response.StatusCode);
5050
Console.WriteLine(response.Headers);
51-
Console.WriteLine("\n\nPress any key to continue.");
51+
Console.WriteLine("\n\nPress <Enter> to continue.");
5252
Console.ReadLine();
5353

5454
// Send a Single Email using the Mail Helper, entirely with convenience methods
@@ -63,7 +63,7 @@ static async Task Execute()
6363
Console.WriteLine(msg.Serialize());
6464
Console.WriteLine(response.StatusCode);
6565
Console.WriteLine(response.Headers);
66-
Console.WriteLine("\n\nPress any key to continue.");
66+
Console.WriteLine("\n\nPress <Enter> to continue.");
6767
Console.ReadLine();
6868

6969
// Send a Single Email Without the Mail Helper
@@ -94,7 +94,7 @@ static async Task Execute()
9494
urlPath: "mail/send");
9595
Console.WriteLine(response.StatusCode);
9696
Console.WriteLine(response.Headers);
97-
Console.WriteLine("\n\nPress any key to continue.");
97+
Console.WriteLine("\n\nPress <Enter> to continue.");
9898
Console.ReadLine();
9999

100100
// GET Collection
@@ -107,7 +107,7 @@ static async Task Execute()
107107
Console.WriteLine(response.StatusCode);
108108
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
109109
Console.WriteLine(response.Headers);
110-
Console.WriteLine("\n\nPress any key to continue to POST.");
110+
Console.WriteLine("\n\nPress <Enter> to continue to POST.");
111111
Console.ReadLine();
112112

113113
// POST
@@ -124,7 +124,7 @@ static async Task Execute()
124124
Console.WriteLine(response.StatusCode);
125125
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
126126
Console.WriteLine(response.Headers);
127-
Console.WriteLine("\n\nPress any key to continue to GET single.");
127+
Console.WriteLine("\n\nPress <Enter> to continue to GET single.");
128128
Console.ReadLine();
129129

130130
if (ds_response != null && ds_response.ContainsKey("id"))
@@ -138,7 +138,7 @@ static async Task Execute()
138138
Console.WriteLine(response.StatusCode);
139139
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
140140
Console.WriteLine(response.Headers);
141-
Console.WriteLine("\n\nPress any key to continue to PATCH.");
141+
Console.WriteLine("\n\nPress <Enter> to continue to PATCH.");
142142
Console.ReadLine();
143143

144144
// PATCH
@@ -154,15 +154,15 @@ static async Task Execute()
154154
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
155155
Console.WriteLine(response.Headers.ToString());
156156

157-
Console.WriteLine("\n\nPress any key to continue to PUT.");
157+
Console.WriteLine("\n\nPress <Enter> to continue to PUT.");
158158
Console.ReadLine();
159159

160160
// DELETE
161161
response = await client.RequestAsync(method: SendGridClient.Method.DELETE,
162162
urlPath: string.Format("asm/groups/{0}", group_id));
163163
Console.WriteLine(response.StatusCode);
164164
Console.WriteLine(response.Headers.ToString());
165-
Console.WriteLine("\n\nPress any key to DELETE and exit.");
165+
Console.WriteLine("\n\nPress <Enter> to DELETE and exit.");
166166
Console.ReadLine();
167167
}
168168
}

ExampleNet45Project/Example.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static async Task Execute()
3131
Console.WriteLine(msg.Serialize());
3232
Console.WriteLine(response.StatusCode);
3333
Console.WriteLine(response.Headers);
34-
Console.WriteLine("\n\nPress any key to continue.");
34+
Console.WriteLine("\n\nPress <Enter> to continue.");
3535
Console.ReadLine();
3636

3737
// Send a Single Email using the Mail Helper with convenience methods and initialized SendGridMessage object
@@ -48,7 +48,7 @@ static async Task Execute()
4848
Console.WriteLine(msg.Serialize());
4949
Console.WriteLine(response.StatusCode);
5050
Console.WriteLine(response.Headers);
51-
Console.WriteLine("\n\nPress any key to continue.");
51+
Console.WriteLine("\n\nPress <Enter> to continue.");
5252
Console.ReadLine();
5353

5454
// Send a Single Email using the Mail Helper, entirely with convenience methods
@@ -63,7 +63,7 @@ static async Task Execute()
6363
Console.WriteLine(msg.Serialize());
6464
Console.WriteLine(response.StatusCode);
6565
Console.WriteLine(response.Headers);
66-
Console.WriteLine("\n\nPress any key to continue.");
66+
Console.WriteLine("\n\nPress <Enter> to continue.");
6767
Console.ReadLine();
6868

6969
// Send a Single Email Without the Mail Helper
@@ -94,7 +94,7 @@ static async Task Execute()
9494
urlPath: "mail/send");
9595
Console.WriteLine(response.StatusCode);
9696
Console.WriteLine(response.Headers);
97-
Console.WriteLine("\n\nPress any key to continue.");
97+
Console.WriteLine("\n\nPress <Enter> to continue.");
9898
Console.ReadLine();
9999

100100
// GET Collection
@@ -107,7 +107,7 @@ static async Task Execute()
107107
Console.WriteLine(response.StatusCode);
108108
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
109109
Console.WriteLine(response.Headers);
110-
Console.WriteLine("\n\nPress any key to continue to POST.");
110+
Console.WriteLine("\n\nPress <Enter> to continue to POST.");
111111
Console.ReadLine();
112112

113113
// POST
@@ -124,7 +124,7 @@ static async Task Execute()
124124
Console.WriteLine(response.StatusCode);
125125
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
126126
Console.WriteLine(response.Headers);
127-
Console.WriteLine("\n\nPress any key to continue to GET single.");
127+
Console.WriteLine("\n\nPress <Enter> to continue to GET single.");
128128
Console.ReadLine();
129129

130130
if (ds_response != null && ds_response.ContainsKey("id"))
@@ -137,7 +137,7 @@ static async Task Execute()
137137
Console.WriteLine(response.StatusCode);
138138
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
139139
Console.WriteLine(response.Headers);
140-
Console.WriteLine("\n\nPress any key to continue to PATCH.");
140+
Console.WriteLine("\n\nPress <Enter> to continue to PATCH.");
141141
Console.ReadLine();
142142

143143

@@ -154,15 +154,15 @@ static async Task Execute()
154154
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
155155
Console.WriteLine(response.Headers.ToString());
156156

157-
Console.WriteLine("\n\nPress any key to continue to PUT.");
157+
Console.WriteLine("\n\nPress <Enter> to continue to PUT.");
158158
Console.ReadLine();
159159

160160
// DELETE
161161
response = await client.RequestAsync(method: SendGridClient.Method.DELETE,
162162
urlPath: string.Format("asm/groups/{0}", group_id));
163163
Console.WriteLine(response.StatusCode);
164164
Console.WriteLine(response.Headers.ToString());
165-
Console.WriteLine("\n\nPress any key to DELETE and exit.");
165+
Console.WriteLine("\n\nPress <Enter> to DELETE and exit.");
166166
Console.ReadLine();
167167
}
168168
}

SendGrid.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Global
2828
Release|Any CPU = Release|Any CPU
2929
EndGlobalSection
3030
GlobalSection(ProjectConfigurationPlatforms) = postSolution
31-
{377C20E4-2297-488F-933B-FB635C56D8FC}.Debug|Any CPU.ActiveCfg = Release|Any CPU
32-
{377C20E4-2297-488F-933B-FB635C56D8FC}.Debug|Any CPU.Build.0 = Release|Any CPU
31+
{377C20E4-2297-488F-933B-FB635C56D8FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{377C20E4-2297-488F-933B-FB635C56D8FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
3333
{377C20E4-2297-488F-933B-FB635C56D8FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
3434
{377C20E4-2297-488F-933B-FB635C56D8FC}.Release|Any CPU.Build.0 = Release|Any CPU
3535
{D89ADAEA-2BE8-49AC-B5BC-6EABBB2AE4E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

src/SendGrid/SendGridClient.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace SendGrid
99
using Newtonsoft.Json;
1010
using System;
1111
using System.Collections.Generic;
12-
using System.Linq;
1312
using System.Net;
1413
using System.Net.Http;
1514
using System.Net.Http.Headers;
@@ -24,7 +23,6 @@ namespace SendGrid
2423
public class SendGridClient
2524
{
2625
private readonly string version;
27-
// private readonly string urlPath;
2826
private readonly string mediaType;
2927
private HttpClient client;
3028

@@ -86,13 +84,13 @@ public SendGridClient(IWebProxy webProxy, string apiKey, string host = null, Dic
8684
{
8785
if (header.Key == "Authorization")
8886
{
89-
var split = header.Value.Split(new char[0]);
87+
var split = header.Value.Split();
9088
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(split[0], split[1]);
9189
}
9290
else if (header.Key == "Content-Type")
9391
{
9492
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(header.Value));
95-
this.mediaType = header.Value;
93+
mediaType = header.Value;
9694
}
9795
else
9896
{
@@ -152,7 +150,7 @@ public enum Method
152150
/// <returns>Authorization value to add to the header</returns>
153151
public virtual AuthenticationHeaderValue AddAuthorization(KeyValuePair<string, string> header)
154152
{
155-
string[] split = header.Value.Split(new char[0]);
153+
string[] split = header.Value.Split();
156154
return new AuthenticationHeaderValue(split[0], split[1]);
157155
}
158156

@@ -162,7 +160,7 @@ public virtual AuthenticationHeaderValue AddAuthorization(KeyValuePair<string, s
162160
/// <param name="request">The parameters for the API call</param>
163161
/// <param name="cancellationToken">Cancel the asynchronous call</param>
164162
/// <returns>Response object</returns>
165-
public async Task<Response> MakeRequest(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken))
163+
public async Task<Response> MakeRequest(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken))
166164
{
167165
HttpResponseMessage response = await client.SendAsync(request, cancellationToken);
168166
return new Response(response.StatusCode, response.Content, response.Headers);
@@ -187,6 +185,7 @@ public async Task<Response> RequestAsync(
187185
try
188186
{
189187
var endpoint = client.BaseAddress + BuildUrl(urlPath, queryParams);
188+
190189
// Build the request body
191190
StringContent content = null;
192191
if (requestBody != null)
@@ -220,7 +219,7 @@ public async Task<Response> RequestAsync(
220219
/// <returns>A Response object.</returns>
221220
public async Task<Response> SendEmailAsync(SendGridMessage msg, CancellationToken cancellationToken = default(CancellationToken))
222221
{
223-
return await this.RequestAsync(
222+
return await RequestAsync(
224223
Method.POST,
225224
msg.Serialize(),
226225
urlPath: "mail/send",

0 commit comments

Comments
 (0)