示例#1
0
        public async Task ShouldNotReturnNullForValidPokemon()
        {
            var result = await pokemonService.GetPokemon(Constants.ValidPokemon);

            System.Console.WriteLine(result.Description);

            Assert.IsNotNull(result);
        }
示例#2
0
        public void IfRepositoryThrowsArgumentOutOfRangeException_GetPokemon_ShouldReturnHttpNotFound()
        {
            var pokemonName = new Faker().Lorem.Word();

            A.CallTo(() => _pokemonRepository.Get(A <string> ._)).Throws <ArgumentOutOfRangeException>();

            var actionResult = _pokemonService.GetPokemon(pokemonName);

            var result = CastActionResultOrFail <NotFoundResult, Pokemon>(actionResult);

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task returns_failed_pokemon_result()
        {
            var pokemonResult = new Result <Pokemon>(_errorResult);

            _pokemonClient.Setup(c => c.GetPokemon(_knownName))
            .Returns(Task.FromResult(pokemonResult));

            var result = await _pokemonService.GetPokemon(_knownName);

            Assert.IsTrue(result.Failed);
            Assert.AreEqual(_errorResult, result.ErrorResult);
        }
示例#4
0
        public void TestMissingEnglishDescriptionPokeServiceThrowsException()
        {
            var name       = "test name";
            var id         = 1;
            var returnPoke = new RawPokemon();

            returnPoke.Name = name;
            returnPoke.Id   = id;
            var pokeCharacteristic = new PokemonCharacteristic();

            pokeCharacteristic.descriptions = new System.Collections.Generic.List <Description>();
            pokeCharacteristic.descriptions.Add(new Description {
                description = "oui francais", language = new Language {
                    name = "fr"
                }
            });

            var mockRepo    = new Mock <IPokemonRepository>();
            var pokeService = new PokemonService(mockRepo.Object);

            mockRepo.Setup(a => a.GetPokemon(name)).Returns(returnPoke);
            mockRepo.Setup(a => a.GetCharacteristic(id)).Returns(pokeCharacteristic);

            Assert.Throws <ApiException>(() => pokeService.GetPokemon(name));
        }
示例#5
0
        private async void LoadData(string url)
        {
            try
            {
                UserDialogs.Instance.ShowLoading("Carregando");

                var pokemon = await PokemonService.GetPokemon(url);

                var abilities = new List <AbilityDetailsModel>();

                foreach (var item in pokemon.Abilities)
                {
                    abilities.Add(item.Ability);
                }

                Abilities = abilities;

                UrlImage = pokemon.Sprites.Front_Default ?? "";
                Name     = pokemon.Name.ToUpper() ?? "";
                Weight   = pokemon.Weight;
                Height   = pokemon.Height;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                UserDialogs.Instance.HideLoading();
            }
        }
        public IHttpActionResult Get()
        {
            PokemonService pokemonService = CreatePokemonService();
            var            pokemon        = pokemonService.GetPokemon();

            return(Ok(pokemon));
        }
        protected override async Task OnInitializedAsync()
        {
            Pokemon = await PokemonService.GetPokemon(int.Parse(Id));

            PokemonTypes = (await PokemonTypeService.GetPokemonTypes()).ToList();
            Mapper.Map(Pokemon, EditPokemonModel);
        }
示例#8
0
        private async void onClickCameraCommand(object obj)
        {
            IsBusy         = true;
            ShowResult     = false;
            ShowError      = false;
            IsBusy         = true;
            NameRecognized = "";

            var pokemonService = new PokemonService();
            var service        = new TextRecognitionService();
            var imageData      = await TakePicture();

            var handWritingResult = await service.GetHandwrittenTextFromImage(imageData);

            this.NameRecognized = handWritingResult;
            if (NameRecognized != "ERROR Recognizing")
            {
                var result = await pokemonService.GetPokemon(NameRecognized);

                if (result != null)
                {
                    PokemonItem = result;
                    ShowResult  = true;
                    WikiUrl     = await service.GetEntityLink(this.NameRecognized);

                    DependencyService.Get <ITextToSpeech>().Speak(PokemonItem.name);
                }
            }
            else
            {
                ShowError = true;
            }

            IsBusy = false;
        }
示例#9
0
        public static async Task <Pokemon> Run([TimerTrigger("* */5 * * * *")] TimerInfo myTimer, TraceWriter log)
        {
            var pokemonService = new PokemonService();

            log.Info("Getting data from API");
            var pokemon = await pokemonService.GetPokemon("charizard");

            return(pokemon);
        }
示例#10
0
        public void TestInvalidNamePokeServiceThrowsException()
        {
            var badName    = "fake";
            var returnPoke = new RawPokemon();

            returnPoke = null;
            var mockRepo    = new Mock <IPokemonRepository>();
            var pokeService = new PokemonService(mockRepo.Object);

            mockRepo.Setup(a => a.GetPokemon(badName)).Returns(returnPoke);

            Assert.Throws <ApiException>(() => pokeService.GetPokemon(badName));
        }
示例#11
0
        public void ShouldIndicateCheckupAlert()
        {
            // Arrange
            A.CallTo(() => _PokemonRespository.GetPokemon(A <int> .Ignored)).Returns(new Pokemon
            {
                NextCheckup = DateTime.Now.AddDays(13)
            });

            // Act (SUT)
            var PokemonService   = new PokemonService(_PokemonRespository);
            var PokemonViewModel = PokemonService.GetPokemon(1);

            // Assert
            Assert.IsTrue(PokemonViewModel.CheckupAlert);
        }
示例#12
0
        public void TestMissingCharacteristicPokeServiceThrowsException()
        {
            var name       = "test name";
            var id         = 1;
            var returnPoke = new RawPokemon();

            returnPoke.Name = name;
            returnPoke.Id   = id;
            var pokeCharacteristic = new PokemonCharacteristic();

            pokeCharacteristic = null;
            var mockRepo    = new Mock <IPokemonRepository>();
            var pokeService = new PokemonService(mockRepo.Object);

            mockRepo.Setup(a => a.GetPokemon(name)).Returns(returnPoke);
            mockRepo.Setup(a => a.GetCharacteristic(id)).Returns(pokeCharacteristic);
            Assert.Throws <ApiException>(() => pokeService.GetPokemon(name));
        }
        private async Task CarregarPokemon(int id)
        {
            try
            {
                Ocupado = true;

                var pokemon = await _ApiService.GetPokemon(_cont);

                _mapper.Map(pokemon, this);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                Ocupado = false;
            }
        }
        protected async override Task OnInitializedAsync()
        {
            int.TryParse(Id, out int pokemonId);

            if (pokemonId != 0)
            {
                PageHeader = "Edit Pokemon";
                Pokemon    = await PokemonService.GetPokemon(int.Parse(Id));
            }
            else
            {
                PageHeader = "Create Pokemon";
                Pokemon    = new Pokemon
                {
                    TypeOneId   = 1,
                    DateOfBirth = DateTime.Now,
                    PhotoPath   = "images/nophoto.jpg"
                };
            }
            PokemonTypes = (await PokemonTypeService.GetPokemonTypes()).ToList();
            Mapper.Map(Pokemon, EditPokemonModel);
        }
 public async Task <PokemonEntry> GetPokemonById(int pokemonId)
 {
     Logger.LogInformation($"Getting Pokemon {pokemonId}...");
     return(await PokemonService.GetPokemon(pokemonId));
 }
示例#16
0
 protected async override Task OnInitializedAsync()
 {
     Id      = Id ?? "1";
     Pokemon = await PokemonService.GetPokemon(int.Parse(Id));
 }
示例#17
0
 public async Task GetPokemon_Null_ThrowsArgumentNullException()
 {
     string name = null;
     await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => _pokemonService.GetPokemon(name));
 }
        public async Task <ActionResult <object> > GetPokemon(int id)
        {
            var result = await service.GetPokemon(id);

            return(result);
        }