Beispiel #1
0
        public void GivenNewItemDTOWithAllProperties_WhenCreatingNewItem_ThenItemRepositoryReceiveCallToSaveNewItem()
        {
            //Given
            ItemDTO newItemDTO = new ItemDTO()
            {
                AmountInStock = 5,
                Price         = 10.0,
                Name          = "Test",
                Description   = "Test description"
            };
            Item newItem = new Item()
            {
                AmountInStock = 5,
                Price         = 10.0,
                Name          = "Test",
                Description   = "Test description"
            };

            _itemMapperStub.FromItemDTOToItemWhenCreatingNewItem(newItemDTO).Returns(newItem);

            //When
            _itemService.CreateNewItem(newItemDTO);

            //then
            _itemRepositoryStub.Received().SaveNewItemInDB(newItem);
        }
Beispiel #2
0
        public ItemDTO CreateNewItem(ItemDTO itemDTO)
        {
            foreach (var item in itemDTO.GetType().GetProperties())
            {
                if (item.Name != "Id")
                {
                    if ((item.GetValue(itemDTO) == null))
                    {
                        throw new ItemInputException();
                    }
                }
                else
                {
                    if ((item.GetValue(itemDTO).ToString() != "-1"))
                    {
                        throw new ItemInputException();
                    }
                }
            }
            Item newItem = _itemMapper.FromItemDTOToItemWhenCreatingNewItem(itemDTO);

            _itemRepository.SaveNewItemInDB(newItem);
            return(_itemMapper.FromItemToItemDTO(newItem));
        }