public async Task PostCreateCharacterAsync_ShouldCreateCharacterWithCharacterService_ThenReturnCharacterResponse() { var createCharacterRequest = new CreateCharacterRequest(); var createdCharacter = new Character(); var characterResponse = new CreateCharacterResponse(); _characterService.CreateCharacterAsync(_executionContext, createCharacterRequest) .Returns(createdCharacter); _mapper.Map <CreateCharacterResponse>(createdCharacter) .Returns(characterResponse); var result = await _controller.PostCreateCharacterAsync(_executionContext, createCharacterRequest); result.Value.Should().BeSameAs(characterResponse); result.StatusCode.Should().Be(StatusCodes.Status201Created); }
public async Task CreateCharacter(CreateCharacterRequest request) { var identityView = IdentityView.FromObjectId(_dbContext, (SHIdentity.FromPrincipal(Context.User)).ObjectId); if (identityView.Identity == null) { return; } if (!Context.User.Identity.IsAuthenticated) { return; } if (request == null || String.IsNullOrEmpty(request.Name)) { return; } if (_dbContext.Mob.Count(e => e.AccountId == identityView.Identity.Id) > 2) { return; } var mob = new Mob() { MobClassId = request.MobClassId, MobRaceId = request.MobRaceId, AccountId = identityView.Identity.Id, Name = request.Name, ZoneId = 1 }; if (_dbContext.Mob.Any(e => e.AccountId == identityView.Identity.Id && e.Name.Equals(mob.Name))) { return; } mob = _dbContext.Mob.Add(mob).Entity; _dbContext.SaveChanges(); var response = new CreateCharacterResponse(); response.Mob = mob; await Clients.Client(Context.ConnectionId).SendAsync("CreateCharacterResponse", "", JsonConvert.SerializeObject(response)); }