Exemple #1
0
        public async Task Handler_Should_ReturnExceptionResult_WhenSaveChangesError()
        {
            BlogUnitOfWorkMock.Setup(m => m.SaveChangesAsync(It.IsAny <CancellationToken>())).ReturnsAsync(Result <int> .Fail(new ApplicationException("Error: SaveChangesAsync")));

            var result = await Mediator.Send(new UnpublishPostCommand { Id = _postId });

            result.IsSuccess.Should().BeFalse();
            result.Exception.Should().BeOfType <ApplicationException>();
        }
        public async Task Handler_Should_ReturnExceptionResult_WhenSaveChangesError()
        {
            BlogSettingsRepositoryMock.Setup(m => m.SingleOrDefaultAsync(It.IsAny <CancellationToken>())).ReturnsAsync(default(BlogSettings));

            BlogUnitOfWorkMock.Setup(m => m.SaveChangesAsync(It.IsAny <CancellationToken>())).ReturnsAsync(Result <int> .Fail(new ApplicationException("Error: SaveChangesAsync")));

            var result = await Mediator.Send(new UpdateBlogSettingsCommand
            {
                Title = "blog title-NEW",
            });

            result.IsSuccess.Should().BeFalse();
            result.Exception.Should().BeOfType <ApplicationException>();
        }
Exemple #3
0
        public async Task Handler_Should_ReturnExceptionResult_WhenSaveChangesError()
        {
            BlogUnitOfWorkMock.Setup(m => m.SaveChangesAsync(It.IsAny <CancellationToken>())).ReturnsAsync(Result <int> .Fail(new ApplicationException("Error: SaveChangesAsync")));

            var result = await Mediator.Send(new AddPostCommand
            {
                UserName    = "******",
                Categories  = "category",
                Title       = "title",
                Content     = "content",
                Description = "description"
            });

            result.IsSuccess.Should().BeFalse();
            result.Exception.Should().BeOfType <ApplicationException>();
        }