Skip to content

Commit

Permalink
Unit tests added for client error exception constructors of type (Enu…
Browse files Browse the repository at this point in the history
…m errorCode, string field, string message, string helpUrl)
  • Loading branch information
jlahteen committed Apr 18, 2019
1 parent 943ddef commit 963ef39
Show file tree
Hide file tree
Showing 19 changed files with 817 additions and 0 deletions.
Expand Up @@ -488,6 +488,49 @@ public void ThrowAndSerialize_BadRequestException11_ShouldReturn()
AssertExceptions(exception1, exception2);
}

[TestMethod]
public void ThrowAndSerialize_BadRequestException12_ShouldReturn()
{
ClientErrorResponse clientErrorResponse1, clientErrorResponse2;
BadRequestException exception1 = null, exception2 = null;

try
{
throw new BadRequestException(ErrorCode.InvalidOrderNumber, "Field.CustomerName", "The field content is not valid. Please consult the help URL!", "http://juhta.net/helpurls/125533");
}

catch (BadRequestException ex)
{
AssertException(
ex,
"ThrowAndSerialize_BadRequestException11_ShouldReturn",
HttpStatusCode.BadRequest,
ErrorCode.InvalidOrderNumber.ToString(),
"The field content is not valid. Please consult the help URL!",
"Field.CustomerName",
"http://juhta.net/helpurls/125533"
);

clientErrorResponse1 = ex.ToClientErrorResponse();

exception1 = ex;
}

clientErrorResponse2 = JsonConvert.DeserializeObject<ClientErrorResponse>(JsonConvert.SerializeObject(clientErrorResponse1));

try
{
clientErrorResponse2.Throw();
}

catch (BadRequestException ex)
{
exception2 = ex;
}

AssertExceptions(exception1, exception2);
}

#endregion
}
}
Expand Up @@ -488,6 +488,49 @@ public void ThrowAndSerialize_ConflictException11_ShouldReturn()
AssertExceptions(exception1, exception2);
}

[TestMethod]
public void ThrowAndSerialize_ConflictException12_ShouldReturn()
{
ClientErrorResponse clientErrorResponse1, clientErrorResponse2;
ConflictException exception1 = null, exception2 = null;

try
{
throw new ConflictException(ErrorCode.InvalidOrderNumber, "Field.CustomerName", "The field content is not valid. Please consult the help URL!", "http://juhta.net/helpurls/125533");
}

catch (ConflictException ex)
{
AssertException(
ex,
"ThrowAndSerialize_ConflictException11_ShouldReturn",
HttpStatusCode.Conflict,
ErrorCode.InvalidOrderNumber.ToString(),
"The field content is not valid. Please consult the help URL!",
"Field.CustomerName",
"http://juhta.net/helpurls/125533"
);

clientErrorResponse1 = ex.ToClientErrorResponse();

exception1 = ex;
}

clientErrorResponse2 = JsonConvert.DeserializeObject<ClientErrorResponse>(JsonConvert.SerializeObject(clientErrorResponse1));

try
{
clientErrorResponse2.Throw();
}

catch (ConflictException ex)
{
exception2 = ex;
}

AssertExceptions(exception1, exception2);
}

#endregion
}
}
Expand Up @@ -488,6 +488,49 @@ public void ThrowAndSerialize_ExpectationFailedException11_ShouldReturn()
AssertExceptions(exception1, exception2);
}

