public async Task InvokesPersistToBlobStoreWhenSuccessfullyCreated()
        {
            var entryContent = new EntryContentFixture().Build();
            var entry        = new ArticleEntry();
            var createMock   = new Mock <ICreateArticleEntryCoordinator>();
            var uploadMock   = new Mock <IUploadArticleEntryCoordinator>();
            var uploadUrl    = "someUrl";

            createMock.Setup(c => c.CreateArticleEntry(It.IsAny <Guid>(), It.IsAny <ArticleEntry>()))
            .ReturnsAsync(entryContent);

            createMock.Setup(c => c.MarkUploadSuccess(It.IsAny <EntryContent>(), It.IsAny <string>()))
            .ReturnsAsync(entryContent);

            uploadMock.Setup(u => u.UploadMarkdownArticleEntry(entryContent, It.IsAny <ArticleEntry>()))
            .ReturnsAsync(uploadUrl)
            .Verifiable();

            var persistArticleEntryStrategy = new CreateAndPersistArticleEntryStrategyFixture
            {
                CreateEntryCoordinator = createMock.Object,
                UploadCoordinator      = uploadMock.Object
            }.Build();

            var result = await persistArticleEntryStrategy.PersistArticleEntryAsync(Guid.NewGuid(), new ArticleEntry());

            uploadMock.VerifyAll();
            createMock.Verify(c => c.MarkUploadSuccess(entryContent, uploadUrl));
            Assert.Equal(entryContent, result);
        }
        public async Task ReturnsLatestEntryConvertedUrlDecodedIfExists()
        {
            var articleIdToFind = Guid.NewGuid();
            var urlToExpect     = "someUrl";

            var latestEntryContent = new EntryContentFixture
            {
                ArticleId        = articleIdToFind,
                ConvertedBlobUrl = StringUtilities.ToBase64(urlToExpect)
            }
            .Build();


            var mockGetLatestArticle = new Mock <IGetLatestArticleEntryStrategy>();

            mockGetLatestArticle.Setup(m => m.FindLatestEntry(articleIdToFind))
            .ReturnsAsync(latestEntryContent).Verifiable();

            var converterStrategy = new BogMarkdownConverterStrategyFixture
            {
                GetLatestArticleEntryStrategy = mockGetLatestArticle.Object
            }.Build();

            var result = await converterStrategy.GetLatestConvertedEntryContentUri(articleIdToFind);

            Assert.Equal(urlToExpect, result);
            mockGetLatestArticle.VerifyAll();
        }
        public async Task WillConvertAndSaveMdContentsIfStillOutstanding()
        {
            var articleIdToFind      = Guid.NewGuid();
            var mdUrl                = "someMdUrl";
            var urlToExpect          = "someUrl";
            var mockConvertedContent = "someContent";

            var latestEntryContent = new EntryContentFixture
            {
                ArticleId        = articleIdToFind,
                BlobUrl          = StringUtilities.ToBase64(mdUrl),
                ConvertedBlobUrl = string.Empty
            }
            .Build();

            var mockGetLatestArticle = new Mock <IGetLatestArticleEntryStrategy>();

            mockGetLatestArticle.Setup(m => m.FindLatestEntry(articleIdToFind))
            .ReturnsAsync(latestEntryContent).Verifiable();

            var mockMarkdownConverter = new Mock <IBogMarkdownConverter>();

            mockMarkdownConverter.Setup(m => m.ConvertArticle(articleIdToFind, mdUrl))
            .ReturnsAsync(mockConvertedContent).Verifiable();

            var mockUploadArticleEntryCoordinator = new Mock <IUploadArticleEntryCoordinator>();

            mockUploadArticleEntryCoordinator
            .Setup(m => m.UploadConvertedArticleEntry(latestEntryContent, mockConvertedContent))
            .ReturnsAsync(urlToExpect).Verifiable();

            var mockBlogApiDbContextFixture = new MockBlogApiDbContextFixture();

            var converterStrategy = new BogMarkdownConverterStrategyFixture
            {
                GetLatestArticleEntryStrategy = mockGetLatestArticle.Object,
                BogMarkdownConverter          = mockMarkdownConverter.Object,
                UploadArticleEntryCoordinator = mockUploadArticleEntryCoordinator.Object,
                Context = mockBlogApiDbContextFixture.Build()
            }.Build();

            var result = await converterStrategy.GetLatestConvertedEntryContentUri(articleIdToFind);

            Assert.Equal(urlToExpect, result);

            mockGetLatestArticle.VerifyAll();
            mockMarkdownConverter.VerifyAll();
            mockUploadArticleEntryCoordinator.VerifyAll();
            mockBlogApiDbContextFixture.Mock.Verify(m => m.Attach(latestEntryContent), Times.Once);
            mockBlogApiDbContextFixture.Mock.Verify(m => m.SaveChanges(), Times.Once);
        }
        private static EntryContent BuildTestSetup(ArticleEntry articleEntry, out string base64, out Mock <IBlobStore> mock,
                                                   out UploadArticleEntryCoordinator coordinator)
        {
            base64 = string.IsNullOrWhiteSpace(articleEntry.Content)? "foo" : StringUtilities.ToBase64(articleEntry.Content);
            var entryContent     = new EntryContentFixture().Build();
            var blobStoreFixture = new BlobStoreFixture();

            mock = blobStoreFixture.Mock;
            var uploadFixture = new UploadArticleEntryCoordinatorFixture
            {
                BlobStore = blobStoreFixture.Build()
            };

            coordinator = uploadFixture.Build();
            return(entryContent);
        }
        public async Task UpdatesAndPersistsEntryContentOnUpload()
        {
            var entryContent     = new EntryContentFixture().Build();
            var blobUrl          = "http://somewhere";
            var blobUrlBase64    = StringUtilities.ToBase64(blobUrl);
            var mockClock        = new MockClock();
            var dbContextFixture = new MockBlogApiDbContextFixture();
            var createArticleEntryCoordinator = new CreateArticleEntryCoordinatorFixture
            {
                Context = dbContextFixture.Build(),
                Clock   = mockClock
            }.Build();

            var resultEntryContent = await createArticleEntryCoordinator.MarkUploadSuccess(entryContent, blobUrl);

            Assert.Equal(blobUrlBase64, resultEntryContent.BlobUrl);

            dbContextFixture.Mock.Verify(ctx => ctx.Attach(entryContent));
            dbContextFixture.Mock.Verify(ctx => ctx.SaveChanges());
        }
