public async Task PostCreateLootAsync_ShouldCreateLoot_ThenReturnLootResponse() { const int groupId = 8; var createLootRequest = new CreateLootRequest(); var createdLoot = new Loot(); var lootResponse = new LootResponse(); _lootService.CreateLootAsync(_executionContext, groupId, createLootRequest) .Returns(createdLoot); _mapper.Map <LootResponse>(createdLoot) .Returns(lootResponse); var result = await _controller.PostCreateLootAsync(_executionContext, groupId, createLootRequest); result.Value.Should().BeSameAs(lootResponse); result.StatusCode.Should().Be(StatusCodes.Status201Created); }
public async Task <CreatedActionResult <LootResponse> > PostCreateLootAsync( [FromServices] NaheulbookExecutionContext executionContext, [FromRoute] int groupId, CreateLootRequest request ) { try { var loot = await _lootService.CreateLootAsync(executionContext, groupId, request); return(_mapper.Map <LootResponse>(loot)); } catch (ForbiddenAccessException ex) { throw new HttpErrorException(StatusCodes.Status403Forbidden, ex); } catch (GroupNotFoundException ex) { throw new HttpErrorException(StatusCodes.Status404NotFound, ex); } }