Skip to content

Commit

Permalink
combine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maya-Painter committed Sep 5, 2023
1 parent 3c428e1 commit a935fc5
Showing 1 changed file with 6 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ async Task TestSearch(Expression<Func<ToDoActivity, bool>> expression, string ex
}

[TestMethod]
public async Task LinqCountWithContinuationTokenTest()
public async Task LinqAggregatesWithContinuationTokenTest()
{
await ToDoActivity.CreateRandomItems(container: this.Container, pkCount: 1, perPKItemCount: 2, randomPartitionKey: true);

Expand Down Expand Up @@ -909,67 +909,32 @@ public async Task LinqCountWithContinuationTokenTest()
Assert.AreEqual(2, count);
Assert.IsNotNull(continuationToken);

IOrderedQueryable<ToDoActivity> secondQuery = this.Container.GetItemLinqQueryable<ToDoActivity>(continuationToken: continuationToken, requestOptions: requestOptions);
IOrderedQueryable<ToDoActivity> secondQuery = this.Container.GetItemLinqQueryable<ToDoActivity>(allowSynchronousQueryExecution: true, continuationToken: continuationToken, requestOptions: requestOptions);

try
{
count = await secondQuery.CountAsync();
Assert.Fail("Expected Count query to return exception");
}
catch (CosmosException exception)
{
Assert.IsTrue(exception.StatusCode == System.Net.HttpStatusCode.BadRequest);
Assert.IsTrue(exception.SubStatusCode == (int)Documents.SubStatusCodes.MalformedContinuationToken);
Assert.IsTrue(exception.Message.Contains("ParallelCrossPartitionQueryPipelineStage"));
return;
}

Assert.Fail("Expect Count query to return exception");
}

[TestMethod]
public async Task LinqAverageWithContinuationTokenTest()
{
await ToDoActivity.CreateRandomItems(container: this.Container, pkCount: 1, perPKItemCount: 2, randomPartitionKey: true);

QueryRequestOptions requestOptions = new QueryRequestOptions()
{
MaxItemCount = 1
};

IOrderedQueryable<ToDoActivity> firstQuery = this.Container.GetItemLinqQueryable<ToDoActivity>(allowSynchronousQueryExecution: true, requestOptions: requestOptions);

double average = firstQuery.Average(x => x.taskNum);

string continuationToken = null;

FeedIterator<ToDoActivity> firstFeedIterator = firstQuery.ToFeedIterator();

// if instead of while loop in order to retrieve continuation token
if (firstFeedIterator.HasMoreResults)
{
FeedResponse<ToDoActivity> firstFeedResponse = await firstFeedIterator.ReadNextAsync();

continuationToken = firstFeedResponse.ContinuationToken;
}

Assert.IsNotNull(continuationToken);

IOrderedQueryable<ToDoActivity> secondQuery = this.Container.GetItemLinqQueryable<ToDoActivity>(allowSynchronousQueryExecution: true, continuationToken: continuationToken, requestOptions: requestOptions);

try
{
average = secondQuery.Average(x => x.taskNum);
secondQuery.Average(x => x.taskNum);
Assert.Fail("Expected Average query to return exception");
}
catch (CosmosException exception)
{
Assert.IsTrue(exception.StatusCode == System.Net.HttpStatusCode.BadRequest);
Assert.IsTrue(exception.SubStatusCode == (int)Documents.SubStatusCodes.MalformedContinuationToken);
Assert.IsTrue(exception.Message.Contains("ParallelCrossPartitionQueryPipelineStage"));
return;
}

Assert.Fail("Expect Average query to return exception");
}
}

[TestMethod]
public async Task LinqSelectEverythingWithoutQueryableTest()
Expand Down

0 comments on commit a935fc5

Please sign in to comment.