Esempio n. 1
0
        public async Task HandlingDeleteTagCommand_ShouldDeleteTagFromScope()
        {
            // Arrange
            Assert.AreEqual(1, _project.Tags.Count);

            // Act
            await _dut.Handle(_command, default);

            // Assert
            Assert.AreEqual(0, _project.Tags.Count);
        }
        public void ShouldNotCallHandleIfTagNotExist()
        {
            dbSetTag.Setup(x => x.FindAsync(id)).Returns(null);
            context.Setup(x => x.Tags).Returns(dbSetTag.Object);

            DeleteTagCommandHandler deleteTagCommandHandler = new DeleteTagCommandHandler(context.Object, stringLocalizer.Object);
            DeleteTagCommand        deleteTagCommand        = new DeleteTagCommand(id);

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

            act.Should().Throw <NotFoundException>();
        }
        public void ShouldNotCallHandleIfNotSavedChanges()
        {
            dbSetTag.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Tag>(Task.FromResult(new Tag {
                Id = id
            })));
            context.Setup(x => x.Tags).Returns(dbSetTag.Object);
            context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(0));

            DeleteTagCommandHandler deleteTagCommandHandler = new DeleteTagCommandHandler(context.Object, stringLocalizer.Object);
            DeleteTagCommand        deleteTagCommand        = new DeleteTagCommand(id);

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

            act.Should().Throw <RestException>();
        }
        public async Task ShouldCallHandle()
        {
            dbSetTag.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Tag>(Task.FromResult(new Tag {
                Id = id
            })));
            context.Setup(x => x.Tags).Returns(dbSetTag.Object);
            context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1));

            DeleteTagCommandHandler deleteTagCommandHandler = new DeleteTagCommandHandler(context.Object, stringLocalizer.Object);
            DeleteTagCommand        deleteTagCommand        = new DeleteTagCommand(id);

            var result = await deleteTagCommandHandler.Handle(deleteTagCommand, new CancellationToken());

            result.Should().Be(Unit.Value);
        }
Esempio n. 5
0
        public async Task GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var sut   = new DeleteTagCommandHandler(_context);
            var tagId = 10;

            // Act (Assert)
            var ex = await Assert.ThrowsAsync <NotFoundException>(() => sut.Handle(new DeleteTagCommand
            {
                Id = tagId
            },
                                                                                   CancellationToken.None));

            // Assert
            Assert.IsType <NotFoundException>(ex);
        }
Esempio n. 6
0
        public void GivenValidRequest_ShouldSuccessfullyDeleteTag()
        {
            // Arrange
            var sut    = new DeleteTagCommandHandler(_context);
            var entity = new Tag("Test Tag 1");

            _context.Tags.Add(entity);
            _context.SaveChanges();

            // Act
            var result = sut.Handle(new DeleteTagCommand {
                Id = entity.Id
            }, CancellationToken.None);
            var tag = _context.Tags.FirstOrDefault(i => i.Id == entity.Id);

            // Assert
            Assert.IsType <Unit>(result.Result);
            Assert.Null(tag);
        }