public void TestSetState() { ProductsProps newP = new ProductsProps(); string xml = p.GetState(); newP.SetState(xml); Assert.AreEqual(newP.ID, p.ID); Assert.AreEqual(newP.description, p.description); Assert.AreEqual(newP.unitPrice, p.unitPrice); Assert.AreEqual(newP.quantity, p.quantity); Assert.AreEqual(newP.code, p.code); }
public IBaseProps Retrieve(object key) { DBDataReader data = null; ProductsProps props = new ProductsProps(); DBCommand command = new DBCommand(); command.CommandText = "usp_ProductsSelect"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@ProductID", SqlDbType.Int); command.Parameters["@ProductID"].Value = (Int32)key; try { data = RunProcedure(command); if (!data.IsClosed) { if (data.Read()) { props.SetState(data); } else { throw new Exception("Record does not exist in the database."); } } return(props); } catch (Exception e) { // log this exception throw; } finally { if (data != null) { if (!data.IsClosed) { data.Close(); } } } }
public object RetrieveAll(Type type) { List <ProductsProps> results = new List <ProductsProps>(); DBDataReader data = null; ProductsProps props = new ProductsProps(); DBCommand command = new DBCommand(); command.CommandText = "usp_ProductsSelectAll"; command.CommandType = CommandType.StoredProcedure; try { data = RunProcedure(command); if (!data.IsClosed) { while (data.Read()) { props = new ProductsProps(); props.SetState(data); results.Add(props); } } return(results); } catch (Exception e) { // log this exception throw; } finally { if (data != null) { if (!data.IsClosed) { data.Close(); } } } }