Beispiel #1
0
        public void Test_CitiesEmptyAtFirst()
        {
            //Arrange, Act
            int result = City.GetAll().Count;

            //Assert
            Assert.Equal(0, result);
        }
        public HomeModule()
        {
            Get["/"] = _ => {
                List <City> allCities = City.GetAll();
                return(View["index.cshtml", allCities]);
            };

            Post["/"] = _ => {
                Flight newFlight = new Flight(Request.Form["departure"], Request.Form["departure-city"], Request.Form["arrival-city"], Request.Form["status"]);
                newFlight.Save();
                return(View["add_flight_success.cshtml", newFlight]);
            };

            Get["/cities"] = _ => {
                List <City> allCities = City.GetAll();
                return(View["cities.cshtml", allCities]);
            };

            Post["/cities"] = _ => {
                string userInput = Request.Form["name"];
                City   newCity   = new City(userInput);
                newCity.Save();
                List <City> allCities = City.GetAll();
                return(View["cities.cshtml", allCities]);
            };

            Get["/flights"] = _ => {
                List <Flight> allFlights = Flight.GetAll();
                return(View["flights.cshtml", allFlights]);
            };

            Post["/flights"] = _ => {
                string departure       = Request.Form["departure"];
                int    departureCityId = Request.Form["departure-city"];
                int    arrivalCityId   = Request.Form["arrival-city"];
                string status          = Request.Form["status"];

                City departureCity = City.Find(departureCityId);
                City arrivalCity   = City.Find(arrivalCityId);

                string departureCityString = departureCity.GetName();
                string arrivalCityString   = arrivalCity.GetName();

                Flight newFlight = new Flight(departure, departureCityString, arrivalCityString, status);
                newFlight.Save();
                newFlight.AddCities(departureCity, arrivalCity);

                List <Flight> allFlights = Flight.GetAll();
                return(View["flights.cshtml", allFlights]);
            };
        }
Beispiel #3
0
        public void Test_Save_AssignsIdToCityObject()
        {
            //Arrange
            City testCity = new City("Miami");

            testCity.Save();

            //Act
            City savedCity = City.GetAll()[0];

            int result = savedCity.GetId();
            int testId = testCity.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Beispiel #4
0
        public void Test_Save_SavesCityToDatabase()
        {
            //Arrange
            City testCity = new City("Miami");

            testCity.Save();

            //Act
            List <City> result   = City.GetAll();
            List <City> testList = new List <City> {
                testCity
            };

            //Assert
            Assert.Equal(testList, result);
        }