-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(bunq/sdk_csharp#63) add response id to failed request #73
(bunq/sdk_csharp#63) add response id to failed request #73
Conversation
caughtException = e; | ||
} | ||
|
||
Assert.NotNull(caughtException); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will not need this first assert @OGKevin , also it is a good practice to keep unit tests with a single assertion. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove this first assertion and caughtException
turns out to be null, the code will break on the next line due to NullReferenceException
. Rather have the test fails correctly instead of due to an unhandled exception.
The good practice of one assertion per test is not always practical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a valid point @OGKevin , plus one can say you are being more 'defensive' this way.
BunqSdk/Http/ApiClient.cs
Outdated
); | ||
} | ||
|
||
private static string GetResponsId(HttpHeaders allHeader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in method name
BunqSdk/Http/ApiClient.cs
Outdated
|
||
private static string GetResponsId(HttpHeaders allHeader) | ||
{ | ||
if (allHeader.Contains(HEADER_RESPONSE_ID_UPPER_CASE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a method could be extracted here to avoid the conditional expressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cant seem to picture how an extracted method will prevent these conditional lines 🤔. Could you please provide a snippet with what you mean ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OGKevin something like:
private static string GetResponseId(HttpHeaders allHeader, IEnumerable<string> allHeaderResponse)
{
foreach (var headerResponse in allHeaderResponse)
{
if (allHeader.Contains(headerResponse))
{
return allHeader.GetValues(headerResponse).First();
}
}
throw new BunqException(ERROR_COULD_NOT_DETERMINE_RESPONSE_ID_HEADER);
}
Actually... the loop brings needed extra complexity, in this case. Maybe it is better to stick with the conditional statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think it is indeed better if we stick to the conditional statements! 👍
BunqSdk/Exception/ApiException.cs
Outdated
@@ -4,12 +4,16 @@ namespace Bunq.Sdk.Exception | |||
public class ApiException : System.Exception | |||
{ | |||
public int ResponseCode { get; private set; } | |||
public string ResponsId { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in property
@epels all yours please 👀 |
/// <summary> | ||
/// API context to use for the test API calls. | ||
/// </summary> | ||
private static readonly ApiContext API_CONTEXT = GetApiContext(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UpperCamelCase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be refactored in #58
/// <summary> | ||
/// Invalid user id to trigger BadRequestException | ||
/// </summary> | ||
private const int INVALID_USER_PERSON_ID = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UpperCamelCase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be refactored in #58
[Fact] | ||
public void TestBadRequestWithResponseId() | ||
{ | ||
ApiException caughtException = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Assert.Throws()
@@ -2,7 +2,8 @@ | |||
{ | |||
public class BadRequestException : ApiException | |||
{ | |||
public BadRequestException(int responseCode, string message) : base(responseCode, message) | |||
public BadRequestException(int responseCode, string message, string responseId) : | |||
base(responseCode, message, responseId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd choose to move the :
to the new line (like here)
@@ -18,37 +18,49 @@ public class ExceptionFactory | |||
/// <summary> | |||
/// Glue to concatenate the error messages. | |||
/// </summary> | |||
private const string GLUE_ERROR_MESSAGES = "\n"; | |||
private const string SEPARATOR_ERROR_MESSAGES = "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UpperCamelCase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be refactored in #58
BunqSdk/Http/ApiClient.cs
Outdated
responseCode, | ||
responseBody, | ||
GetResponseId(responseMessage.Headers) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unindent the closing parenthese
BunqSdk/Http/ApiClient.cs
Outdated
); | ||
} | ||
|
||
private static string GetResponseId(HttpHeaders allHeader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetResponseIdByAllHeader
(/DetermineResponseIdByAllHeader
)?
BunqSdk/Http/ApiClient.cs
Outdated
int responseCode, | ||
string responseBody, | ||
string responseId | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation
BunqSdk/Http/ApiClient.cs
Outdated
responseCode, | ||
FetchErrorDescriptions(responseBody), | ||
responseId | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unindent closing parenthese
BunqSdk/Http/ApiClient.cs
Outdated
responseCode, | ||
new List<string> {responseBody}, | ||
responseId | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unindent closing parenthese
b855651
to
7cb55ae
Compare
|
||
/// <returns>The exception that belongs to this status code.</returns> | ||
public static ApiException CreateExceptionForResponse( | ||
int responseCode, | ||
IList<string> messages, | ||
IEnumerable<string> messages, | ||
string responseId | ||
) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this open brace go on the same line as the close parenthese?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is ? 😁
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline at EOF
BunqSdk/Http/ApiClient.cs
Outdated
if (allHeader.Contains(HEADER_RESPONSE_ID_UPPER_CASE)) | ||
{ | ||
return allHeader.GetValues(HEADER_RESPONSE_ID_UPPER_CASE).First(); | ||
} else if (allHeader.Contains(HEADER_RESPONSE_ID_LOWER_CASE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c# code style is rusty, by why the }
on same line.
BunqSdk/Http/ApiClient.cs
Outdated
} else if (allHeader.Contains(HEADER_RESPONSE_ID_LOWER_CASE)) | ||
{ | ||
return allHeader.GetValues(HEADER_RESPONSE_ID_LOWER_CASE).First(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing else
@andrederoos merging! |
Closes #63