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