protected void btnApply_Click(object sender, EventArgs e) { Double tmp; // workaround for tryparse validation bool valid = Double.TryParse(txtMaxPriceFilter.Text, out tmp); //check value is valid // instantiate class clsStockCollection Stock = new clsStockCollection(); if (valid == false) { lblError.Text = "Invalid filter entered."; // error message } else if (tmp > 10000 || tmp < 0) { lblError.Text = "Invalid filter. Must be between 0 and 10000."; // another error } else { // Writing comments for the exact same code over and over is raising my blood pressure // so I'm not going to anymore // you know the drill by now Stock.FilterByMaxPrice(Convert.ToDouble(txtMaxPriceFilter.Text)); lstStockList.DataSource = Stock.StockList; lstStockList.DataValueField = "productId"; lstStockList.DataTextField = "productName"; lstStockList.DataBind(); } }
public void FilterByMaxPriceDataFound() { clsStockCollection FilteredStock = new clsStockCollection(); //instantiate class // outcome bool Boolean OK = true; // should not normally be possible for an item to be free // but a test record should be created with a price of 0.00 to test this method FilteredStock.FilterByMaxPrice(0.00); // should be exactly 1 result if (FilteredStock.Count == 1) { // if doesn't match the specific name, change bool to false if (FilteredStock.StockList[0].productName != "TESTITEM-IGNORE") { OK = false; } } else { OK = false; // if count 0 also make it false } Assert.IsTrue(OK); }
public void FilterByMaxPriceNoneFound() { clsStockCollection FilteredStock = new clsStockCollection(); //instantiate class // price cannot be free so none should be found FilteredStock.FilterByMaxPrice(-1); // should be no records Assert.AreEqual(0, FilteredStock.Count); }
public void FilterByMaxPriceOK() { clsStockCollection AllStock = new clsStockCollection(); //instantiate class clsStockCollection FilteredStock = new clsStockCollection(); //instantiate class again // invoke method FilteredStock.FilterByMaxPrice(10000); // should be equal Assert.AreEqual(AllStock.Count, FilteredStock.Count); }
protected void btnClear_Click(object sender, EventArgs e) { // instantiate class clsStockCollection Stock = new clsStockCollection(); Stock.FilterByMaxPrice(10000); txtMaxPriceFilter.Text = ""; lstStockList.DataSource = Stock.StockList; lstStockList.DataValueField = "productId"; lstStockList.DataTextField = "productName"; lstStockList.DataBind(); }