public void ShouldNotCallHandleIfTagNotExist() { dbSetTag.Setup(x => x.FindAsync(id)).Returns(null); context.Setup(x => x.Tags).Returns(dbSetTag.Object); EditTagCommandHandler editTagCommandHandler = new EditTagCommandHandler(context.Object, stringLocalizer.Object, mapper.Object); EditTagCommand editTagCommand = new EditTagCommand(tagDto); Func <Task> act = async() => await editTagCommandHandler.Handle(editTagCommand, new CancellationToken()); act.Should().ThrowAsync <NotFoundException>(); }
public void ShouldNotCallHandleIfNotSavedChanges() { dbSetTag.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Tag>(Task.FromResult(tag))); context.Setup(x => x.Tags).Returns(dbSetTag.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(0)); EditTagCommandHandler editTagCommandHandler = new EditTagCommandHandler(context.Object, stringLocalizer.Object, mapper.Object); EditTagCommand editTagCommand = new EditTagCommand(tagDto); Func <Task> act = async() => await editTagCommandHandler.Handle(editTagCommand, new CancellationToken()); act.Should().ThrowAsync <RestException>(); }
public async Task ShouldCallHandle() { dbSetTag.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Tag>(Task.FromResult(tag))); context.Setup(x => x.Tags).Returns(dbSetTag.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1)); EditTagCommandHandler editTagCommandHandler = new EditTagCommandHandler(context.Object, stringLocalizer.Object, mapper.Object); EditTagCommand editTagCommand = new EditTagCommand(tagDto); var result = await editTagCommandHandler.Handle(editTagCommand, new CancellationToken()); mapper.Verify(x => x.Map(editTagCommand, tag), Times.Once); result.Should().Be(Unit.Value); }