Example #1
0
        public async Task FeedRangePK_GetPartitionKeyRangesAsync()
        {
            Documents.Routing.Range <string> range             = new Documents.Routing.Range <string>("AA", "BB", true, false);
            Documents.PartitionKeyRange      partitionKeyRange = new Documents.PartitionKeyRange()
            {
                Id = Guid.NewGuid().ToString(), MinInclusive = range.Min, MaxExclusive = range.Max
            };
            Documents.PartitionKeyDefinition partitionKeyDefinition = new Documents.PartitionKeyDefinition();
            partitionKeyDefinition.Paths.Add("/id");
            PartitionKey partitionKey = new PartitionKey("test");

            Routing.IRoutingMapProvider routingProvider = Mock.Of <Routing.IRoutingMapProvider>();
            Mock.Get(routingProvider)
            .Setup(f => f.TryGetOverlappingRangesAsync(It.IsAny <string>(), It.IsAny <Documents.Routing.Range <string> >(), It.IsAny <bool>()))
            .ReturnsAsync(new List <Documents.PartitionKeyRange>()
            {
                partitionKeyRange
            });

            FeedRangePartitionKey feedRangePartitionKey = new FeedRangePartitionKey(partitionKey);
            IEnumerable <string>  pkRanges = await feedRangePartitionKey.GetPartitionKeyRangesAsync(routingProvider, null, partitionKeyDefinition, default(CancellationToken));

            Assert.AreEqual(1, pkRanges.Count());
            Assert.AreEqual(partitionKeyRange.Id, pkRanges.First());
        }
Example #2
0
        public async Task FeedRangePKRangeId_GetEffectiveRangesAsync_Null()
        {
            Documents.PartitionKeyRange partitionKeyRange = new Documents.PartitionKeyRange()
            {
                Id = Guid.NewGuid().ToString(), MinInclusive = "AA", MaxExclusive = "BB"
            };
            FeedRangePartitionKeyRange feedRangePartitionKeyRange = new FeedRangePartitionKeyRange(partitionKeyRange.Id);

            Routing.IRoutingMapProvider routingProvider = Mock.Of <Routing.IRoutingMapProvider>();
            Mock.Get(routingProvider)
            .SetupSequence(f => f.TryGetPartitionKeyRangeByIdAsync(It.IsAny <string>(), It.IsAny <string>(), It.Is <bool>(b => true)))
            .ReturnsAsync((Documents.PartitionKeyRange)null)
            .ReturnsAsync((Documents.PartitionKeyRange)null);
            List <Documents.Routing.Range <string> > ranges = await feedRangePartitionKeyRange.GetEffectiveRangesAsync(routingProvider, null, null);
        }
Example #3
0
        public async Task FeedRangePKRangeId_GetEffectiveRangesAsync()
        {
            Documents.PartitionKeyRange partitionKeyRange = new Documents.PartitionKeyRange()
            {
                Id = Guid.NewGuid().ToString(), MinInclusive = "AA", MaxExclusive = "BB"
            };
            FeedRangePartitionKeyRange feedRangePartitionKeyRange = new FeedRangePartitionKeyRange(partitionKeyRange.Id);

            Routing.IRoutingMapProvider routingProvider = Mock.Of <Routing.IRoutingMapProvider>();
            Mock.Get(routingProvider)
            .Setup(f => f.TryGetPartitionKeyRangeByIdAsync(It.IsAny <string>(), It.Is <string>(s => s == partitionKeyRange.Id), It.IsAny <bool>()))
            .ReturnsAsync(partitionKeyRange);
            List <Documents.Routing.Range <string> > ranges = await feedRangePartitionKeyRange.GetEffectiveRangesAsync(routingProvider, null, null);

            Assert.AreEqual(1, ranges.Count);
            Assert.AreEqual(partitionKeyRange.ToRange().Min, ranges[0].Min);
            Assert.AreEqual(partitionKeyRange.ToRange().Max, ranges[0].Max);
        }
Example #4
0
        public async Task FeedRangePKRangeId_GetEffectiveRangesAsync_Null()
        {
            Documents.PartitionKeyRange partitionKeyRange = new Documents.PartitionKeyRange()
            {
                Id = Guid.NewGuid().ToString(), MinInclusive = "AA", MaxExclusive = "BB"
            };
            FeedRangePartitionKeyRange feedRangePartitionKeyRange = new FeedRangePartitionKeyRange(partitionKeyRange.Id);

            Routing.IRoutingMapProvider routingProvider = Mock.Of <Routing.IRoutingMapProvider>();
            Mock.Get(routingProvider)
            .SetupSequence(f => f.TryGetPartitionKeyRangeByIdAsync(It.IsAny <string>(), It.IsAny <string>(), It.Is <bool>(b => true)))
            .ReturnsAsync((Documents.PartitionKeyRange)null)
            .ReturnsAsync((Documents.PartitionKeyRange)null);
            CosmosException exception = await Assert.ThrowsExceptionAsync <CosmosException>(() => feedRangePartitionKeyRange.GetEffectiveRangesAsync(routingProvider, null, null));

            Assert.AreEqual(HttpStatusCode.Gone, exception.StatusCode);
            Assert.AreEqual((int)Documents.SubStatusCodes.PartitionKeyRangeGone, exception.SubStatusCode);
        }