Пример #1
0
        public void GetFilmsTest()
        {
            HttpClient        client            = new HttpClient();
            FilmsDeserializer filmsDeserializer = new FilmsDeserializer();
            FilmsHandler      filmsHandler      = new FilmsHandler(client, filmsDeserializer);
            List <Film>       films             = filmsHandler.Handle(HttpMethod.Get, "https://ghibliapi.herokuapp.com/films", null, null);

            Assert.AreEqual(20, films.Count, "Wrong number of films");
        }
Пример #2
0
        static void UI(HttpClient client)
        {
            while (true)
            {
                Console.WriteLine("Type number to choose command:");
                Console.WriteLine("1. Show all films id and title");
                Console.WriteLine("2. Show film by id");
                Console.WriteLine("3. Show all people id and name");
                Console.WriteLine("4. Show people by id");
                Console.WriteLine("5. End program");

                var command = Console.ReadLine();

                switch (command)
                {
                case "1":
                    FilmsDeserializer filmsParser  = new FilmsDeserializer();
                    FilmsHandler      filmsHandler = new FilmsHandler(client, filmsParser);
                    WriteAllFilmsIdAndTitle(filmsHandler.Handle(HttpMethod.Get, GHIBLI_SITE + "films", null, null));
                    break;

                case "2":
                    Console.WriteLine("Enter film id:");
                    var filmId = Console.ReadLine();
                    FilmDeserializer filmParser  = new FilmDeserializer();
                    FilmHandler      filmHandler = new FilmHandler(client, filmParser);
                    filmHandler.Handle(HttpMethod.Get, $"{GHIBLI_SITE}films/{filmId}", null, null).WriteFilm(client);
                    break;

                case "3":
                    AllPeopleDeserializer allPeopleDeserializer = new AllPeopleDeserializer();
                    AllPeopleHandler      allPeopleHandler      = new AllPeopleHandler(client, allPeopleDeserializer);
                    WriteAllPeopleIdAndName(allPeopleHandler.Handle(HttpMethod.Get, GHIBLI_SITE + "people", null, null));
                    break;

                case "4":
                    Console.WriteLine("Enter people id:");
                    var peopleId = Console.ReadLine();
                    PeopleDeserializer peopleDeserializer = new PeopleDeserializer();
                    PeopleHandler      peopleHandler      = new PeopleHandler(client, peopleDeserializer);
                    peopleHandler.Handle(HttpMethod.Get, $"{GHIBLI_SITE}people/{peopleId}", null, null).WritePeople();
                    break;

                case "5":
                    return;

                default:
                    Console.WriteLine("Wrong option! Try again.");
                    break;
                }

                Console.WriteLine();
            }
        }