Skip to content

Commit

Permalink
Tests: Fixes Assert proper way (#4878)
Browse files Browse the repository at this point in the history
Tests: Fixes Assert proper way
  • Loading branch information
kirankumarkolli authored and kundadebdatta committed Nov 11, 2024
1 parent 852c542 commit 6e4a88f
Showing 1 changed file with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void ValidatePageSize(DocumentClient client)
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"Invalid status code: {innerException}");
}

headers = new Documents.Collections.RequestNameValueCollection
Expand All @@ -104,7 +104,7 @@ private void ValidatePageSize(DocumentClient client)
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"Invalid status code: {innerException}");
}

// Invalid value
Expand All @@ -121,7 +121,7 @@ private void ValidatePageSize(DocumentClient client)
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"Invalid status code: {innerException}");
}

headers = new Documents.Collections.RequestNameValueCollection();
Expand All @@ -135,7 +135,7 @@ private void ValidatePageSize(DocumentClient client)
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"Invalid status code: {innerException}");
}

// Valid page size
Expand Down Expand Up @@ -200,7 +200,7 @@ private async Task ValidateConsistencyLevel(DocumentClient client)
headers = new RequestNameValueCollection();
headers.Add(HttpConstants.HttpHeaders.ConsistencyLevel, ConsistencyLevel.Eventual.ToString());
var response = ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result;
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
}

[TestMethod]
Expand Down Expand Up @@ -238,7 +238,7 @@ private void ValidateJsonSerializationFormatReadFeed(DocumentClient client, Docu
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"invalid status code: {innerException}");
}

// Supported values
Expand All @@ -247,20 +247,20 @@ private void ValidateJsonSerializationFormatReadFeed(DocumentClient client, Docu
headers = new Documents.Collections.RequestNameValueCollection();
headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, ContentSerializationFormat.JsonText.ToString());
var response = ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result;
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue);

// None
headers = new Documents.Collections.RequestNameValueCollection();
response = ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result;
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue);

// Binary (Read feed should ignore all options)
headers = new Documents.Collections.RequestNameValueCollection();
headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, ContentSerializationFormat.CosmosBinary.ToString());
response = ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result;
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue);
//Assert.AreEqual(JsonSerializationFormat.Binary, response.ResponseBody.ReadByte());
}
Expand All @@ -280,7 +280,7 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"Invalid status code: {innerException}");
}

// Supported values
Expand All @@ -289,20 +289,20 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen
headers = new Documents.Collections.RequestNameValueCollection();
headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, ContentSerializationFormat.JsonText.ToString());
var response = QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers);
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue);

// None
headers = new Documents.Collections.RequestNameValueCollection();
response = QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers);
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue);

// Binary
headers = new Documents.Collections.RequestNameValueCollection();
headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, ContentSerializationFormat.CosmosBinary.ToString());
response = QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers);
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue);
}

Expand Down Expand Up @@ -364,8 +364,8 @@ private void SupportedSerializationFormatsNegativeCases(
if (isHttps)
{
// Invalid value is treated as default JsonText if HTTPS
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.IsTrue(this.CheckSerializationFormat(response) == JsonSerializationFormat.Text);
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
Assert.AreEqual(JsonSerializationFormat.Text, this.CheckSerializationFormat(response));
}
else
{
Expand All @@ -375,7 +375,7 @@ private void SupportedSerializationFormatsNegativeCases(
catch (Exception ex)
{
DocumentClientException innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"invalid status code {innerException}");
}
}

Expand All @@ -400,7 +400,7 @@ private void SupportedSerializationFormatsPositiveCases(
response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result;
}

Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");

if(expectedFormat == SupportedSerializationFormats.JsonText)
{
Expand Down Expand Up @@ -506,7 +506,7 @@ private void ValidateIndexingDirective(DocumentClient client)
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"invalid status code {innerException}");
}

