public static List <Parasite> GetAll() { List <Parasite> allParasites = new List <Parasite> { }; SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM parasites;", conn); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { int parasiteId = rdr.GetInt32(0); string parasiteName = rdr.GetString(1); Parasite newParasite = new Parasite(parasiteName, parasiteId); allParasites.Add(newParasite); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(allParasites); }
public static Parasite Find(int id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM parasites WHERE id = @ParasiteId;", conn); SqlParameter parasiteIdParameter = new SqlParameter(); parasiteIdParameter.ParameterName = "@ParasiteId"; parasiteIdParameter.Value = id.ToString(); cmd.Parameters.Add(parasiteIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); int foundParasiteId = 0; string foundParasiteName = null; while (rdr.Read()) { foundParasiteId = rdr.GetInt32(0); foundParasiteName = rdr.GetString(1); } Parasite foundParasite = new Parasite(foundParasiteName, foundParasiteId); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(foundParasite); }
public void Test_DatabaseEmptyAtFirst() { //Arrange, Act int result = Parasite.GetAll().Count; //Assert Assert.Equal(0, result); }
public void Test_Equal_ReturnsTrueIfNamesAreTheSame() { //Arrange, Act Parasite firstParasite = new Parasite("Duck with Muscles"); Parasite secondParasite = new Parasite("Duck with Muscles"); //Assert Assert.Equal(firstParasite, secondParasite); }
public void Test_Find_FindsParasiteInDatabase() { // Arrange Parasite testParasite = new Parasite("Pencilvestyr"); testParasite.Save(); // Act Parasite foundParasite = Parasite.Find(testParasite.GetId()); // Assert Assert.Equal(testParasite, foundParasite); }
public override bool Equals(System.Object otherParasite) { if (!(otherParasite is Parasite)) { return(false); } else { Parasite newParasite = (Parasite)otherParasite; bool idEquality = (this.GetId() == newParasite.GetId()); bool nameEquality = (this.GetName() == newParasite.GetName()); return(idEquality && nameEquality); } }
public void Test_Save_AssignsIdToObject() { //Arrange Parasite testParasite = new Parasite("Hamurai"); //Act testParasite.Save(); Parasite savedParasite = Parasite.GetAll()[0]; int result = savedParasite.GetId(); int testId = testParasite.GetId(); //Assert Assert.Equal(testId, result); }
public void Test_Save_SavesToDatabase() { // Arrange Parasite testParasite = new Parasite("Sleepy Gary"); // Act testParasite.Save(); List <Parasite> result = Parasite.GetAll(); List <Parasite> testList = new List <Parasite> { testParasite }; // Assert Assert.Equal(testList, result); }
public void Dispose() { Parasite.DeleteAll(); }