コード例 #1
0
        public async Task <IActionResult> CreateDivisionAsync(ClanId clanId, CreateDivisionRequest request)
        {
            var userId = HttpContext.GetUserId();

            var clan = await _clanService.FindClanAsync(clanId);

            if (clan == null)
            {
                return(this.NotFound("Clan does not exist."));
            }

            var result = await _clanService.CreateDivisionAsync(
                clan,
                userId,
                request.Name,
                request.Description);

            if (result.IsValid)
            {
                return(this.Ok("Division created."));
            }

            result.AddToModelState(ModelState);

            return(this.BadRequest(new ValidationProblemDetails(ModelState)));
        }
コード例 #2
0
        public void CanCreateDivisions()
        {
            var divisionRepo = new Mock<IDivisionRepository>();

            var request = new CreateDivisionRequest {Name = "D1"};

            var handler = new CreateDivisionRequestHandle(divisionRepo.Object);

            var response = handler.Handle(request);

            Assert.NotNull(response);
            divisionRepo.Verify(x => x.Save(It.Is<Division>(y => y.Name == request.Name)));
        }
コード例 #3
0
 private async Task <HttpResponseMessage> ExecuteAsync(ClanId clanId, CreateDivisionRequest request)
 {
     return(await _httpClient.PostAsJsonAsync($"api/clans/{clanId}/divisions", request));
 }