public void Given_Null_When_GetUrlItemEntityCollectionAsync_Invoked_Then_It_Should_Throw_Exception() { var helper = new Mock <ICosmosDbContainerHelper>(); var query = new CosmosDbQuery(helper.Object); Func <Task> func = async() => await query.GetUrlItemEntityCollectionAsync(null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); }
public async Task Given_Values_When_GetUrlItemEntityCollectionAsync_Invoked_Then_It_Should_Return_Result(string owner) { var records = new List <UrlItemEntity>() { new UrlItemEntity() { ShortUrl = "helloworld", Owner = owner, DateGenerated = DateTimeOffset.UtcNow.AddHours(-1) }, new UrlItemEntity() { ShortUrl = "loremipsum", Owner = owner, DateGenerated = DateTimeOffset.UtcNow.AddHours(-2) } }; var feed = new Mock <FeedResponse <UrlItemEntity> >(); feed.SetupGet(p => p.Resource).Returns(records); feed.Setup(p => p.GetEnumerator()).Returns(records.GetEnumerator()); var iterator = new Mock <FeedIterator <UrlItemEntity> >(); iterator.SetupSequence(p => p.HasMoreResults) .Returns(true) .Returns(false); iterator.Setup(p => p.ReadNextAsync(It.IsAny <CancellationToken>())).ReturnsAsync(feed.Object); var container = new Mock <Container>(); container.Setup(p => p.GetItemQueryIterator <UrlItemEntity>(It.IsAny <QueryDefinition>(), It.IsAny <string>(), It.IsAny <QueryRequestOptions>())) .Returns(iterator.Object); var helper = new Mock <ICosmosDbContainerHelper>(); helper.Setup(p => p.GetContainerAsync()).ReturnsAsync(container.Object); var query = new CosmosDbQuery(helper.Object); var result = await query.GetUrlItemEntityCollectionAsync(owner).ConfigureAwait(false); result.Should().NotBeNull(); result.Items.Should().HaveCount(records.Count); result.Items.All(p => p.Owner == owner).Should().BeTrue(); }
public async Task Given_Values_When_GetUrlItemEntityCollectionAsync_Invoked_Then_It_Should_Return_Null(string owner) { var iterator = new Mock <FeedIterator <UrlItemEntity> >(); iterator.SetupGet(p => p.HasMoreResults).Returns(false); var container = new Mock <Container>(); container.Setup(p => p.GetItemQueryIterator <UrlItemEntity>(It.IsAny <QueryDefinition>(), It.IsAny <string>(), It.IsAny <QueryRequestOptions>())) .Returns(iterator.Object); var helper = new Mock <ICosmosDbContainerHelper>(); helper.Setup(p => p.GetContainerAsync()).ReturnsAsync(container.Object); var query = new CosmosDbQuery(helper.Object); var result = await query.GetUrlItemEntityCollectionAsync(owner).ConfigureAwait(false); result.Items.Should().HaveCount(0); }