Skip to content

Commit

Permalink
Merge pull request #751 from dixong/compilerwarnings
Browse files Browse the repository at this point in the history
Update to remove compiler warnings based on stylecop/xunit
  • Loading branch information
thinkingserious authored Oct 5, 2018
2 parents afdcd5a + 56fbeb7 commit d7b22ee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/SendGrid/Helpers/Mail/SendGridMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,9 +1332,11 @@ public void SetAsm(int groupID, List<int> groupsToDisplay = null)
{
this.Asm = new ASM();
this.Asm.GroupId = groupID;
if (groupsToDisplay != null) {
if (groupsToDisplay != null)
{
this.Asm.GroupsToDisplay = groupsToDisplay;
}

return;
}

Expand Down
23 changes: 14 additions & 9 deletions src/SendGrid/SendGridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using SendGrid.Helpers.Mail;
using SendGrid.Helpers.Reliability;
using System;
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -272,11 +272,11 @@ private string BuildUrl(string urlPath, string queryParams = null)

if (queryParams != null)
{
var ds_query_params = ParseJson(queryParams);
var ds_query_params = this.ParseJson(queryParams);
string query = "?";
foreach (var pair in ds_query_params)
{
foreach(var element in pair.Value)
foreach (var element in pair.Value)
{
if (query != "?")
{
Expand Down Expand Up @@ -358,30 +358,34 @@ private void InitiateClient(string apiKey, string host, Dictionary<string, strin
/// </summary>
/// <remarks>
/// This function flattens all Objects/Array.
/// This means that for example <code>{'id': 1, 'id': 2, 'id': 3}</code> and
/// This means that for example <code>{'id': 1, 'id': 2, 'id': 3}</code> and
/// <code>{'id': [1, 2, 3]}</code> result in the same output.
/// </remarks>
/// <param name="json">The JSON string to parse.</param>
/// <returns>A dictionary of all values.</returns>
private Dictionary<string, List<object>> ParseJson(string json)
{
var dict = new Dictionary<string, List<object>>();
using(var sr = new StringReader(json))
using(var reader = new JsonTextReader(sr))

using (var sr = new StringReader(json))
using (var reader = new JsonTextReader(sr))
{
var propertyName = "";
var propertyName = string.Empty;
while (reader.Read())
{
switch (reader.TokenType)
{
case JsonToken.PropertyName:
{
propertyName = reader.Value.ToString();
if(!dict.ContainsKey(propertyName))
if (!dict.ContainsKey(propertyName))
{
dict.Add(propertyName, new List<object>());
}

break;
}

case JsonToken.Boolean:
case JsonToken.Integer:
case JsonToken.Float:
Expand All @@ -395,6 +399,7 @@ private Dictionary<string, List<object>> ParseJson(string json)
}
}
}

return dict;
}
}
Expand Down
11 changes: 6 additions & 5 deletions tests/SendGrid.Tests/Helpers/Mail/SendGridMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void SendGridMessage_AddAttachment_Should_Add_Single_Attachment_To_Attach
sut.AddAttachment(filename, content, type, disposition, contentId);

// Assert
Assert.Equal(1, sut.Attachments.Count);
Assert.Single(sut.Attachments);

var attachment = sut.Attachments.First();

Expand All @@ -57,6 +57,7 @@ public void SendGridMessage_AddAttachment_Should_Add_Single_Attachment_To_Attach
Assert.Equal(contentId, attachment.ContentId);
}

[Fact]
public void SendGridMessage_AddAttachment_Doesnt_Touch_Attachment_Passed_In()
{
// Arrange
Expand All @@ -81,7 +82,7 @@ public void SendGridMessage_AddAttachment_Doesnt_Touch_Attachment_Passed_In()
sut.AddAttachment(attachment);

// Assert
Assert.Equal(1, sut.Attachments.Count);
Assert.Single(sut.Attachments);

var addedAttachment = sut.Attachments.First();

Expand Down Expand Up @@ -163,7 +164,7 @@ public void SendGridMessage_AddAttachments_Doesnt_Touch_Attachments_Passed_In()
sut.AddAttachments(attachments);

// Assert
Assert.Equal(1, sut.Attachments.Count);
Assert.Single(sut.Attachments);

var addedAttachment = sut.Attachments.First();

Expand Down Expand Up @@ -209,7 +210,7 @@ public async Task SendGridMessage_AddAttachmentAsync_Adds_Base64_Content_Of_Stre
await sut.AddAttachmentAsync("filename", stream);

// Assert
Assert.Equal(1, sut.Attachments.Count);
Assert.Single(sut.Attachments);

var attachment = sut.Attachments.First();

Expand Down Expand Up @@ -269,7 +270,7 @@ public async Task SendGridMessage_AddAttachmentAsync_Should_Add_Single_Attachmen
await sut.AddAttachmentAsync(filename, contentStream, type, disposition, contentId);

// Assert
Assert.Equal(1, sut.Attachments.Count);
Assert.Single(sut.Attachments);

var addedAttachment = sut.Attachments.First();

Expand Down
2 changes: 1 addition & 1 deletion tests/SendGrid.Tests/Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6001,7 +6001,7 @@ public async Task TestWhenHttpCallTimesOutThenExceptionIsThrown()

// If we are certain that we don't want custom exceptions to be thrown,
// we can also test that the original exception was thrown
Assert.IsType(typeof(TimeoutException), thrownException);
Assert.IsType<TimeoutException>(thrownException);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task ShouldReturnHttpResponseAndNotRetryWhenSuccessful()

var result = await client.SendAsync(new HttpRequestMessage());

Assert.Equal(result.StatusCode, HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
Assert.Equal(1, innerHandler.InvocationCount);
}

Expand All @@ -43,7 +43,7 @@ public async Task ShouldReturnHttpResponseAndNotRetryWhenUnauthorised()

var result = await client.SendAsync(new HttpRequestMessage());

Assert.Equal(result.StatusCode, HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode);
Assert.Equal(1, innerHandler.InvocationCount);
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public async Task ShouldRetryOnceWhenFailedOnFirstAttemptThenSuccessful()

var result = await client.SendAsync(new HttpRequestMessage());

Assert.Equal(result.StatusCode, HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
Assert.Equal(2, innerHandler.InvocationCount);
}

Expand Down

0 comments on commit d7b22ee

Please sign in to comment.