public void InvalidUrlThrowsException()
        {
            var client = new HttpClient();
            var url    = "https://INVALIDurl.co";
            var path   = "api/starships/?format=json";

            client.BaseAddress = new Uri(url);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var ex = Assert.ThrowsAsync <Exception>(() => HttpRequestClient.GetShipAsync(path, client));
        }
Exemplo n.º 2
0
        static async Task RunAsync()
        {
            var shipsUnableToCalc = new List <string>();

            try
            {
                Ship[] ships = await HttpRequestClient.GetShipAsync("api/starships/?format=json", client);

                if (ships.Length > 0)
                {
                    foreach (var ship in ships)
                    {
                        if (ship.MGLT > 0)
                        {
                            Console.WriteLine(ship.Name + ": " + Calculations.GetResupplyCount(megaLights, ship));
                        }
                        else
                        {
                            shipsUnableToCalc.Add(ship.Name);
                        }
                    }

                    if (verboseOperation)
                    {
                        Console.WriteLine("\nUnable to calculate resupply frequence for the following ships:");
                        foreach (var s in shipsUnableToCalc)
                        {
                            Console.WriteLine(s);
                        }
                    }
                }
                else
                {
                    throw new Exception("No Ships were found\nMove along");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public void NullClientThrowsException()
        {
            var path = "api/starships/?format=json";

            var ex = Assert.ThrowsAsync <Exception>(() => HttpRequestClient.GetShipAsync(path, null));
        }