public void Create_InvalidParent() { var repo = new CharacterRepository(); Assert.Throws <ArgumentNullException>(() => repo.Create(null), "Unit Test expected an ArgumentNullException to be thrown!"); }
public void Create_given_a_character_it_maps_to_character() { var character = default(Character); var dto = new CharacterCreateUpdateDTO { ActorId = 42, Name = "Turange Leela", Species = "Mutant, Human", Planet = "Earth" }; var mock = new Mock <IFuturamaContext>(); mock.Setup(s => s.Characters.Add(It.IsAny <Character>())) .Callback <Character>(c => character = c); using (var repository = new CharacterRepository(mock.Object)) { repository.Create(dto); } Assert.Equal(42, character.ActorId); Assert.Equal("Turange Leela", character.Name); Assert.Equal("Mutant, Human", character.Species); Assert.Equal("Earth", character.Planet); }
private static void CreateCharacter(CharacterRepository repo) { Character newCharacter = UserIO.PromptUserForNewCharacter(); newCharacter = repo.Create(newCharacter); UserIO.DisplayCharacter(repo.ReadById(newCharacter.Id)); }
private static void CreateChar(int id, int lobbyId, string username) { _characterRepository.Create(id); _memberRepository.Create(lobbyId, id); _characterRepository.Update(new Character { CharacterName = username, State = CharacterState.InGame, TelegramUserId = id }); }
//[Test] public void Create() { var mobRepo = new MobileRepository(); var mob = mobRepo.Create(1, "TestMob"); var repo = new CharacterRepository(); var actual = repo.Create(mob); Assert.That(actual, Is.Not.Null); Assert.That(actual.ID, Is.GreaterThanOrEqualTo(1)); }
//[Route("api/create")] public IHttpActionResult Post(Character charac) { if (!ModelState.IsValid) { return(BadRequest()); } logger.Log("Inside CharacterController.Post"); repo.Create(new Fallout(), charac.CharacterName, charac.PlayerName); Character created_character = repo.Get(charac.CharacterName); return(Ok(created_character)); }
private void AddCharacter(string data) { var charactersNumber = DatabaseProvider.AccountCharacters.FindAll(x => x.Account.Id == _client.Account.Id).Count; if (charactersNumber >= int.Parse(Config.Get("Player_Max_Per_Account"))) { _client.SendPackets(Packet.CreateCharacterFullErrors); return; } var datas = data.Split('|'); var name = datas[0]; var classe = int.Parse(datas[1]); var sex = int.Parse(datas[2]); var color1 = int.Parse(datas[3]); var color2 = int.Parse(datas[4]); var color3 = int.Parse(datas[5]); if (classe == (int)Character.Class.Pandawa && bool.Parse(Config.Get("Subscription")) && _client.Account.IsNotSubscribed()) { return; } if (DatabaseProvider.Characters.All(x => x.Name != name) && name.Length >= 3 && name.Length <= 20) { var reg = new Regex("^[a-zA-Z-]+$"); if (reg.IsMatch(name) && name.Count(c => c == '-') < 3) { if (classe >= 1 && classe <= 12 && (sex == 1 || sex == 0)) { var newCharacter = new Character { Id = DatabaseProvider.Characters.Count > 0 ? DatabaseProvider.Characters.OrderByDescending(x => x.Id).First().Id + 1 : 1, Name = name, Classe = (Character.Class)classe, Sex = sex, Color1 = color1, Color2 = color2, Color3 = color3, Level = int.Parse(Config.Get("Starting_level")), Skin = int.Parse(classe + "" + sex), PdvNow = (int.Parse(Config.Get("Starting_level")) - 1) * Character.GainHpPerLvl + Character.BaseHp, PdvMax = (int.Parse(Config.Get("Starting_level")) - 1) * Character.GainHpPerLvl + Character.BaseHp, }; newCharacter.GenerateInfos(_client.Account.GmLevel); CharacterRepository.Create(newCharacter, _client.Account.Id); _client.SendPackets(Packet.CreationSuccess); _client.SendPackets(Packet.GameBegin); SendCharactersList(""); } else { _client.SendPackets(Packet.CreateCharacterFullErrors); } } else { _client.SendPackets(Packet.CreateCharacterBadName); } } else { _client.SendPackets(Packet.NameAlredyExists); } }
public List <MessageConfig> StateMachine(CharacterState state, string command, int playerId) { //TODO: Вынести сюда создание репозиториев switch (state) { case CharacterState.ChangeName: return(BotService.TryChangeName(command, playerId)); case CharacterState.ChangeGameMode: switch (command) { case "/game": return(BotService.FindGameCommand(playerId)); case "/tutorial": var character = _characterRepository.Read(playerId); LobbyRepository lobbyRepository = new LobbyRepository(); MemberRepository memberRepository = new MemberRepository(); memberRepository.Create(0, playerId); var lobby = lobbyRepository.Read(0); lobby.Players.Add(new Player { Health = 3, HeroName = character.CharacterName, Rotate = Direction.North, TelegramUserId = playerId, UserCoordinate = new Coordinate(3, 3) }); lobbyRepository.Update(lobby); character.State = CharacterState.Tutorial; _characterRepository.Update(character); return(new List <MessageConfig> { new MessageConfig() { Answer = "Обучение", PlayerId = playerId } }); default: return(new List <MessageConfig> { new MessageConfig() { Answer = "неверная команда", PlayerId = playerId } }); } case CharacterState.Tutorial: switch (command) { case "Вверх": return(TutorialService.MoveCommand(playerId, Direction.North)); case "Вниз": return(TutorialService.MoveCommand(playerId, Direction.South)); case "Вправо": return(TutorialService.MoveCommand(playerId, Direction.East)); case "Влево": return(TutorialService.MoveCommand(playerId, Direction.West)); case "Взрыв стены": var inlineKeyboard = KeybordConfiguration.ChooseDirectionKeyboard(); BotClient.SendTextMessageAsync(playerId, "Выбирай направление", replyMarkup: inlineKeyboard); BotClient.OnCallbackQuery += BotClient_OnCallbackQueryBomb; return(null); case "/skip": var character = _characterRepository.Read(playerId); LobbyRepository lobbyRepository = new LobbyRepository(); MemberRepository memberRepository = new MemberRepository(); memberRepository.DeleteOne(playerId); var lobby = lobbyRepository.Read(0); lobby.Players.Remove(lobby.Players.Find(e => e.TelegramUserId == playerId)); lobbyRepository.Update(lobby); character.State = CharacterState.ChangeGameMode; _characterRepository.Update(character); return(new List <MessageConfig> { new MessageConfig() { Answer = "Обучение пропущено", PlayerId = playerId } }); default: return(new List <MessageConfig> { new MessageConfig() { Answer = "Неверная команда", PlayerId = playerId } }); } case CharacterState.FindGame: switch (command) { case "/help": return(new List <MessageConfig> { new MessageConfig() { Answer = Answers.Help.RandomAnswer(), PlayerId = playerId } }); case "/stop": _characterRepository.Read(playerId); MemberRepository repo = new MemberRepository(); var character = _characterRepository.Read(playerId); character.State = CharacterState.ChangeGameMode; _characterRepository.Update(character); repo.DeleteOne(playerId); return(new List <MessageConfig> { new MessageConfig() { Answer = "Вы удалены из очереди", PlayerId = playerId } }); default: return(new List <MessageConfig> { new MessageConfig() { Answer = "Неверная команда", PlayerId = playerId } }); } case CharacterState.InGame: switch (command) { case "Вперед": return(BotService.MoveCommand(playerId, Direction.North)); case "Назад": return(BotService.MoveCommand(playerId, Direction.South)); case "Вправо": return(BotService.MoveCommand(playerId, Direction.East)); case "Влево": return(BotService.MoveCommand(playerId, Direction.West)); case "Удар кинжалом": return(BotService.StabCommand(playerId)); case "Пропуск хода": return(BotService.SkipTurn(playerId)); case "Выстрел": { var inlineKeyboard = KeybordConfiguration.ChooseDirectionKeyboard(); BotClient.SendTextMessageAsync(playerId, "Выбирай направление", replyMarkup: inlineKeyboard); BotClient.OnCallbackQuery += BotClient_OnCallbackQueryShoot; return(null); } case "Взрыв стены": { var inlineKeyboard = KeybordConfiguration.ChooseDirectionKeyboard(); BotClient.SendTextMessageAsync(playerId, "Выбирай направление", replyMarkup: inlineKeyboard); BotClient.OnCallbackQuery += BotClient_OnCallbackQueryBomb; return(null); } case "/afk": return(BotService.AfkCommand(playerId)); case "/leave": return(BotService.TryLeaveCommand(playerId)); } return(new List <MessageConfig> { new MessageConfig() { Answer = Answers.UndefinedCommand.RandomAnswer(), PlayerId = playerId } }); case CharacterState.NewCharacter: if (command == "/start") { if (_characterRepository.Read(playerId) == null) { _characterRepository.Create(playerId); return(new List <MessageConfig> { new MessageConfig() { Answer = "Напишите имя персонажа", PlayerId = playerId } }); } } return(new List <MessageConfig> { new MessageConfig() { Answer = "Неверная команда", PlayerId = playerId } }); case CharacterState.AcceptLeave: if (command == "Подтверждаю") { return(BotService.LeaveCommand(playerId)); } else { return(new List <MessageConfig> { new MessageConfig { Answer = "Не подтверждено", PlayerId = playerId } }); } case CharacterState.Ban: //TODO:REBAN return(new List <MessageConfig> { new MessageConfig() { Answer = "В бане", PlayerId = playerId } }); default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } throw new ArgumentOutOfRangeException(nameof(state), state, null); }