[TestMethod]
public void ThrowAndSerialize_ExpectationFailedException12_ShouldReturn()
{
ClientErrorResponse clientErrorResponse1, clientErrorResponse2;
ExpectationFailedException exception1 = null, exception2 = null;

try
{
throw new ExpectationFailedException(ErrorCode.InvalidOrderNumber, "Field.CustomerName", "The field content is not valid. Please consult the help URL!", "http://juhta.net/helpurls/125533");
}

catch (ExpectationFailedException ex)
{
AssertException(
ex,
"ThrowAndSerialize_ExpectationFailedException11_ShouldReturn",
HttpStatusCode.ExpectationFailed,
ErrorCode.InvalidOrderNumber.ToString(),
"The field content is not valid. Please consult the help URL!",
"Field.CustomerName",
"http://juhta.net/helpurls/125533"
);

clientErrorResponse1 = ex.ToClientErrorResponse();

exception1 = ex;
}

clientErrorResponse2 = JsonConvert.DeserializeObject<ClientErrorResponse>(JsonConvert.SerializeObject(clientErrorResponse1));

try
{
clientErrorResponse2.Throw();
}

catch (ExpectationFailedException ex)
{
exception2 = ex;
}

AssertExceptions(exception1, exception2);
}

#endregion
}
}
Expand Up @@ -488,6 +488,49 @@ public void ThrowAndSerialize_ForbiddenException11_ShouldReturn()
AssertExceptions(exception1, exception2);
}

[TestMethod]
public void ThrowAndSerialize_ForbiddenException12_ShouldReturn()
{
ClientErrorResponse clientErrorResponse1, clientErrorResponse2;
ForbiddenException exception1 = null, exception2 = null;

try
{
throw new ForbiddenException(ErrorCode.InvalidOrderNumber, "Field.CustomerName", "The field content is not valid. Please consult the help URL!", "http://juhta.net/helpurls/125533");
}

catch (ForbiddenException ex)
{
AssertException(
ex,
"ThrowAndSerialize_ForbiddenException11_ShouldReturn",
HttpStatusCode.Forbidden,
ErrorCode.InvalidOrderNumber.ToString(),
"The field content is not valid. Please consult the help URL!",
"Field.CustomerName",
"http://juhta.net/helpurls/125533"
);

clientErrorResponse1 = ex.ToClientErrorResponse();

exception1 = ex;
}

clientErrorResponse2 = JsonConvert.DeserializeObject<ClientErrorResponse>(JsonConvert.SerializeObject(clientErrorResponse1));

try
{
clientErrorResponse2.Throw();
}

catch (ForbiddenException ex)
{
exception2 = ex;
}

AssertExceptions(exception1, exception2);
}

#endregion
}
}
Expand Up @@ -488,6 +488,49 @@ public void ThrowAndSerialize_GoneException11_ShouldReturn()
AssertExceptions(exception1, exception2);
}

[TestMethod]
public void ThrowAndSerialize_GoneException12_ShouldReturn()
{
ClientErrorResponse clientErrorResponse1, clientErrorResponse2;
GoneException exception1 = null, exception2 = null;

try
{
throw new GoneException(ErrorCode.InvalidOrderNumber, "Field.CustomerName", "The field content is not valid. Please consult the help URL!", "http://juhta.net/helpurls/125533");
}

catch (GoneException ex)
{
AssertException(
ex,
"ThrowAndSerialize_GoneException11_ShouldReturn",
HttpStatusCode.Gone,
ErrorCode.InvalidOrderNumber.ToString(),
"The field content is not valid. Please consult the help URL!",
"Field.CustomerName",
"http://juhta.net/helpurls/125533"
);

clientErrorResponse1 = ex.ToClientErrorResponse();

exception1 = ex;
}

clientErrorResponse2 = JsonConvert.DeserializeObject<ClientErrorResponse>(JsonConvert.SerializeObject(clientErrorResponse1));

try
{
clientErrorResponse2.Throw();
}

catch (GoneException ex)
{
exception2 = ex;
}

AssertExceptions(exception1, exception2);
}

#endregion
}
}
Expand Up @@ -488,6 +488,49 @@ public void ThrowAndSerialize_LengthRequiredException11_ShouldReturn()
AssertExceptions(exception1, exception2);
}

