public void Setup() { translateAPIService = new TranslateAPIService(); pokemonAPIService = new PokemonAPIService(); pokemonService = new PokemonService(translateAPIService, pokemonAPIService, Mapper); pokemonController = new PokemonController(pokemonService); }
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; }
public IHttpActionResult Get() { PokemonService pokemonService = CreatePokemonService(); var pokemon = pokemonService.GetPokemon(); return(Ok(pokemon)); }
public async Task GetAll_TwoPokemonInDb_GetsBoth() { var pokemons = new List <Pokemon>() { new Pokemon() { Id = Guid.Parse("47b176a6-535f-447b-9f09-86465f07967a"), Abilities = new List <PokemonAbility>() { new PokemonAbility() { Ability = new Ability() { Name = "Leaf strike" } } } }, new Pokemon() { Id = Guid.Parse("47b176a6-535f-447b-9f09-86465f07967b") } }; // arrange var repository = new Mock <IRepository <Pokemon> >(); repository.Setup(x => x.GetAll( null, null, It.IsAny <Func <IQueryable <Pokemon>, IIncludableQueryable <Pokemon, object> > >(), true, CancellationToken.None )).ReturnsAsync(pokemons); var mapper = TestHelper.GetMapper(); var logger = new NullLogger <PokemonService>(); var service = new PokemonService(mapper: mapper, validator: null, repository: repository.Object, logger: logger); // act var result = (await service.GetAll(CancellationToken.None)).ToList(); // assert Assert.Equal(pokemons[0].Id, result[0].Id); Assert.Equal(pokemons[0].Abilities.ToList()[0].Ability.Name, result[0].Abilities.ToList()[0].Name); Assert.Equal(pokemons[1].Id, result[1].Id); repository.Verify(x => x.GetAll(null, null, It.IsAny <Func <IQueryable <Pokemon>, IIncludableQueryable <Pokemon, object> > >(), true, CancellationToken.None) , Times.Once); repository.VerifyNoOtherCalls(); }
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)); }
protected override async Task OnInitializedAsync() { Pokemon = await PokemonService.GetPokemon(int.Parse(Id)); PokemonTypes = (await PokemonTypeService.GetPokemonTypes()).ToList(); Mapper.Map(Pokemon, EditPokemonModel); }
public void Setup() { _pokemonClient = new Mock <IPokemonClient>(); _translatorClient = new Mock <ITranslatorClient>(); _pokemonService = new PokemonService(_pokemonClient.Object, _translatorClient.Object); }
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 TwitchBot(string _channelName) { //Init Client twitchClient = new TwitchClient(); twitchPubSub = new TwitchPubSub(); //Init Database this.db = new AppDbContextFactory().Create(); //Init access accessService = new AccessService(); //Init Twitch API api = new TwitchAPI(); api.Settings.ClientId = accessService.GetTwitchClientID(); api.Settings.AccessToken = accessService.GetTwitchAccessToken(); //Init services this.achievementService = new AchievementService(db); this.settingsService = new SettingsService(db); this.pokemonService = new PokemonService(db); userService = new UserService(db, api); chatOutputService = new ChatOutputService(twitchClient, _channelName); bossService = new BossService(userService, pokemonService, chatOutputService, settingsService); userfightService = new UserfightService(userService, chatOutputService); chatService = new ChatInputService(userService, chatOutputService, bossService, userfightService, achievementService); destinationChannelName = _channelName; Connect(); }
public IHttpActionResult GetPokemonList() { PokemonService service = CreatePokemonService(); var pokeList = service.GetPokemonList(); return(Ok(pokeList)); }
public PlayerController(UserService userService, PokemonSpeciesService pokemonSpeciesService, PokemonService pokemonService, UserRepository userRepository) { _userService = userService; _pokemonSpeciesService = pokemonSpeciesService; _pokemonService = pokemonService; _userRepository = userRepository; }
public IHttpActionResult GetPokemonSingle(int id) { PokemonService service = CreatePokemonService(); var pokemon = service.GetPokemonByID(id); return(Ok(pokemon)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); pokeRecycler = FindViewById <RecyclerView>(Resource.Id.recycler_poke); pokeRecycler.HasFixedSize = true; adapter = new PokemonAdapter(pokemons, this); pokeRecycler.SetAdapter(adapter); JsonConvert.DefaultSettings = () => new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), Converters = { new StringEnumConverter() } }; try { pokemonService = RestService.For <PokemonService>("https://pokeapi.co"); } catch (Exception e) { Log.Error("TAGG", e.StackTrace); } getData(); }
private string _key = "PokemonCache"; //Chave com o nome do objeto que armazena os dados. public MonkeyCacheViewModel() { Pokemons = new ObservableCollection <PokemonLTB>(); _pokemonService = new PokemonService(); CarregaPokemons(); }
private PokemonService CreatePokemonService() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new PokemonService(userId); return(service); }
public LiteDbViewModel() { Pokemons = new ObservableCollection <PokemonLTB>(); _pokemonService = new PokemonService(); _dataBase = new LiteDatabase(Path.Combine(FileSystem.AppDataDirectory, "MeuBanco.db")); }
public PokemonControllerTests() { pokemonRepository = new PokemonRepository(new HttpClient()); translatorRepository = new TranslatorRepository(new HttpClient()); _pokemonService = new PokemonService(pokemonRepository, translatorRepository); _pokemonController = new PokemonController(_pokemonService); }
public ActionResult Editar(int id) { var service = new PokemonService(); var pokemon = service.BuscarPorID(id); return(View("Delete", pokemon)); }
public ActionResult Delete(Pokemon pokemon) { var service = new PokemonService(); service.Deletar(pokemon.Id); return(View("Index", service.FindAll())); }
public ActionResult Save(PokemonModel pokemon) { var servico = new PokemonService(); servico.Save(pokemon); return(RedirectToAction("Index")); }
public ActionResult Index(string searchString) { var service = new PokemonService(); List <Pokemon> filterPokemons = service.FindByText(searchString); List <PokemonViewModel> allPokemonsVms = (from x in filterPokemons select new PokemonViewModel(x)).ToList(); return(PartialView("_PartialList_Pokemons", allPokemonsVms)); }
private async Task ExecuteRefreshCommand() { IsBusy = true; var pokemonService = new PokemonService(); var pokemons = await pokemonService.GetAll(); this.Items = pokemons; IsBusy = false; }
public ActionResult Delete(int?id) { var service = new PokemonService(); Pokemon pokemon = service.FindById((int)id); PokemonViewModel poker = new PokemonViewModel(pokemon); return(View(poker)); }
public async Task Pokemon(CommandContext ctx, [Description("Name of the Pokémon")][RemainingText] string query) { var results = await PokemonService.GetPokemonCardsAsync(query).ConfigureAwait(false); if (results.Cards.Count == 0) { await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false); } else { foreach (var dex in results.Cards) { var card = PokemonService.GetExactPokemon(dex.ID); var output = new DiscordEmbedBuilder() .WithTitle(card.Name) .WithDescription("Pokédex ID: " + card.NationalPokedexNumber.ToString() ?? "Unknown") .AddField("Series", card.Series ?? "Unknown", true) .AddField("Rarity", card.Rarity ?? "Unknown", true) .AddField("HP", card.Hp ?? "Unknown", true) .AddField("Ability", (card.Ability != null) ? card.Ability.Name : "Unknown", true) .WithImageUrl(card.ImageUrlHiRes ?? card.ImageUrl) .WithFooter(!card.Equals(results.Cards.Last()) ? "Type 'next' within 10 seconds for the next Pokémon" : "This is the last found Pokémon on the list.") .WithColor(DiscordColor.Gold); var types = new StringBuilder(); foreach (var type in card.Types) { types.Append(type); } output.AddField("Types", types.ToString() ?? "Unknown", true); var weaknesses = new StringBuilder(); foreach (var weakness in card.Weaknesses) { weaknesses.Append(weakness.Type); } output.AddField("Weaknesses", weaknesses.ToString() ?? "Unknown", true); await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false); if (results.Cards.Count == 1) { continue; } var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false); if (interactivity.Result is null) { break; } if (!card.Equals(results.Cards.Last())) { await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false); } } } }
public ActionResult Index() { //var model = new PokemonListItem[0]; var userId = Guid.Parse(User.Identity.GetUserId()); var service = new PokemonService(userId); var model = service.GetAllPokemon(); return(View(model)); }
public PokemonViewModel() { Titulo = "AutoMapper Exemplo"; _ApiService = new PokemonService(); _mapper = AppBootstrapper.CreateMapper(); ObterProximoPokemonCommand = new Command(ExecuteObterProximoPokemonCommand); }
public void Setup() { this.pokeApiClient = new PokeApiClient(); this.pokemonService = new PokemonService(this.pokeApiClient); this.shakespeareService = new ShakespeareService(); this.cacheService = new CacheService(); this.translationService = new TranslationService(pokemonService, shakespeareService, cacheService); }
public async void ShouldReturnTooManyStatusCode() { //arrange var handlerMockPokeAPI = new Mock <HttpMessageHandler>(); var responsePokeAPI = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(@"{""flavor_text_entries"":[{""flavor_text"":""Its nature is to store up electricity. Forests\nwhere nests of Pikachu live are dangerous,\nsince the trees are so often struck by lightning."",""language"":{""name"":""en"",""url"":""https://pokeapi.co/api/v2/language/9/""},""version"":{""name"":""ultra-sun"",""url"":""https://pokeapi.co/api/v2/version/29/""}}]}"), }; handlerMockPokeAPI .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(responsePokeAPI); var httpClientPokeAPI = new HttpClient(handlerMockPokeAPI.Object); var handlerMockFunTranslationAPI = new Mock <HttpMessageHandler>(); var responseFunTranslationAPI = new HttpResponseMessage { StatusCode = HttpStatusCode.TooManyRequests, }; handlerMockFunTranslationAPI .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(responseFunTranslationAPI); var httpClientFunTranslationAPI = new HttpClient(handlerMockFunTranslationAPI.Object); var pokeApi = new PokeAPIRepository(httpClientPokeAPI); var funTranslationAPI = new FunTranslationAPIRepository(httpClientFunTranslationAPI); //act string nameOfPokemonToTranslate = "pikachu"; var pokemonService = new PokemonService(pokeApi, funTranslationAPI); var pokemon = await pokemonService.getPokemonFlavorTextTranslationAsync(nameOfPokemonToTranslate, "en"); //assert Assert.NotNull(pokemon); handlerMockPokeAPI.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get), ItExpr.IsAny <CancellationToken>()); handlerMockFunTranslationAPI.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post), ItExpr.IsAny <CancellationToken>()); Assert.Equal(HttpStatusCode.TooManyRequests.GetHashCode().ToString(), pokemon.description); }
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); }
public void OutOfRangeThrowsException() { IPokemonService service = new PokemonService(new ModInfo() { FolderPath = TestConstants.TestModFolder }); Action retrieveTooBigId = () => service.Retrieve(200); retrieveTooBigId.Should().Throw <ArgumentOutOfRangeException>(); }