コード例 #1
0
        private async Task Given_NotfoundResponse_When_GetAsync_HttpRequest_Throws_Exception()
        {
            //Arrange
            var client = SetupClient(HttpStatusCode.NotFound, new StringContent(""));

            //Act & Assert
            var pokeService = new PokeService(client);
            await Assert.ThrowsAsync <HttpResponseException>(() => pokeService.GetBasicPokemonInfoAsync("abcd"));
        }
コード例 #2
0
        public async Task Given_InvalidRequest_When_GetBasicPokemonInfoAsync_IsCalled_Throws_Exception()
        {
            //Arrange
            var httpClient = new HttpClient()
            {
                BaseAddress = new Uri(config["PokeService:BaseUri"].Replace("v2", ""))
            };
            string queryInput = "hello";

            //Act & Assert
            var pokeService = new PokeService(httpClient);
            await Assert.ThrowsAsync <HttpResponseException>(() => pokeService.GetBasicPokemonInfoAsync(queryInput));
        }
コード例 #3
0
        private async Task Given_ValidInput_WithMissingProperty_When_GetAsync_HttpRequest_Returns_ValidResponse()
        {
            //Arrange
            var client = SetupClient(HttpStatusCode.OK, new StringContent(PokeApiClientData.jsonData_MissingProperty));

            //Act
            var pokeService = new PokeService(client);
            var response    = await pokeService.GetBasicPokemonInfoAsync("mewtwo");

            //Assert
            Assert.NotNull(response);
            Assert.Equal("mewtwo", response.Name);
            Assert.True(response.IsLegendary);
            Assert.Null(response.FlavorTextEntries);
            Assert.Equal("rare", response.Habitat.Name);
        }
コード例 #4
0
        private async Task Given_IncorrectResponse_when_GetAsync_HttpRequest_returns_defaultValues()
        {
            //Arrange
            var client = SetupClient(HttpStatusCode.OK, new StringContent(PokeApiClientData.jsonData_Invalid));

            //Act
            var pokeService = new PokeService(client);
            var response    = await pokeService.GetBasicPokemonInfoAsync("mewtwo");

            //Assert
            Assert.NotNull(response);
            Assert.Null(response.Name);
            Assert.False(response.IsLegendary);
            Assert.Null(response.FlavorTextEntries);
            Assert.Null(response.Habitat);
        }
コード例 #5
0
        private async Task Given_ValidInput_When_GetAsync_HttpRequest_Returns_ValidResponse()
        {
            //Arrange
            var client = SetupClient(HttpStatusCode.OK, new StringContent(PokeApiClientData.jsonData));

            //Act
            var pokeService = new PokeService(client);
            var response    = await pokeService.GetBasicPokemonInfoAsync("mewtwo");

            //Assert
            Assert.NotNull(response);
            Assert.Equal("mewtwo", response.Name);
            Assert.True(response.IsLegendary);
            Assert.Equal("It was created by\na scientist after\nyears of horrific\fgene splicing and\nDNA engineering\nexperiments.", response.FlavorTextEntries.First().FlavorText);
            Assert.Equal("rare", response.Habitat.Name);
        }