[TestMethod]
public void ThrowAndSerialize_LengthRequiredException12_ShouldReturn()
{
ClientErrorResponse clientErrorResponse1, clientErrorResponse2;
LengthRequiredException exception1 = null, exception2 = null;

try
{
throw new LengthRequiredException(ErrorCode.InvalidOrderNumber, "Field.CustomerName", "The field content is not valid. Please consult the help URL!", "http://juhta.net/helpurls/125533");
}

catch (LengthRequiredException ex)
{
AssertException(
ex,
"ThrowAndSerialize_LengthRequiredException11_ShouldReturn",
HttpStatusCode.LengthRequired,
ErrorCode.InvalidOrderNumber.ToString(),
"The field content is not valid. Please consult the help URL!",
"Field.CustomerName",
"http://juhta.net/helpurls/125533"
);

clientErrorResponse1 = ex.ToClientErrorResponse();

exception1 = ex;
}

clientErrorResponse2 = JsonConvert.DeserializeObject<ClientErrorResponse>(JsonConvert.SerializeObject(clientErrorResponse1));

try
{
clientErrorResponse2.Throw();
}

catch (LengthRequiredException ex)
{
exception2 = ex;
}

AssertExceptions(exception1, exception2);
}

#endregion
}
}
Expand Up @@ -488,6 +488,49 @@ public void ThrowAndSerialize_MethodNotAllowedException11_ShouldReturn()
AssertExceptions(exception1, exception2);
}

[TestMethod]
public void ThrowAndSerialize_MethodNotAllowedException12_ShouldReturn()
{
ClientErrorResponse clientErrorResponse1, clientErrorResponse2;
MethodNotAllowedException exception1 = null, exception2 = null;

try
{
throw new MethodNotAllowedException(ErrorCode.InvalidOrderNumber, "Field.CustomerName", "The field content is not valid. Please consult the help URL!", "http://juhta.net/helpurls/125533");
}

catch (MethodNotAllowedException ex)
{
AssertException(
ex,
"ThrowAndSerialize_MethodNotAllowedException11_ShouldReturn",
HttpStatusCode.MethodNotAllowed,
ErrorCode.InvalidOrderNumber.ToString(),
"The field content is not valid. Please consult the help URL!",
"Field.CustomerName",
"http://juhta.net/helpurls/125533"
);

clientErrorResponse1 = ex.ToClientErrorResponse();

exception1 = ex;
}

clientErrorResponse2 = JsonConvert.DeserializeObject<ClientErrorResponse>(JsonConvert.SerializeObject(clientErrorResponse1));

try
{
clientErrorResponse2.Throw();
}

catch (MethodNotAllowedException ex)
{
exception2 = ex;
}

AssertExceptions(exception1, exception2);
}

#endregion
}
}
Expand Up @@ -488,6 +488,49 @@ public void ThrowAndSerialize_NotAcceptableException11_ShouldReturn()
AssertExceptions(exception1, exception2);
}

[TestMethod]
public void ThrowAndSerialize_NotAcceptableException12_ShouldReturn()
{
ClientErrorResponse clientErrorResponse1, clientErrorResponse2;
NotAcceptableException exception1 = null, exception2 = null;

try
{
throw new NotAcceptableException(ErrorCode.InvalidOrderNumber, "Field.CustomerName", "The field content is not valid. Please consult the help URL!", "http://juhta.net/helpurls/125533");
}

catch (NotAcceptableException ex)
{
AssertException(
ex,
"ThrowAndSerialize_NotAcceptableException11_ShouldReturn",
HttpStatusCode.NotAcceptable,
ErrorCode.InvalidOrderNumber.ToString(),
"The field content is not valid. Please consult the help URL!",
"Field.CustomerName",
"http://juhta.net/helpurls/125533"
);

clientErrorResponse1 = ex.ToClientErrorResponse();

exception1 = ex;
}

clientErrorResponse2 = JsonConvert.DeserializeObject<ClientErrorResponse>(JsonConvert.SerializeObject(clientErrorResponse1));

try
{
clientErrorResponse2.Throw();
}

catch (NotAcceptableException ex)
{
exception2 = ex;
}

AssertExceptions(exception1, exception2);
}

#endregion
}
}

0 comments on commit 963ef39

Please sign in to comment.