public async Task <GlossaryItemDto> UpdateAsync(GlossaryItemUpdateDto glossaryUpdateItem, int id)
        {
            GlossaryItem itemForUpdate = await GetItemIfExistsAsync(id);

            itemForUpdate.Definition = glossaryUpdateItem.Definition;
            _unitOfWork.Commit();

            var glossaryItemResultDto = _mapper.Map <GlossaryItem, GlossaryItemDto>(itemForUpdate);

            return(glossaryItemResultDto);
        }
Esempio n. 2
0
        public void Update_throws_non_existing_item_exception_when_item_not_found()
        {
            var itemForUpdateDto = new GlossaryItemUpdateDto
            {
                Definition = "Updated definition"
            };

            GlossaryItem glossaryItemNull = null;

            _unitOfWorkMock.Setup(e => e.Commit());
            _glossaryRepositoryMock.Setup(e => e.FindByIdAsync(3))
            .Returns(Task.FromResult(glossaryItemNull));

            _glossaryItemsService = new GlossaryItemsService(_glossaryRepositoryMock.Object, _unitOfWorkMock.Object, _mapperMock.Object);

            Assert.ThrowsAsync <NonExistingItemException>(async() => await _glossaryItemsService.UpdateAsync(itemForUpdateDto, 3));
            _glossaryRepositoryMock.Verify(e => e.FindByIdAsync(3), Times.Once);
            _unitOfWorkMock.Verify(e => e.Commit(), Times.Never);
        }
Esempio n. 3
0
        public async Task Update_change_item_definition_success()
        {
            var itemForUpdateDto = new GlossaryItemUpdateDto
            {
                Definition = "Updated definition"
            };

            var itemBeforeUpdate = new GlossaryItem
            {
                Id         = 3,
                Term       = "alkaline",
                Definition = "Definition test"
            };

            var itemAfterUpdate = new GlossaryItem
            {
                Id         = 3,
                Term       = "alkaline",
                Definition = "Updated definition"
            };

            var itemAfterUpdateDto = new GlossaryItemDto
            {
                Id         = 3,
                Term       = "alkaline",
                Definition = "Updated definition"
            };

            _unitOfWorkMock.Setup(e => e.Commit());
            _glossaryRepositoryMock.Setup(e => e.FindByIdAsync(3))
            .Returns(Task.FromResult(itemBeforeUpdate));

            _mapperMock
            .Setup(e => e.Map <GlossaryItem, GlossaryItemDto>(itemAfterUpdate))
            .Returns(itemAfterUpdateDto);

            _glossaryRepositoryMock.Setup(e => e.Update(itemBeforeUpdate));

            await _glossaryItemsService.UpdateAsync(itemForUpdateDto, 3);

            _glossaryRepositoryMock.Verify(e => e.FindByIdAsync(3), Times.Once);
            _unitOfWorkMock.Verify(e => e.Commit(), Times.Once);
        }
        public async Task <IActionResult> Put(GlossaryItemUpdateDto glossaryItemForUpdate, int id)
        {
            var updatedItem = await _glossaryService.UpdateAsync(glossaryItemForUpdate, id);

            return(Ok(updatedItem));
        }