Skip to content

Tests: Fixes Assert proper way #4878

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

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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