示例#1
0
        public async Task CreationOfNotExistingDatabaseReturnTrue()
        {
            // Arrange
            var databaseName     = "test";
            var expectedDatabase = new Database {
                Id = databaseName
            };
            var mockDocumentClient = new Mock <IDocumentClient>();

            mockDocumentClient.Setup(x => x.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(databaseName), It.IsAny <RequestOptions>()))
            .ReturnsAsync(((Database)null).ToResourceResponse(HttpStatusCode.NotFound));
            mockDocumentClient.Setup(x => x.CreateDatabaseAsync(It.IsAny <Database>(), It.IsAny <RequestOptions>()))
            .ReturnsAsync(expectedDatabase.ToResourceResponse(HttpStatusCode.OK));
            var databaseCreator          = new CosmosDatabaseCreator(mockDocumentClient.Object);
            var databaseCreatorCosmonaut = new CosmosDatabaseCreator(new CosmonautClient(mockDocumentClient.Object));

            // Act
            var created = await databaseCreator.EnsureCreatedAsync(databaseName);

            var createdCosmonaut = await databaseCreatorCosmonaut.EnsureCreatedAsync(databaseName);

            // Assert
            created.Should().BeTrue();
            createdCosmonaut.Should().BeTrue();
        }
示例#2
0
        public async Task DatabaseCreator_CreatesDatabaseWithThroughput_WhenThroughputIsPresent()
        {
            var databaseCreator = new CosmosDatabaseCreator(_cosmonautClient);

            var created = await databaseCreator.EnsureCreatedAsync(_databaseId, 10000);

            var offer = await _cosmonautClient.GetOfferV2ForDatabaseAsync(_databaseId);

            created.Should().BeTrue();
            offer.Content.OfferThroughput.Should().Be(10000);
        }
示例#3
0
        public async Task DatabaseCreator_CreatesDatabaseWithoutThroughput_WhenThroughputNull()
        {
            var databaseCreator = new CosmosDatabaseCreator(_cosmonautClient);

            var created = await databaseCreator.EnsureCreatedAsync(_databaseId);

            var offer = await _cosmonautClient.GetOfferV2ForDatabaseAsync(_databaseId);

            created.Should().BeTrue();
            offer.Should().BeNull();
        }
示例#4
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);
        }
示例#5
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);
        }
        public async Task CreationOfNotExistingDatabaseReturnTrue()
        {
            // Arrange
            var databaseName     = "test";
            var expectedDatabase = new Database {
                Id = databaseName
            };
            var orderQueriable = new EnumerableQuery <Database>(new List <Database>());

            var mockDocumentClient = new Mock <IDocumentClient>();

            mockDocumentClient.Setup(x => x.CreateDatabaseQuery(null)).Returns(orderQueriable);
            mockDocumentClient.Setup(x => x.CreateDatabaseAsync(It.IsAny <Database>(), It.IsAny <RequestOptions>()))
            .ReturnsAsync(new ResourceResponse <Database>(expectedDatabase));
            var databaseCreator = new CosmosDatabaseCreator(mockDocumentClient.Object);

            // Act
            var created = await databaseCreator.EnsureCreatedAsync(databaseName);

            // Assert
            Assert.True(created);
        }
        public async Task CreationOfExistingDatabaseReturnsFalse()
        {
            // Arrange
            var databaseName     = "test";
            var expectedDatabase = new Database {
                Id = databaseName
            };
            var orderQueriable = new EnumerableQuery <Database>(new List <Database> {
                expectedDatabase
            });

            var mockDocumentClient = new Mock <IDocumentClient>();

            mockDocumentClient.Setup(x => x.CreateDatabaseQuery(null)).Returns(orderQueriable);
            var databaseCreator = new CosmosDatabaseCreator(mockDocumentClient.Object);

            // Act
            var created = await databaseCreator.EnsureCreatedAsync(databaseName);

            // Assert
            Assert.False(created);
        }