public void Given_Null_When_GetUrlItemEntityAsync_Invoked_Then_It_Should_Throw_Exception() { var helper = new Mock <ICosmosDbContainerHelper>(); var query = new CosmosDbQuery(helper.Object); Func <Task> func = async() => await query.GetUrlItemEntityAsync(null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); }
public async Task Given_Values_When_GetUrlItemEntityAsync_Invoked_Then_It_Should_Return_Null(string shortUrl) { 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.GetUrlItemEntityAsync(shortUrl).ConfigureAwait(false); result.Should().BeNull(); }
public async Task Given_Values_When_GetUrlItemEntityAsync_Invoked_Then_It_Should_Return_Result(string shortUrl) { var record = new UrlItemEntity() { ShortUrl = shortUrl }; var records = new List <UrlItemEntity>() { record }; 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.GetUrlItemEntityAsync(shortUrl).ConfigureAwait(false); result.Should().NotBeNull(); result.ShortUrl.Should().Be(shortUrl); }