public async Task GetById_ExistingItem_ReturnsItemWithIdAndCachesResult()
        {
            var id   = Guid.Parse("F7148339-E162-4657-B886-C29BF6A2D312");
            var item = ItemFactory.CreateItem(id, "This is a text.");

            _itemRepository.GetByIdAsync(id).Returns(item);

            await _itemObtainingService.ExistsAsync(id);

            var firstItem  = _itemObtainingService.GetById(id);
            var secondItem = _itemObtainingService.GetById(id);

            Assert.Multiple(() =>
            {
                Assert.That(firstItem, Is.EqualTo(item).UsingItemComparer());
                Assert.That(secondItem, Is.EqualTo(firstItem));
                _itemRepository.Received(1).GetByIdAsync(id);
            });
        }
        public async Task UpdateAsync(Item item)
        {
            if (!await _itemObtainingService.ExistsAsync(item.Id))
            {
                throw new ItemNotFoundException("Item with id=" + item.Id + " was not found.");
            }

            var originalItem = _itemObtainingService.GetById(item.Id);

            UpdateExistingItem(originalItem, item);

            await _repository.UpdateAsync(originalItem);
        }
        public async Task UpdateAsync_ExistingItem_UpdatesItem()
        {
            var currentTime = new DateTime(2018, 10, 1, 8, 42, 5);
            var id          = Guid.Parse("F7148339-E162-4657-B886-C29BF6A2D312");

            var(originalItem, receivedItem, changedItem) = CreateItems(id, currentTime);

            _itemObtainingService.ExistsAsync(id).Returns(true);
            _itemObtainingService.GetById(id).Returns(originalItem);
            _dateTimeWrapper.CurrentDateTime().Returns(currentTime, DateTime.MinValue);

            await _itemUpdatingService.UpdateAsync(receivedItem);

            await _itemRepository.Received(1).UpdateAsync(ArgExtended.IsItem(changedItem));
        }
        public async Task <IHttpActionResult> GetItemByIdAsync(Guid id)
        {
            if (!IsIdValid(id))
            {
                return(BadRequest(ModelState));
            }

            if (!await _itemObtainingService.ExistsAsync(id))
            {
                return(NotFound());
            }

            var item = _itemObtainingService.GetById(id);

            return(Ok(item));
        }