public void ShouldNotCallHandleIfPostNotExist() { dbSetPost.Setup(x => x.FindAsync(id)).Returns(null); context.Setup(x => x.Posts).Returns(dbSetPost.Object); UnpinPostCommandHandler unpinPostCommandHandler = new UnpinPostCommandHandler(context.Object, stringLocalizer.Object); UnpinPostCommand unpinPostCommand = new UnpinPostCommand(id); Func <Task> act = async() => await unpinPostCommandHandler.Handle(unpinPostCommand, new CancellationToken()); act.Should().Throw <NotFoundException>(); }
public void ShouldNotCallHandleIfNotSavedChanges() { dbSetPost.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Post>(Task.FromResult(post))); context.Setup(x => x.Posts).Returns(dbSetPost.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(0)); UnpinPostCommandHandler unpinPostCommandHandler = new UnpinPostCommandHandler(context.Object, stringLocalizer.Object); UnpinPostCommand unpinPostCommand = new UnpinPostCommand(id); Func <Task> act = async() => await unpinPostCommandHandler.Handle(unpinPostCommand, new CancellationToken()); act.Should().Throw <RestException>(); }
public async Task ShouldCallHandle() { dbSetPost.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Post>(Task.FromResult(post))); context.Setup(x => x.Posts).Returns(dbSetPost.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1)); UnpinPostCommandHandler unpinPostCommandHandler = new UnpinPostCommandHandler(context.Object, stringLocalizer.Object); UnpinPostCommand unpinPostCommand = new UnpinPostCommand(id); var result = await unpinPostCommandHandler.Handle(unpinPostCommand, new CancellationToken()); result.Should().Be(Unit.Value); post.IsPinned.Should().BeFalse(); }