예제 #1
0
        public async Task EquipItemAsync_ShouldUpdateItemModifiersFieldAndSaveDb()
        {
            const int itemId       = 4;
            var       equipRequest = new EquipItemRequest {
                Level = 24
            };
            var item = new Item();

            _unitOfWorkFactory.GetUnitOfWork().Items.GetWithOwnerAsync(itemId)
            .Returns(item);
            _unitOfWorkFactory.GetUnitOfWork().When(x => x.SaveChangesAsync())
            .Do(_ => _itemUtil.Received(1).EquipItem(item, 24));

            var actualItem = await _service.EquipItemAsync(new NaheulbookExecutionContext(), itemId, equipRequest);

            actualItem.Should().BeSameAs(item);
            await _unitOfWorkFactory.GetUnitOfWork().Received(1).SaveChangesAsync();
        }
예제 #2
0
        public async Task <bool> EquipItemAsync(ApiRequestModel apiRequestModel, EquipItemRequest model)
        {
            var requestUrl = "store_items/equip";

            var requestBody = new
            {
                user_id = model.UserId,
                item_id = model.ItemId
            };

            using (var response = await SendPostRequestAsync(apiRequestModel, requestUrl, requestBody))
            {
                if (!response.IsSuccessStatusCode)
                {
                    return(false);
                }

                return(true);
            }
        }
예제 #3
0
        public async Task <ActionResult <ItemPartialResponse> > PostEquipItemAsync(
            [FromServices] NaheulbookExecutionContext executionContext,
            [FromRoute] int itemId,
            EquipItemRequest request
            )
        {
            try
            {
                var item = await _itemService.EquipItemAsync(executionContext, itemId, request);

                return(_mapper.Map <ItemPartialResponse>(item));
            }
            catch (ForbiddenAccessException ex)
            {
                throw new HttpErrorException(StatusCodes.Status403Forbidden, ex);
            }
            catch (ItemNotFoundException ex)
            {
                throw new HttpErrorException(StatusCodes.Status404NotFound, ex);
            }
        }