Exemplo n.º 1
0
 public void SwapMovement(CharacterRotate newRot, CharacterTranslate newTrans, List <CharacterControlExtraBase> extras = null)
 {
     StopAll();
     rotate        = newRot;
     translate     = newTrans;
     extraControls = extras;
     Init();
 }
Exemplo n.º 2
0
        public async Task <IActionResult> PostAsync([FromBody] CharacterModel characterModel)
        {
            var houseModel = await this.potterAPIClient.GetHouseAsync(characterModel.House);

            if (houseModel?.Id == null)
            {
                return(NotFound("House not exists."));
            }

            var character = CharacterTranslate.To(characterModel);

            await this.characterService.AddAsync(character);

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetAsync(Guid id)
        {
            var character = await this.characterService.GetAsync(id);

            if (character == null)
            {
                return(NotFound());
            }

            var characterModel = CharacterTranslate.To(character);

            characterModel.House = await this.potterAPIClient.GetHouseAsync(character.HouseId);

            return(Ok(characterModel));
        }
Exemplo n.º 4
0
        public void ModelToEntity()
        {
            var characterModel = new CharacterModel
            {
                House    = "3824jgdjdg",
                Name     = "HP",
                Patronus = "Cachorro",
                Role     = "Estudante",
                School   = "Hogwarts"
            };

            var character = CharacterTranslate.To(characterModel);

            Assert.Equal("3824jgdjdg", character.HouseId);
            Assert.Equal("HP", character.Name);
            Assert.Equal("Cachorro", character.Patronus);
            Assert.Equal("Estudante", character.Role);
            Assert.Equal("Hogwarts", character.School);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PutAsync(Guid id, [FromBody] CharacterModel characterModel)
        {
            try
            {
                var houseModel = await this.potterAPIClient.GetHouseAsync(characterModel.House);

                if (houseModel?.Id == null)
                {
                    return(NotFound("House not exists."));
                }

                var character = CharacterTranslate.To(characterModel, id);
                await this.characterService.UpdateAsync(id, character);

                return(Ok());
            }
            catch (ArgumentNullException)
            {
                return(NotFound());
            }
        }
Exemplo n.º 6
0
        public void EntityToModel()
        {
            var id        = Guid.NewGuid();
            var character = new Character
            {
                Id       = id,
                HouseId  = "3824jgdjdg",
                Name     = "HP",
                Patronus = "Cachorro",
                Role     = "Estudante",
                School   = "Hogwarts"
            };

            var characterModel = CharacterTranslate.To(character);

            Assert.Equal(characterModel.Id, id);
            Assert.Null(characterModel.House);
            Assert.Equal("HP", characterModel.Name);
            Assert.Equal("Cachorro", characterModel.Patronus);
            Assert.Equal("Estudante", characterModel.Role);
            Assert.Equal("Hogwarts", characterModel.School);
        }
Exemplo n.º 7
0
        public async Task <IActionResult> GetAsync(string house = null)
        {
            var characters = await this.characterService.AllAsync(house);

            if (characters?.Count == 0)
            {
                return(NotFound());
            }

            var houses = await this.potterAPIClient.GetHousesAsync();

            var characterModels = new List <CharacterGetModel>();

            foreach (var item in characters)
            {
                var characterModel = CharacterTranslate.To(item);
                characterModel.House = houses?.FirstOrDefault(h => h.Id == item.HouseId);
                characterModels.Add(characterModel);
            }

            return(Ok(characterModels));
        }
Exemplo n.º 8
0
        public void EntityToModelWhenEntityIsNull()
        {
            var characterModel = CharacterTranslate.To((Character)null);

            Assert.Null(characterModel);
        }
Exemplo n.º 9
0
        public void ModelToEntityWhenModelIsNull()
        {
            var character = CharacterTranslate.To((CharacterModel)null);

            Assert.Null(character);
        }