예제 #1
0
        public async Task CallsDownToQueryIfArticleDoesExist()
        {
            var articleIdToLookup = Guid.NewGuid();
            var articleToBuildFor = new ArticleFixture
            {
                Id = articleIdToLookup
            }.Build();

            var mockMapping = new Dictionary <string, string>();
            var mockContextWithNoArticles = new MockBlogApiDbContextFixture();

            mockContextWithNoArticles.Mock.Setup(m => m.Find <Article>(articleIdToLookup)).ReturnsAsync(articleToBuildFor);

            var mockQuery = new Mock <IGetMediaLookupQuery>();

            mockQuery.Setup(m => m.CreateMediaLookup(articleIdToLookup)).Returns(mockMapping);

            var blogArticleCoordinatorFixture = new FindBlogArticleCoordinatorFixture
            {
                Context = mockContextWithNoArticles.Build(),
            };

            var lookupStrategy = new GetArticleMediaLookupStrategyFixture
            {
                FindBlogArticleCoordinator = blogArticleCoordinatorFixture.Build(),
                MediaLookupQuery           = mockQuery.Object
            }.Build();

            var result = await lookupStrategy.GetMediaLookup(articleIdToLookup);

            Assert.Equal(mockMapping, result.MediaLookup);

            mockQuery.Verify(m => m.CreateMediaLookup(articleIdToLookup), Times.Once);
        }
예제 #2
0
        public async Task DoesNotCallDownToQueryIfArticleDoesNotExist()
        {
            var articleIdToLookup         = Guid.NewGuid();
            var mockContextWithNoArticles = new MockBlogApiDbContextFixture();

            mockContextWithNoArticles.Mock.Setup(m => m.Find <Article>(articleIdToLookup)).ReturnsAsync(null as Article);

            var mockQuery = new Mock <IGetMediaLookupQuery>();

            mockQuery.Setup(m => m.CreateMediaLookup(articleIdToLookup));

            var blogArticleCoordinatorFixture = new FindBlogArticleCoordinatorFixture
            {
                Context = mockContextWithNoArticles.Build(),
            };

            var lookupStrategy = new GetArticleMediaLookupStrategyFixture
            {
                FindBlogArticleCoordinator = blogArticleCoordinatorFixture.Build(),
                MediaLookupQuery           = mockQuery.Object
            }.Build();

            var result = await lookupStrategy.GetMediaLookup(articleIdToLookup);

            Assert.Null(result);
            mockQuery.Verify(m => m.CreateMediaLookup(articleIdToLookup), Times.Never);
        }
        public async Task ReturnsNullWhenNoArticleFound(Guid articleId, Article expectedArticle = null)
        {
            var contextFixture = new MockBlogApiDbContextFixture();

            contextFixture.Mock.Setup(m => m.Find <Article>(articleId)).Returns(Task.FromResult(expectedArticle));

            var coordinator = new FindBlogArticleCoordinatorFixture
            {
                Context = contextFixture.Build()
            }.Build();

            var result = await coordinator.Find(articleId);

            contextFixture.Mock.Verify(m => m.Find <Article>(articleId));

            if (expectedArticle == null)
            {
                Assert.Null(result);
                return;
            }

            Assert.Equal(expectedArticle, result);
        }
 public GetArticleMediaLookupStrategyFixture()
 {
     FindBlogArticleCoordinator = new FindBlogArticleCoordinatorFixture().Build();
     MediaLookupQuery           = new GetMediaLookupQueryFixture().Build();
 }