예제 #1
0
        public async Task GetMonsterListAsync_LoadMonsterThenMapTheResponse()
        {
            const int groupId          = 8;
            var       monsters         = new List <Monster>();
            var       monstersResponse = new List <MonsterResponse>();

            _monsterService.GetMonstersForGroupAsync(_executionContext, groupId)
            .Returns(monsters);
            _mapper.Map <List <MonsterResponse> >(monsters)
            .Returns(monstersResponse);

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

            result.Value.Should().BeSameAs(monstersResponse);
        }
예제 #2
0
        public async Task <ActionResult <List <MonsterResponse> > > GetMonsterListAsync(
            [FromServices] NaheulbookExecutionContext executionContext,
            [FromRoute] int groupId
            )
        {
            try
            {
                var monsters = await _monsterService.GetMonstersForGroupAsync(executionContext, groupId);

                return(_mapper.Map <List <MonsterResponse> >(monsters));
            }
            catch (ForbiddenAccessException ex)
            {
                throw new HttpErrorException(StatusCodes.Status403Forbidden, ex);
            }
            catch (GroupNotFoundException ex)
            {
                throw new HttpErrorException(StatusCodes.Status404NotFound, ex);
            }
        }