headers = new Documents.Collections.RequestNameValueCollection();
Expand All @@ -520,7 +520,7 @@ private void ValidateIndexingDirective(DocumentClient client)
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"invalid status code {innerException}");
}

// Valid Indexing Directive
Expand All @@ -532,7 +532,7 @@ private void ValidateIndexingDirective(DocumentClient client)
headers = new Documents.Collections.RequestNameValueCollection();
headers.Add("indexAction", "\"exclude\"");
var result = CreateDocumentScript(client, headers);
Assert.IsTrue(result.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode, "Invalid status code");
}

[TestMethod]
Expand Down Expand Up @@ -565,20 +565,20 @@ private void ValidateEnableScanInQuery(DocumentClient client, bool isHttps = fal
else
{
// Invalid boolean is treated as false by TCP
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
}
}
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"invalid status code {innerException}");
}

// Valid boolean
headers = new Documents.Collections.RequestNameValueCollection();
headers.Add(HttpConstants.HttpHeaders.EnableScanInQuery, "true");
var response2 = ReadDatabaseFeedRequest(client, headers);
Assert.IsTrue(response2.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response2.StatusCode, "Invalid status code");
}

[TestMethod]
Expand Down Expand Up @@ -612,21 +612,21 @@ private void ValidateEnableLowPrecisionOrderBy(DocumentClient client, bool isHtt
else
{
// Invalid boolean is treated as false by TCP"
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
}
}
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, "Invalid status code");
}

// Valid boolean
document = CreateDocumentRequest(client, new Documents.Collections.RequestNameValueCollection()).GetResource<Document>();
headers = new Documents.Collections.RequestNameValueCollection();
headers.Add(HttpConstants.HttpHeaders.EnableLowPrecisionOrderBy, "true");
var response2 = ReadDocumentRequest(client, document, headers);
Assert.IsTrue(response2.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response2.StatusCode, "Invalid status code");
}

[TestMethod]
Expand Down Expand Up @@ -659,20 +659,20 @@ private void ValidateEmitVerboseTracesInQuery(DocumentClient client, bool isHttp
else
{
// Invalid boolean is treated as false by TCP
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Invalid status code");
}
}
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code");
Assert.AreEqual(HttpStatusCode.BadRequest, innerException.StatusCode, $"invalid status code {innerException}");
}

// Valid boolean
headers = new Documents.Collections.RequestNameValueCollection();
headers.Add(HttpConstants.HttpHeaders.EmitVerboseTracesInQuery, "true");
var response2 = ReadDatabaseFeedRequest(client, headers);
Assert.IsTrue(response2.StatusCode == HttpStatusCode.OK, "Invalid status code");
Assert.AreEqual(HttpStatusCode.OK, response2.StatusCode, "Invalid status code");
}

[TestMethod]
Expand Down Expand Up @@ -1061,7 +1061,7 @@ private void ValidateIfNonMatch(DocumentClient client)
var headers = new Documents.Collections.RequestNameValueCollection();
headers.Add(HttpConstants.HttpHeaders.IfNoneMatch, document.ETag);
var response = ReadDocumentRequest(client, document, headers);
Assert.IsTrue(response.StatusCode == HttpStatusCode.NotModified, "Invalid status code");
Assert.AreEqual(HttpStatusCode.NotModified, response.StatusCode, "Invalid status code");

// validateInvalidIfMatch
AccessCondition condition = new AccessCondition() { Type = AccessConditionType.IfMatch, Condition = "invalid etag" };
Expand All @@ -1073,7 +1073,7 @@ private void ValidateIfNonMatch(DocumentClient client)
catch (Exception ex)
{
var innerException = ex.InnerException as DocumentClientException;
Assert.IsTrue(innerException.StatusCode == HttpStatusCode.PreconditionFailed, "Invalid status code");
Assert.AreEqual(HttpStatusCode.PreconditionFailed, innerException.StatusCode, $"invalid status code {innerException}");
}
}

Expand Down

0 comments on commit 6e4a88f

Please sign in to comment.