public void ThenItShouldHaveAConsistentOrder() { var query = new CosmosQuery(CosmosCombinationOperator.And) .AddCondition("Name", DataOperator.Equals, "some-thing"); var queryOrderBy = query.ToString().Substring(query.ToString().Length - CosmosQueryTestConstants.OrderBy.Length); Assert.AreEqual(CosmosQueryTestConstants.OrderBy, queryOrderBy); }
public void ThenItShouldAddOffsetAndLimitToQuery() { var query = new CosmosQuery(CosmosCombinationOperator.And) .AddCondition("Name", DataOperator.Equals, "some-thing") .TakeResultsBetween(10, 50); var expectedOffsetLimit = $"OFFSET 10 LIMIT 50"; Assert.AreEqual(expectedOffsetLimit, query.ToString().Substring(query.ToString().Length - expectedOffsetLimit.Length)); }
public void ThenItShouldPrefixCountQueryWithSelectCount() { var query = new CosmosQuery(CosmosCombinationOperator.And) .AddCondition("Name", DataOperator.Equals, "some-thing"); Assert.AreEqual(CosmosQueryTestConstants.CountQueryPrefix, query.ToString(true).Substring(0, CosmosQueryTestConstants.CountQueryPrefix.Length)); }
public void ThenItShouldNotOrderByForCountQuery() { var query = new CosmosQuery(CosmosCombinationOperator.And) .AddCondition("Name", DataOperator.Equals, "some-thing"); var orderByIndex = query.ToString(true).IndexOf(CosmosQueryTestConstants.OrderBy, StringComparison.InvariantCultureIgnoreCase); Assert.AreEqual(-1, orderByIndex); }
public void ThenItShouldNotOffsetLimitForCountQuery() { var query = new CosmosQuery(CosmosCombinationOperator.And) .AddCondition("Name", DataOperator.Equals, "some-thing") .TakeResultsBetween(10, 50); var offsetLimitIndex = query.ToString(true).IndexOf("OFFSET 10 LIMIT 50", StringComparison.InvariantCultureIgnoreCase); Assert.AreEqual(-1, offsetLimitIndex); }
internal static string QueryWithoutOrderByOrSkip(CosmosQuery query) { var queryText = query.ToString(); var orderByIndex = queryText.IndexOf(OrderBy, StringComparison.InvariantCultureIgnoreCase); if (orderByIndex > -1) { queryText = queryText.Substring(0, orderByIndex).Trim(); } return(queryText); }