Example #1
0
        public void FindSiteIdFromSiteNumberTest()
        {
            // Arrange
            int campgroundId1;
            int campgroundId2;
            int siteId1;
            int siteId2;

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                SqlCommand command = new SqlCommand(
                    @"SELECT campground_id
                      FROM campground
                      WHERE name = 'The Back Yard'",
                    connection);

                SqlCommand command2 = new SqlCommand(
                    @"SELECT campground_id
                      FROM campground
                      WHERE name = 'The Front Yard'",
                    connection);

                SqlCommand command3 = new SqlCommand(
                    @"SELECT site_id
                      FROM site
                      WHERE site_number = 2
                      AND campground_id = @campground_id",
                    connection);

                SqlCommand command4 = new SqlCommand(
                    @"SELECT site_id
                      FROM site
                      WHERE site_number = 1
                      AND campground_id = @campground_id",
                    connection);

                connection.Open();

                campgroundId1 = Convert.ToInt32(command.ExecuteScalar());
                campgroundId2 = Convert.ToInt32(command2.ExecuteScalar());

                command3.Parameters.AddWithValue("@campground_id", campgroundId1);
                command4.Parameters.AddWithValue("@campground_id", campgroundId2);

                siteId1 = Convert.ToInt32(command3.ExecuteScalar());
                siteId2 = Convert.ToInt32(command4.ExecuteScalar());
            }

            Assert.AreEqual(siteId1, dao.FindSiteIdFromSiteNumber(2, campgroundId1));
            Assert.AreEqual(siteId2, dao.FindSiteIdFromSiteNumber(1, campgroundId2));
        }