public void GivenNewItemDTOAndExistingID_WhenUpdatingThatItem_ThenCallToItemRepositoryToUpdate() { //Given Item newItem = new Item() { AmountInStock = 5, Price = 10.0, Name = "Test", Description = "Test description", Id = 0 }; ItemDTO newItemDTO = new ItemDTO() { AmountInStock = 5, Price = 10.0, Name = "Test", Description = "Test description", }; _itemMapperStub.FromItemDTOToItemWhenUpdating(newItemDTO).Returns(newItem); _itemRepositoryStub.UpdateItem(0, newItem).Returns(newItem); //When _itemService.UpdateItem(0, newItemDTO); //then _itemRepositoryStub.Received().UpdateItem(0, newItem); }
public ItemDTO UpdateItem(int id, ItemDTO itemToUpdateDTO) { foreach (var item in itemToUpdateDTO.GetType().GetProperties()) { if (item.Name != "Id") { if ((item.GetValue(itemToUpdateDTO) == null)) { throw new ItemInputException(); } } else { if ((item.GetValue(itemToUpdateDTO).ToString() != "-1")) { throw new ItemInputException(); } } } Item ItemToUpdate = _itemMapper.FromItemDTOToItemWhenUpdating(itemToUpdateDTO); return(_itemMapper.FromItemToItemDTO(_itemRepository.UpdateItem(id, ItemToUpdate))); }