Exemplo n.º 1
0
        public async Task CreateIfNotExists_SetsPartitionKey_IfSpecified()
        {
            // Arrange
            string partitionKeyPath = "partitionKey";
            var    mockService      = new Mock <ICosmosDBService>(MockBehavior.Strict);
            var    context          = CosmosDBTestUtility.CreateContext(mockService.Object, partitionKeyPath: partitionKeyPath);

            CosmosDBTestUtility.SetupDatabaseMock(mockService);
            CosmosDBTestUtility.SetupCollectionMock(mockService, partitionKeyPath);

            // Act
            await CosmosDBUtility.CreateDatabaseAndCollectionIfNotExistAsync(context);

            // Assert
            mockService.VerifyAll();
        }
Exemplo n.º 2
0
        public async Task CreateIfNotExist_Rethrows()
        {
            // Arrange
            var             mockService = new Mock <ICosmosDBService>(MockBehavior.Strict);
            CosmosDBContext context     = CosmosDBTestUtility.CreateContext(mockService.Object);

            CosmosDBTestUtility.SetupDatabaseMock(mockService);

            // overwrite the default setup with one that throws
            mockService
            .Setup(m => m.CreateDatabaseIfNotExistsAsync(It.Is <Database>(d => d.Id == CosmosDBTestUtility.DatabaseName)))
            .ThrowsAsync(CosmosDBTestUtility.CreateDocumentClientException(HttpStatusCode.BadRequest));

            // Act
            await Assert.ThrowsAsync <DocumentClientException>(
                () => CosmosDBUtility.CreateDatabaseAndCollectionIfNotExistAsync(context));

            // Assert
            mockService.VerifyAll();
        }