예제 #1
0
        public void Setup()
        {
            transaction        = new TransactionScope();
            parkSqlDao         = new ParkSQLDAO(ConnectionString);
            weatherSqlDao      = new WeatherSQLDAO(ConnectionString);
            surveyResultSqlDAO = new SurveyResultSQLDAO(ConnectionString);

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                SqlCommand cmdPark    = new SqlCommand($"select count(*) from park where parkName = '{parkName}'", connection);
                SqlCommand cmdWeather = new SqlCommand($"select count(*) from weather where parkCode = '{parkCode}'", connection);
                SqlCommand cmdSurvey  = new SqlCommand($"select count(*) from survey_result where parkCode = '{parkCode}'", connection);


                if (Convert.ToInt32(cmdPark.ExecuteScalar()) == 0)
                {
                    cmdPark = new SqlCommand($"insert into park values('{parkCode}', '{parkName}', '{state}', {acreage}, {elevationInFeet}, '{milesOfTrail}', '{numberOfCampsites}', '{climate}', '{yearFounded}', '{annualVisitorCount}', '{inspirationalQuote}', '{inspirationalQuoteSource}', '{parkDescription}', '{entryFee}', '{numberOfAnimalSpecies}')", connection);
                    cmdPark.ExecuteNonQuery();
                }

                if (Convert.ToInt32(cmdWeather.ExecuteScalar()) == 0)
                {
                    cmdWeather = new SqlCommand($"insert into weather (parkCode, fiveDayForecastValue, low, high, forecast) values('{parkCode}', '{fiveDayForecastValue}', '{low}', '{high}', '{forecast}')", connection);
                    cmdWeather.ExecuteNonQuery();
                }

                if (Convert.ToInt32(cmdSurvey.ExecuteScalar()) == 0)
                {
                    cmdSurvey = new SqlCommand($"insert into survey_result (parkCode, emailAddress, state, activityLevel) values('{parkCode}', '{emailAddress}', '{state}', '{activityLevel}')", connection);
                    cmdSurvey.ExecuteNonQuery();
                }
            }
        }
예제 #2
0
        public void GetParks_ReturnAllParks()
        {
            //Arrange
            ParkSQLDAO dao = new ParkSQLDAO(this.connectionString);

            //Act
            IList <Park> list = dao.GetParks();

            //Assert
            Assert.AreEqual(1, list.Count);
        }
예제 #3
0
        static void Main(string[] args)
        {
            // Get the connection string from the appsettings.json file
            IConfigurationBuilder builder = new ConfigurationBuilder()
                                            .SetBasePath(Directory.GetCurrentDirectory())
                                            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();

            string connectionString = configuration.GetConnectionString("Project");

            ICampgroundDAO  campgroundDAO  = new CampgroundSQLDAO(connectionString);
            IParkDAO        parkDAO        = new ParkSQLDAO(connectionString);
            IReservationDAO reservationDAO = new ReservationSQLDAO(connectionString);
            ISiteDAO        siteDAO        = new SiteSQLDAO(connectionString);



            // Create a menu and run it
            ViewParksMenu menu = new ViewParksMenu(parkDAO, campgroundDAO, reservationDAO, siteDAO);

            menu.Run();
        }