예제 #1
0
        public async Task WithThroughput()
        {
            Mock <ContainerResponse> mockContainerResponse = new Mock <ContainerResponse>();
            Mock <CosmosContainers>  mockContainers        = new Mock <CosmosContainers>();

            mockContainers
            .Setup(c => c.CreateContainerAsync(
                       It.IsAny <CosmosContainerSettings>(),
                       It.Is <int?>((rus) => rus == throughput),
                       It.IsAny <RequestOptions>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mockContainerResponse.Object);

            CosmosContainerFluentDefinitionForCreate CosmosContainerFluentDefinitionForCreate = new CosmosContainerFluentDefinitionForCreate(
                mockContainers.Object,
                containerName,
                partitionKey);

            await CosmosContainerFluentDefinitionForCreate
            .CreateAsync(2400);

            mockContainers.Verify(c => c.CreateContainerAsync(
                                      It.IsAny <CosmosContainerSettings>(),
                                      It.Is <int?>((rus) => rus == throughput),
                                      It.IsAny <RequestOptions>(),
                                      It.IsAny <CancellationToken>()), Times.Once);
        }
예제 #2
0
        public async Task MissingPKForCreateThrows()
        {
            Mock <CosmosContainers> mockContainers = new Mock <CosmosContainers>();

            CosmosContainerFluentDefinitionForCreate CosmosContainerFluentDefinitionForCreate = new CosmosContainerFluentDefinitionForCreate(
                mockContainers.Object,
                containerName,
                null);

            await CosmosContainerFluentDefinitionForCreate.CreateAsync();
        }
예제 #3
0
        public async Task MissingPKForReplace_CallsReadAsync()
        {
            Mock <ContainerResponse> mockContainerResponse = new Mock <ContainerResponse>();

            mockContainerResponse
            .Setup(c => c.Resource)
            .Returns(new CosmosContainerSettings()
            {
                PartitionKey = new Documents.PartitionKeyDefinition()
                {
                    Paths = new Collection <string>()
                    {
                        partitionKey
                    }
                }
            });

            Mock <CosmosContainer> mockContainer = new Mock <CosmosContainer>();

            mockContainer
            .Setup(c => c.ReadAsync(It.IsAny <ContainerRequestOptions>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(mockContainerResponse.Object);

            Mock <CosmosContainers> mockContainers = new Mock <CosmosContainers>();

            mockContainers
            .Setup(c => c.CreateContainerAsync(
                       It.Is <CosmosContainerSettings>((settings) => settings.PartitionKeyPath.Equals(partitionKey)),
                       It.IsAny <int?>(),
                       It.IsAny <RequestOptions>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mockContainerResponse.Object);

            mockContainers.Setup(c => c[containerName]).Returns(mockContainer.Object);

            CosmosContainerFluentDefinitionForCreate CosmosContainerFluentDefinitionForCreate = new CosmosContainerFluentDefinitionForCreate(
                mockContainers.Object,
                containerName,
                null);

            ContainerResponse response = await CosmosContainerFluentDefinitionForCreate.CreateAsync();

            mockContainer.Verify(c => c.ReadAsync(It.IsAny <ContainerRequestOptions>(), It.IsAny <CancellationToken>()), Times.Once);
        }