public void ShouldNotCallHandleIfDiscussionNotExist()
        {
            dbSetDiscussion.Setup(x => x.FindAsync(id)).Returns(null);
            context.Setup(x => x.Discussions).Returns(dbSetDiscussion.Object);

            OpenDiscussionCommandHandler openDiscussionCommandHandler = new OpenDiscussionCommandHandler(context.Object, stringLocalizer.Object);
            OpenDiscussionCommand        openDiscussionCommand        = new OpenDiscussionCommand(id);

            Func <Task> act = async() => await openDiscussionCommandHandler.Handle(openDiscussionCommand, new CancellationToken());

            act.Should().ThrowAsync <NotFoundException>();
        }
        public void ShouldNotCallHandleIfNotSavedChanges()
        {
            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(0));

            OpenDiscussionCommandHandler openDiscussionCommandHandler = new OpenDiscussionCommandHandler(context.Object, stringLocalizer.Object);
            OpenDiscussionCommand        openDiscussionCommand        = new OpenDiscussionCommand(id);

            Func <Task> act = async() => await openDiscussionCommandHandler.Handle(openDiscussionCommand, new CancellationToken());

            act.Should().ThrowAsync <RestException>();
        }
        public async Task ShouldCallHandle()
        {
            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));

            OpenDiscussionCommandHandler openDiscussionCommandHandler = new OpenDiscussionCommandHandler(context.Object, stringLocalizer.Object);
            OpenDiscussionCommand        openDiscussionCommand        = new OpenDiscussionCommand(id);

            var result = await openDiscussionCommandHandler.Handle(openDiscussionCommand, new CancellationToken());

            result.Should().Be(Unit.Value);
            discussion.IsClosed.Should().BeFalse();
        }