コード例 #6
0
        public async Task Given_ValidRequest_When_GetBasicPokemonInfoAsync_IsCalled_Then_Returns_PokemonInfo()
        {
            //Arrange
            var httpClient = new HttpClient()
            {
                BaseAddress = new Uri(config["PokeService:BaseUri"])
            };
            string queryInput = "mewtwo";

            //Act
            var pokeService = new PokeService(httpClient);
            var result      = await pokeService.GetBasicPokemonInfoAsync(queryInput).ConfigureAwait(false);

            //Assert
            Assert.NotNull(result);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: EOlivier48/PokeProject
        static void Main(string[] args)
        {
            PokeService pokeService = new PokeService();
            bool        quit        = false;

            while (quit != true)
            {
                string pokeName = "";
                Console.WriteLine("Type a pokemon name or type quit to quit.");
                pokeName = Console.ReadLine();
                pokeName = pokeName.Trim().ToLower().Replace(".", "").Replace(" ", "-");

                if (pokeName != "quit")
                {
                    if (pokeName == "")
                    {
                        continue;
                    }

                    try
                    {
                        pokemon pokeObj = pokeService.GetPokemon(pokeName, true);
                        NiceOutput(pokeObj);
                    }
                    catch (Exception e) when(e.Message == "Pokemon not found.")
                    {
                        Console.WriteLine(e.Message);
                        continue;
                    }
                }
                else
                {
                    quit = true;
                }
            }
        }
コード例 #8
0
ファイル: Logic.cs プロジェクト: xxxx0107/Pokemont
        private async Task StatsLog(Client client)
        {
            dontspam++;
            var profil = await _client.GetCachedProfile();

            var stats = await _inventory.GetPlayerStats();

            var c = stats.FirstOrDefault();

            int l = c.Level;

            var expneeded       = ((c.NextLevelXp - c.PrevLevelXp) - StringUtils.getExpDiff(c.Level));
            var curexp          = ((c.Experience - c.PrevLevelXp) - StringUtils.getExpDiff(c.Level));
            var curexppercent   = (Convert.ToDouble(curexp) / Convert.ToDouble(expneeded)) * 100;
            var pokemonToEvolve = (await _inventory.GetPokemonToEvolve(null)).Count();

            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "_____________________________");
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "Level: " + c.Level);
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "EXP Needed: " + expneeded);
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, $"Current EXP: {curexp} ({Math.Round(curexppercent)}%)");
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "EXP to Level up: " + ((c.NextLevelXp) - (c.Experience)));
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "KM Walked: " + c.KmWalked);
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "PokeStops visited: " + c.PokeStopVisits);
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "Stardust: " + profil.Profile.Currency.ToArray()[1].Amount);
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "Pokemon to evolve: " + pokemonToEvolve);
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "Pokemons: " + await _inventory.getPokemonCount() + "/" + profil.Profile.PokeStorage);
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "Items: " + await _inventory.getInventoryCount() + "/" + profil.Profile.ItemStorage);
            if (dontspam >= 3)
            {
                dontspam = 0;
                PokeService data = null;
                try
                {
                    var clientx = new WebClient();
                    clientx.Headers.Add("user-agent", "PokegoBot-Ar1i-Github");
                    var jsonString = clientx.DownloadString("https://go.jooas.com/status");
                    data = new JavaScriptSerializer().Deserialize <PokeService>(jsonString);
                }
                catch (Exception)
                {
                }

                if (data != null)
                {
                    Logger.ColoredConsoleWrite(ConsoleColor.White, "");
                    Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "PokemonGO Server Status:");
                    if (data.go_online)
                    {
                        if (data.go_idle > 60)
                        {
                            int gohour = Convert.ToInt32(data.go_idle / 60);

                            if (gohour > 24)
                            {
                                int goday = gohour / 24;

                                Logger.ColoredConsoleWrite(ConsoleColor.Green, "Online since ~" + goday + " day(s).");
                            }
                            else
                            {
                                Logger.ColoredConsoleWrite(ConsoleColor.Green, "Online since ~" + gohour + "h.");
                            }
                        }
                        else
                        {
                            Logger.ColoredConsoleWrite(ConsoleColor.Green, "Online since ~" + data.go_idle + " min.");
                        }

                        Logger.ColoredConsoleWrite(ConsoleColor.Green, "Server anwsers in ~" + data.go_response + " seconds.");
                    }
                    else
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.Red, "Pokemon GO Servers: Offline.");
                    }
                    Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "Pokemon Trainer Club Server Status:");
                    if (data.ptc_online)
                    {
                        if (data.ptc_idle > 60)
                        {
                            int ptchour = Convert.ToInt32(data.ptc_idle / 60);

                            if (ptchour > 24)
                            {
                                int ptcday = ptchour / 24;
                                Logger.ColoredConsoleWrite(ConsoleColor.Green, "Online since ~" + ptcday + " day(s).");
                            }
                            else
                            {
                                Logger.ColoredConsoleWrite(ConsoleColor.Green, "Online since ~" + ptchour + "h.");
                            }
                        }
                        else
                        {
                            Logger.ColoredConsoleWrite(ConsoleColor.Green, "Online since ~" + data.ptc_idle + " min.");
                        }

                        Logger.ColoredConsoleWrite(ConsoleColor.Green, "Server anwsers in ~" + data.ptc_response + " seconds.");
                    }
                    else
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.Red, "Pokemon Trainer Club: Offline.");
                    }
                }
                else
                {
                    Logger.ColoredConsoleWrite(ConsoleColor.Red, "Cant get Server Status from https://go.jooas.com/status");
                }
            }
            Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "_____________________________");


            System.Console.Title = "PokeBot3 | User: "******" | Level " + c.Level + " - (" + ((c.Experience - c.PrevLevelXp) -
                                                                                                                     StringUtils.getExpDiff(c.Level)) + " / " + ((c.NextLevelXp - c.PrevLevelXp) - StringUtils.getExpDiff(c.Level)) + " | " + Math.Round(curexppercent) + "%) | Stardust: " + profil.Profile.Currency.ToArray()[1].Amount + " | " + _botStats.ToString();
            Vars.username    = profil.Profile.Username;
            Vars.xprate      = _botStats.xprate();
            Vars.catchrate   = _botStats.catchrate();
            Vars.stardust    = profil.Profile.Currency.ToArray()[1].Amount.ToString();
            Vars.evolvecount = pokemonToEvolve.ToString();
            Vars.pokemon     = await _inventory.getPokemonCount() + "/" + profil.Profile.PokeStorage;

            Vars.level      = "Level " + c.Level + " - (" + ((c.Experience - c.PrevLevelXp) - StringUtils.getExpDiff(c.Level)) + " / " + ((c.NextLevelXp - c.PrevLevelXp) - StringUtils.getExpDiff(c.Level)) + " | " + Math.Round(curexppercent) + "%)";
            Vars.percentage = Math.Round(curexppercent).ToString();
            Vars.items      = await _inventory.getInventoryCount() + "/" + profil.Profile.ItemStorage;
        }