示例#6
0
        public async Task ReturnsNullWhenEntryNotFound()
        {
            var articleEntry     = new EntryContentFixture().Build();
            var dbContextFixture = new MockBlogApiDbContextFixture();

            dbContextFixture.Mock.Setup(ctx => ctx.Find <EntryContent>(It.IsAny <Guid>()))
            .ReturnsAsync(() => null);

            var coordinator = new CreateEntryMediaCoordinatorFixture
            {
                Context = dbContextFixture.Build()
            }.Build();

            var result = await coordinator.CreateArticleEntryMedia(new ArticleEntryMediaRequest
            {
                EntryId = articleEntry.Id
            });

            Assert.Null(result);
            dbContextFixture.Mock.Verify(ctx => ctx.Find <EntryContent>(articleEntry.Id));
        }
示例#7
0
        public async Task CreatesNewEntryMediaWhenEntryFound()
        {
            var articleEntry = new EntryContentFixture().Build();
            var request      = new ArticleEntryMediaRequest
            {
                FileName      = "testFile",
                ContentType   = "image/png",
                EntryId       = articleEntry.Id,
                MD5Base64Hash = "1234",
                MediaContent  = Enumerable.Empty <byte>().ToArray()
            };
            var mockClock        = new MockClock();
            var dbContextFixture = new MockBlogApiDbContextFixture();

            dbContextFixture.Mock
            .Setup(ctx => ctx.Find <EntryContent>(It.IsAny <Guid>()))
            .ReturnsAsync(() => articleEntry);

            var coordinator = new CreateEntryMediaCoordinatorFixture
            {
                Context = dbContextFixture.Build(),
                Clock   = mockClock
            }.Build();

            var result = await coordinator.CreateArticleEntryMedia(request);

            Assert.Equal(articleEntry.Id, result.EntryContentId);
            Assert.Equal(request.FileName, result.FileName);
            Assert.Equal(request.ContentType, result.ContentType);
            Assert.Equal(request.MD5Base64Hash, result.MD5Base64Hash);
            Assert.Equal(mockClock.Now, result.Created);

            dbContextFixture.Mock.Verify(ctx => ctx.Find <EntryContent>(articleEntry.Id));
            dbContextFixture.Mock.Verify(ctx => ctx.Add(result));
            dbContextFixture.Mock.Verify(ctx => ctx.SaveChanges());
        }