Esempio n. 1
0
        private static CosmosContainer GetMockedContainer(string containerName = "myColl")
        {
            Mock <CosmosResultSetIterator <DocumentServiceLeaseCore> > mockedQuery = new Mock <CosmosResultSetIterator <DocumentServiceLeaseCore> >();

            mockedQuery.Setup(q => q.FetchNextSetAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => CosmosQueryResponse <DocumentServiceLeaseCore> .CreateResponse(DocumentServiceLeaseContainerCosmosTests.allLeases, string.Empty, false));
            mockedQuery.SetupSequence(q => q.HasMoreResults)
            .Returns(true)
            .Returns(false);

            Mock <CosmosItems> mockedItems = new Mock <CosmosItems>();

            mockedItems.Setup(i => i.CreateItemQuery <DocumentServiceLeaseCore>(
                                  // To make sure the SQL Query gets correctly created
                                  It.Is <string>(value => ("SELECT * FROM c WHERE STARTSWITH(c.id, '" + DocumentServiceLeaseContainerCosmosTests.leaseStoreManagerSettings.GetPartitionLeasePrefix() + "')").Equals(value)),
                                  It.IsAny <int>(),
                                  It.IsAny <int?>(),
                                  It.IsAny <string>(),
                                  It.IsAny <CosmosQueryRequestOptions>()))
            .Returns(() =>
            {
                return(mockedQuery.Object);
            });

            Mock <CosmosContainer> mockedContainer = new Mock <CosmosContainer>();

            //mockedContainer.Setup(c => c.LinkUri).Returns(new Uri("/dbs/myDb/colls/" + containerName, UriKind.Relative));
            //mockedContainer.Setup(c => c.Client).Returns(DocumentServiceLeaseContainerCosmosTests.GetMockedClient());
            mockedContainer.Setup(c => c.Items).Returns(mockedItems.Object);
            return(mockedContainer.Object);
        }
        internal static CosmosQueryResponse <TInput> CreateCosmosQueryFeedResponse <TInput>(
            CosmosResponseMessage cosmosResponseMessage,
            CosmosJsonSerializer jsonSerializer)
        {
            using (cosmosResponseMessage)
            {
                // Throw the exception if the query failed.
                cosmosResponseMessage.EnsureSuccessStatusCode();

                string continuationToken = ChangeFeedResultSetStreamIterator.GetContinuationToken(cosmosResponseMessage);
                bool   hasMoreResults    = ChangeFeedResultSetStreamIterator.GetHasMoreResults(continuationToken, cosmosResponseMessage.Headers.ContentLengthAsLong);

                return(CosmosQueryResponse <TInput> .CreateResponse <TInput>(
                           stream : cosmosResponseMessage.Content,
                           jsonSerializer : jsonSerializer,
                           continuationToken : continuationToken,
                           hasMoreResults : hasMoreResults));
            }
        }