public void ShouldNotCallHandleIfDiscussionNotExist() { dbSetDiscussion.Setup(x => x.FindAsync(id)).Returns(null); context.Setup(x => x.Discussions).Returns(dbSetDiscussion.Object); CloseDiscussionCommandHandler closeDiscussionCommandHandler = new CloseDiscussionCommandHandler(context.Object, stringLocalizer.Object); CloseDiscussionCommand closeDiscussionCommand = new CloseDiscussionCommand(id); Func <Task> act = async() => await closeDiscussionCommandHandler.Handle(closeDiscussionCommand, new CancellationToken()); act.Should().ThrowAsync <NotFoundException>(); }
public void ShouldNotCallHandleIfDiscussionIsClosed() { discussion.IsClosed = true; dbSetDiscussion.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Discussion>(Task.FromResult(discussion))); context.Setup(x => x.Discussions).Returns(dbSetDiscussion.Object); CloseDiscussionCommandHandler closeDiscussionCommandHandler = new CloseDiscussionCommandHandler(context.Object, stringLocalizer.Object); CloseDiscussionCommand closeDiscussionCommand = new CloseDiscussionCommand(id); Func <Task> act = async() => await closeDiscussionCommandHandler.Handle(closeDiscussionCommand, new CancellationToken()); act.Should().ThrowAsync <RestException>(); }
public async Task ShouldCallHandle() { discussion.IsClosed = false; dbSetDiscussion.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Discussion>(Task.FromResult(discussion))); context.Setup(x => x.Discussions).Returns(dbSetDiscussion.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1)); CloseDiscussionCommandHandler closeDiscussionCommandHandler = new CloseDiscussionCommandHandler(context.Object, stringLocalizer.Object); CloseDiscussionCommand closeDiscussionCommand = new CloseDiscussionCommand(id); var result = await closeDiscussionCommandHandler.Handle(closeDiscussionCommand, new CancellationToken()); result.Should().Be(Unit.Value); discussion.IsClosed.Should().BeTrue(); }