Exemplo n.º 1
0
        public async Task AddBlogPostCommandHandler_AddsBlog()
        {
            var imageService              = TestContext.CreateImageService();
            var builder                   = new BlogPostBuilder(_authorService, imageService);
            var handlerContext            = TestContext.CreateHandlerContext <BlogPostSummaryViewModel>(RequestDbContext, CreateMapper());
            var addBlogPostCommandHandler = new AddBlogPostCommandHandler(handlerContext, builder);
            var category                  = await RequestDbContext.Categories.FirstOrDefaultAsync();

            var addBlogPostCommand = new AddBlogPostCommand()
            {
                Subject      = "Test",
                ContentIntro = "Test",
                Content      = "Test",
                CategoryId   = category.Id
            };

            var result = await addBlogPostCommandHandler.Handle(addBlogPostCommand, CancellationToken.None);

            Assert.InRange(result.Id, 1, int.MaxValue);
            Assert.Equal(category.Name, result.Category);
        }
Exemplo n.º 2
0
        public async Task AddBlogPostCommandHandler_WithFile_AddsBlog()
        {
            var mapper         = CreateMapper();
            var imageFactory   = TestContext.CreateImageService();
            var builder        = new BlogPostBuilder(_authorService, imageFactory);
            var handlerContext = TestContext.CreateHandlerContext <BlogPostSummaryViewModel>(RequestDbContext, mapper);
            var handler        = new AddBlogPostCommandHandler(handlerContext, builder);
            var fileMock       = TestContext.CreateFileMock();
            var file           = fileMock.Object;
            var category       = await RequestDbContext.Categories.FirstOrDefaultAsync();

            var message = new AddBlogPostCommand()
            {
                Subject      = "Test",
                Content      = "Test",
                ContentIntro = "Test",
                File         = file,
                CategoryId   = category.Id
            };

            var result = await handler.Handle(message, CancellationToken.None);

            Assert.NotNull(result.Image.UriPath);
        }