Пример #1
0
        public async Task QueryOffersAsync_WhenQueryingOffers_ThenAllOffersGetReturned()
        {
            // Arrange
            var collections = await _cosmonautClient.QueryCollectionsAsync(_databaseId);

            // Act
            var offers = await _cosmonautClient.QueryOffersAsync();

            // Assert
            collections.ToList().ForEach(collection =>
            {
                offers.Select(x => x.ResourceLink).Contains(collection.SelfLink).Should().BeTrue();
            });
        }
        public async Task <IEnumerable <CosmosDatabase> > GetDatabases([FromQuery] bool withCollections = false, [FromQuery] bool withOffers = false)
        {
            var databases = await _cosmonautClient.QueryDatabasesAsync();

            var cosmosDatabases = _mapper.Map <List <CosmosDatabase> >(databases);

            if (withCollections)
            {
                foreach (var database in databases)
                {
                    var collections = await _cosmonautClient.QueryCollectionsAsync(database.Id);

                    var cosmosCollections = _mapper.Map <IEnumerable <CosmosCollection> >(collections).ToList();
                    cosmosDatabases.Single(x => x.Id == database.Id).Collections = cosmosCollections;

                    if (withOffers)
                    {
                        foreach (var collection in cosmosCollections)
                        {
                            var offer = await _cosmonautClient.GetOfferV2ForCollectionAsync(database.Id, collection.Id);

                            collection.Offer = new CosmosOffer
                            {
                                Id = offer.Id, Throughput = offer.Content.OfferThroughput
                            };
                        }
                    }
                }
            }

            return(cosmosDatabases);
        }