public void GetParksTest() { Park _expectedPark1 = new Park(1, "Acadia", "Maine", Convert.ToDateTime("1919-02-26"), 47389, 2563129, "Covering most of Mount Desert Island and other coastal islands, Acadia features the tallest mountain on the Atlantic coast of the United States, granite peaks, ocean shoreline, woodlands, and lakes. There are freshwater, estuary, forest, and intertidal habitats."); Park _expectedPark2 = new Park(2, "Arches", "Utah", Convert.ToDateTime("1929-04-12"), 76518, 1284767, "This site features more than 2,000 natural sandstone arches, including the famous Delicate Arch. In a desert climate, millions of years of erosion have led to these structures, and the arid ground has life-sustaining soil crust and potholes, which serve as natural water-collecting basins. Other geologic formations are stone columns, spires, fins, and towers."); Park _expectedPark3 = new Park(3, "Cuyahoga Valley", "Ohio", Convert.ToDateTime("2000-10-11"), 32860, 2189849, "This park along the Cuyahoga River has waterfalls, hills, trails, and exhibits on early rural living. The Ohio and Erie Canal Towpath Trail follows the Ohio and Erie Canal, where mules towed canal boats. The park has numerous historic homes, bridges, and structures, and also offers a scenic train ride."); Dictionary <int, Park> _expectedparks = new Dictionary <int, Park> { { 1, _expectedPark1 }, { 2, _expectedPark2 }, { 3, _expectedPark3 } }; Dictionary <int, Park> _parks = _db.GetParks(); for (int i = 1; i <= _parks.Count; i++) { Assert.AreEqual(_expectedparks[i].Id, _parks[i].Id); Assert.AreEqual(_expectedparks[i].Name, _parks[i].Name); Assert.AreEqual(_expectedparks[i].Location, _parks[i].Location); Assert.AreEqual(_expectedparks[i].EstablishDate, _parks[i].EstablishDate); Assert.AreEqual(_expectedparks[i].Area, _parks[i].Area); Assert.AreEqual(_expectedparks[i].AnnualVisitors, _parks[i].AnnualVisitors); Assert.AreEqual(_expectedparks[i].Description, _parks[i].Description); } }
public void Start() { bool quit = false; try { _parks = _db.GetParks(); } catch (Exception ex) { Console.Clear(); Console.WriteLine(ex); Console.WriteLine("Unexpected error when reading parks from database"); Console.WriteLine("Application will now close..."); Console.ReadKey(); quit = true; } if (_parks.Count == 0) { Console.Clear(); Console.WriteLine("Unexpected error when reading parks from database"); Console.WriteLine("Application will now close..."); Console.ReadKey(); quit = true; } while (!quit) { Console.Clear(); Console.WriteLine("Select a Park for Further Details"); foreach (var park in _parks) { Console.WriteLine($"{park.Value.Id}) {park.Value.Name}"); } Console.WriteLine("Q) quit"); string userChoice = Console.ReadLine(); if (userChoice.ToLower() == "q") { Console.Clear(); Console.WriteLine("Thanks for using our app!"); Console.ReadKey(); quit = true; } else { try { int choice = int.Parse(userChoice); if (_parks.ContainsKey(choice)) { ViewParkInfoMenu(choice); } else { throw new Exception(); } } catch { Console.Clear(); Console.WriteLine("Please enter only valid park numbers"); Console.Write("Press any key to return to the park list..."); Console.ReadKey(); } } } }
public void Start() { bool quit = false; try { _parks = _db.GetParks(); } catch (Exception ex) { ApplicationLoadError(ex); quit = true; } if (_parks.Count == 0) { ApplicationLoadError(new ParkNotFoundException("No parks exist in the database")); quit = true; } while (!quit) { Console.Clear(); Console.WriteLine("Select a Park for Further Details"); foreach (var park in _parks) { Console.WriteLine($"{park.Value.Id}) {park.Value.Name}"); } Console.WriteLine("Q) quit"); string userChoice = Console.ReadLine(); if (userChoice.ToLower() == "q") { Console.Clear(); Console.WriteLine("Thanks for using our app!"); Thread.Sleep(3000); quit = true; } else { try { int choice = int.Parse(userChoice); if (_parks.ContainsKey(choice)) { ViewParkInfoMenu(choice); } else { throw new OnlyValidChoiceException("Please enter only valid park numbers"); } } catch (Exception ex) { Console.Clear(); Console.WriteLine(ex.Message); Console.Write("Press any key to return to the park list..."); Console.ReadKey(); } } } }