Exemplo n.º 1
0
        public async Task <CreatedActionResult <MonsterResponse> > PostCreateMonsterAsync(
            [FromServices] NaheulbookExecutionContext executionContext,
            [FromRoute] int groupId,
            CreateMonsterRequest request
            )
        {
            try
            {
                var monster = await _monsterService.CreateMonsterAsync(executionContext, groupId, request);

                return(_mapper.Map <MonsterResponse>(monster));
            }
            catch (ForbiddenAccessException ex)
            {
                throw new HttpErrorException(StatusCodes.Status403Forbidden, ex);
            }
            catch (GroupNotFoundException ex)
            {
                throw new HttpErrorException(StatusCodes.Status404NotFound, ex);
            }
            catch (ItemTemplateNotFoundException ex)
            {
                throw new HttpErrorException(StatusCodes.Status400BadRequest, ex);
            }
        }
Exemplo n.º 2
0
        public async Task PostCreateMonsterAsync_ShouldCreateMonster_ThenReturnMonsterResponse()
        {
            const int groupId = 8;
            var       createMonsterRequest = new CreateMonsterRequest();
            var       createdMonster       = new Monster();
            var       monsterResponse      = new MonsterResponse();

            _monsterService.CreateMonsterAsync(_executionContext, groupId, createMonsterRequest)
            .Returns(createdMonster);
            _mapper.Map <MonsterResponse>(createdMonster)
            .Returns(monsterResponse);

            var result = await _controller.PostCreateMonsterAsync(_executionContext, groupId, createMonsterRequest);

            result.Value.Should().BeSameAs(monsterResponse);
            result.StatusCode.Should().Be(StatusCodes.Status201Created);
        }