コード例 #1
0
        public async Task EnsureCreatedCreatesCollectionIfMissing()
        {
            // Arrange
            IOrderedQueryable <DocumentCollection> queryable = new EnumerableQuery <DocumentCollection>(new List <DocumentCollection>());

            _mockDocumentClient.Setup(x =>
                                      x.CreateDocumentCollectionQuery(It.IsAny <string>(), It.IsAny <FeedOptions>())).Returns(queryable);
            var collection = new DocumentCollection {
                Id = "collection"
            };
            var collectionResponse = collection.ToResourceResponse(HttpStatusCode.OK);
            var databaseUri        = UriFactory.CreateDatabaseUri("databaseName");

            _mockDocumentClient.Setup(x => x.CreateDocumentCollectionAsync(It.Is <Uri>(uri => uri == databaseUri),
                                                                           It.Is <DocumentCollection>(coll => coll.Id == collection.Id),
                                                                           It.IsAny <RequestOptions>())).ReturnsAsync(collectionResponse);

            var creator = new CosmosCollectionCreator(new CosmonautClient(_mockDocumentClient.Object));

            // Act
            var result = await creator.EnsureCreatedAsync <Dummy>("databaseName", collection.Id, 500, new JsonSerializerSettings());

            // Assert
            result.Should().BeTrue();
        }
コード例 #2
0
        public async Task CollectionCreator_CreatesCollectionWithThroughput_WhenThroughputIsPresent()
        {
            var databaseCreator   = new CosmosDatabaseCreator(_cosmonautClient);
            var collectionCreator = new CosmosCollectionCreator(_cosmonautClient);
            await databaseCreator.EnsureCreatedAsync(_databaseId);

            await collectionCreator.EnsureCreatedAsync <object>(_databaseId, _collectionName, 10000, new JsonSerializerSettings());

            var offer = await _cosmonautClient.GetOfferV2ForCollectionAsync(_databaseId, _collectionName);

            offer.Content.OfferThroughput.Should().Be(10000);
        }
コード例 #3
0
        public async Task CollectionCreator_CreatesCollectionWithDedicatedThroughput_WhenThroughputIsPresentOnDatabase()
        {
            var databaseCreator   = new CosmosDatabaseCreator(_cosmonautClient);
            var collectionCreator = new CosmosCollectionCreator(_cosmonautClient);
            await databaseCreator.EnsureCreatedAsync(_databaseId, 20000);

            await collectionCreator.EnsureCreatedAsync <Cat>(_databaseId, _collectionName, 10000, new JsonSerializerSettings(), onDatabaseBehaviour : ThroughputBehaviour.DedicateCollectionThroughput);

            var databaseOffer = await _cosmonautClient.GetOfferV2ForDatabaseAsync(_databaseId);

            var collectionOffer = await _cosmonautClient.GetOfferV2ForCollectionAsync(_databaseId, _collectionName);

            databaseOffer.Content.OfferThroughput.Should().Be(20000);
            collectionOffer.Content.OfferThroughput.Should().Be(10000);
        }