public static List<Venue> GetAll() { List<Venue> allVenues = new List<Venue>{}; SqlConnection conn = DB.Connection(); SqlDataReader rdr = null; conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM venues;", conn); rdr = cmd.ExecuteReader(); while(rdr.Read()) { int venueId = rdr.GetInt32(0); string name = rdr.GetString(1); Venue newVenue = new Venue(name, venueId); allVenues.Add(newVenue); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return allVenues; }
public static Venue Find(int venueId) { SqlConnection conn = DB.Connection(); SqlDataReader rdr; conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM venues WHERE id = @venueId;", conn); SqlParameter venueIdParameter = new SqlParameter(); venueIdParameter.ParameterName = "@venueId"; venueIdParameter.Value = venueId.ToString(); cmd.Parameters.Add(venueIdParameter); int foundVenueId = 0; string foundVenueName = null; rdr = cmd.ExecuteReader(); while(rdr.Read()) { foundVenueId = rdr.GetInt32(0); foundVenueName = rdr.GetString(1); } Venue newVenue = new Venue(foundVenueName, foundVenueId); if (rdr != null) rdr.Close(); if (conn != null) conn.Close(); return newVenue; }
public void Test_AddShow_AddsAShowWithBandAndVenue() { //Arrange Band testBand = new Band("Ween"); testBand.Save(); Venue testVenue = new Venue("Chad's"); testVenue.Save(); //Act testVenue.AddShow(testBand.GetId(), testDate); List<Venue> expectedVenue = new List<Venue> {testVenue}; List<Venue> result= testBand.GetVenues(); //Assert Assert.Equal(expectedVenue, result); }
public void Test_DeleteOne_DeletesASpecificVenueObject() { //Arrange Venue firstVenue = new Venue("Chad's"); firstVenue.Save(); Venue secondVenue = new Venue("Todd's"); secondVenue.Save(); //Act secondVenue.Delete(); List<Venue> expectedVenue = new List<Venue> {firstVenue}; List<Venue> testVenue= Venue.GetAll(); //Assert Assert.Equal(expectedVenue, testVenue); }
public List<Venue> GetVenues() { SqlConnection conn = DB.Connection(); SqlDataReader rdr = null; conn.Open(); SqlCommand cmd = new SqlCommand("SELECT venues.* FROM bands JOIN shows ON (shows.band_id = bands.id) JOIN venues ON (shows.venue_id = venues.id) WHERE band_id = @BandId ORDER BY shows.date DESC;", conn); SqlParameter bandIdParameter = new SqlParameter(); bandIdParameter.ParameterName = "@BandId"; bandIdParameter.Value = this.GetId(); cmd.Parameters.Add(bandIdParameter); rdr=cmd.ExecuteReader(); List<Venue> foundVenues = new List<Venue>{}; while(rdr.Read()) { int foundId = rdr.GetInt32(0); string foundName = rdr.GetString(1); Venue foundVenue = new Venue(foundName, foundId); foundVenues.Add(foundVenue); } if(rdr!=null) rdr.Close(); if(conn!=null) conn.Close(); return foundVenues; }
public void Test_Save_SavesCorrectObjectToDatabase() { //Arrange Venue newVenue = new Venue("Chad's"); //Act newVenue.Save(); Venue savedVenue = Venue.GetAll()[0]; //Assert Assert.Equal(newVenue, savedVenue); }
public void Test_Find_ReturnsASpecificVenueObject() { //Arrange Venue newVenue = new Venue("Chad's"); newVenue.Save(); //Act Venue foundVenue = Venue.Find(newVenue.GetId()); //Assert Assert.Equal(newVenue, foundVenue); }
public void Venue_Update_UpdatesVenue() { Venue firstVenue = new Venue("Chad's"); firstVenue.Save(); firstVenue.Update("Todd's"); Venue resultVenue = Venue.Find(firstVenue.GetId()); Assert.Equal("Todd's", resultVenue.GetName()); }
public void Dispose() { Band.DeleteAll(); Venue.DeleteAll(); }