public async Task ReadByLeaseTypeAsync_WhenQueryHasResult_ShouldReturnLease()
        {
            // Arrange
            var lease = new CosmosDbLease
            {
                Id        = Guid.NewGuid().ToString(),
                LeaseType = "leasetype"
            };

            var response = new FeedResponse <CosmosDbLease>(new [] { lease });

            var mockDocumentQuery = new Mock <IMockDocumentQuery <CosmosDbLease> >();

            mockDocumentQuery
            .SetupSequence(m => m.HasMoreResults)
            .Returns(true);

            mockDocumentQuery
            .Setup(_ => _.ExecuteNextAsync <CosmosDbLease>(It.IsAny <CancellationToken>()))
            .ReturnsAsync(response).Verifiable();

            var provider = new Mock <IQueryProvider>();

            provider
            .Setup(_ => _.CreateQuery <CosmosDbLease>(It.IsAny <Expression>()))
            .Returns(mockDocumentQuery.Object);

            mockDocumentQuery.As <IQueryable <CosmosDbLease> >().Setup(x => x.Provider).Returns(provider.Object);
            mockDocumentQuery.As <IQueryable <CosmosDbLease> >().Setup(x => x.Expression).Returns(new CosmosDbLease[] { }.AsQueryable().Expression);
            mockDocumentQuery.As <IQueryable <CosmosDbLease> >().Setup(x => x.ElementType).Returns(typeof(CosmosDbLease));

            _mockDocumentClient.Setup(m => m.CreateDocumentQuery <CosmosDbLease>(
                                          It.Is <Uri>(u => u == UriFactory.CreateDocumentCollectionUri(_options.Database, _options.LeasesCollection)),
                                          It.IsAny <FeedOptions>())).Returns(mockDocumentQuery.Object);

            // Act
            var result = await _store.ReadByLeaseTypeAsync(lease.LeaseType);

            // Assert
            result.Should().Be(lease);
            mockDocumentQuery.Verify();
        }
        public async Task TestTryUpdateLeaseAsyncSuccess()
        {
            // Arrange
            CosmosDbLease lease = new CosmosDbLease
            {
                Id = Guid.NewGuid().ToString()
            };

            _mockDocumentClient.Setup(m => m.ReplaceDocumentAsync(
                                          It.IsAny <Uri>(),
                                          It.IsAny <object>(),
                                          It.IsAny <RequestOptions>(),
                                          CancellationToken.None))
            .ReturnsAsync(new Document().ToResourceResponse(HttpStatusCode.OK));

            // Act
            var result = await _store.TryUpdateLeaseAsync(lease);

            // Assert
            result.Result.Should().BeTrue();
        }
        public async Task TestTryUpdateLeaseAsyncFailed()
        {
            // Arrange
            CosmosDbLease lease = new CosmosDbLease
            {
                Id = Guid.NewGuid().ToString()
            };

            _mockDocumentClient.Setup(m => m.ReplaceDocumentAsync(
                                          It.IsAny <Uri>(),
                                          It.IsAny <object>(),
                                          It.IsAny <RequestOptions>(),
                                          CancellationToken.None))
            .ThrowsAsync(CreateDocumentClientExceptionForTesting(string.Empty, new Exception(),
                                                                 HttpStatusCode.Conflict));

            // Act
            var result = await _store.TryUpdateLeaseAsync(lease);

            // Assert
            result.Result.Should().BeFalse();
        }