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

            mockContainers
            .Setup(c => c.CreateContainerAsync(
                       It.Is <CosmosContainerSettings>((settings) => settings.UniqueKeyPolicy.UniqueKeys.Count == 1 && path.Equals(settings.UniqueKeyPolicy.UniqueKeys[0].Paths[0])),
                       It.IsAny <int?>(),
                       It.IsAny <RequestOptions>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mockContainerResponse.Object);

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

            await CosmosContainerFluentDefinitionForCreate
            .WithUniqueKey()
            .Path(path)
            .Attach()
            .CreateAsync();

            mockContainers.Verify(c => c.CreateContainerAsync(
                                      It.Is <CosmosContainerSettings>((settings) => settings.UniqueKeyPolicy.UniqueKeys.Count == 1 && path.Equals(settings.UniqueKeyPolicy.UniqueKeys[0].Paths[0])),
                                      It.IsAny <int?>(),
                                      It.IsAny <RequestOptions>(),
                                      It.IsAny <CancellationToken>()), Times.Once);
        }
예제 #2
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);
        }
예제 #3
0
        public async Task WithIndexingPolicy()
        {
            Mock <ContainerResponse> mockContainerResponse = new Mock <ContainerResponse>();
            Mock <CosmosContainers>  mockContainers        = new Mock <CosmosContainers>();

            mockContainers
            .Setup(c => c.CreateContainerAsync(
                       It.Is <CosmosContainerSettings>((settings) => IndexingMode.None.Equals(settings.IndexingPolicy.IndexingMode) && !settings.IndexingPolicy.Automatic),
                       It.IsAny <int?>(),
                       It.IsAny <RequestOptions>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mockContainerResponse.Object);

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

            await CosmosContainerFluentDefinitionForCreate
            .WithIndexingPolicy()
            .WithIndexingMode(IndexingMode.None)
            .WithAutomaticIndexing(false)
            .Attach()
            .CreateAsync();

            mockContainers.Verify(c => c.CreateContainerAsync(
                                      It.Is <CosmosContainerSettings>((settings) => IndexingMode.None.Equals(settings.IndexingPolicy.IndexingMode) && !settings.IndexingPolicy.Automatic),
                                      It.IsAny <int?>(),
                                      It.IsAny <RequestOptions>(),
                                      It.IsAny <CancellationToken>()), Times.Once);
        }
예제 #4
0
        public async Task WithDefaultTimeToLiveInt()
        {
            Mock <ContainerResponse> mockContainerResponse = new Mock <ContainerResponse>();
            Mock <CosmosContainers>  mockContainers        = new Mock <CosmosContainers>();

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

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

            await CosmosContainerFluentDefinitionForCreate
            .WithDefaultTimeToLive((int)timeToLive.TotalSeconds)
            .CreateAsync();

            mockContainers.Verify(c => c.CreateContainerAsync(
                                      It.Is <CosmosContainerSettings>((settings) => settings.DefaultTimeToLive.Equals((int)timeToLive.TotalSeconds)),
                                      It.IsAny <int?>(),
                                      It.IsAny <RequestOptions>(),
                                      It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task WithTimeToLivePropertyPath()
        {
            Mock <ContainerResponse> mockContainerResponse = new Mock <ContainerResponse>();
            Mock <CosmosDatabase>    mockContainers        = new Mock <CosmosDatabase>();

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

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

            await CosmosContainerFluentDefinitionForCreate
            .WithTimeToLivePropertyPath(path)
            .CreateAsync();

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

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

            await CosmosContainerFluentDefinitionForCreate.CreateAsync();
        }
예제 #7
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);
        }