コード例 #1
0
        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>();
        }
コード例 #2
0
        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>();
        }
コード例 #3
0
        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();
        }