public void Test1Buy() { //var mock = new Mock<ISerializer>; BuyRequest buy = new BuyRequest(); int i = buy.sendBuyRequest(4, 2, 10); Assert.AreNotEqual(-1, i); i = buy.sendBuyRequest(1000000900, 3, 10); Assert.AreEqual(-1, i); }
public void FixtureSetUp() { buy = new int[4]; BuyRequest s = new BuyRequest(); buy[0] = s.sendBuyRequest(3, 5, 3); buy[1] = s.sendBuyRequest(5, 2, 3); buy[2] = s.sendBuyRequest(2, 3, 3); buy[3] = s.sendBuyRequest(1, 4, 3); // this code runs once no matter how many tests are in this class }
private void ButtonBuy_Click(object sender, RoutedEventArgs e) { myLogger.Info("Buy button was pressed"); string c = commodity.Text; string a = amount.Text; string p = price.Text; if (c.Length != 0 & a.Length != 0 & p.Length != 0) { int cI = Convert.ToInt32(c); int aI = Convert.ToInt32(a); int pI = Convert.ToInt32(p); BuyRequest SB = new BuyRequest(); int output = SB.sendBuyRequest(pI, cI, aI); if (output == -1) { MessageBox.Show("Failed:"); } else { MessageBox.Show("The Buy is Done:request id:" + output); EnterHistory("Buy", cI, aI, pI, output, false); } } else { MessageBox.Show("full all the fields"); } commodity.Text = ""; amount.Text = ""; price.Text = ""; }
private void onTimedEvent(Object source, ElapsedEventArgs e) { sql.close(); sql.connect(); MarketUserData MYUSER = new MarketUserData(); MarketUserData myUser = MYUSER.SendQueryUserRequest(); AllMarketCommodityOffer MACO = new AllMarketCommodityOffer(); List <ComInfo> cominfo = MACO.SendQueryAllMarketRequest(); SqlDataReader rdr = sql.sendCommand("SELECT top 100 commodity, AVG(price) as 'average' FROM (SELECT commodity, price, timestamp FROM items where buyer = 20) commodity group by commodity order by commodity"); int counterS = 0; string Scom = ""; while (counterS < 10 && rdr.Read()) { Scom = "" + rdr["commodity"]; if (Convert.ToInt32(Scom) > 3 && myUser.commodities[Scom] > 1) { SellRequest SR = new SellRequest(); int price = Math.Max(Convert.ToInt32(rdr["average"]) + Convert.ToInt32(rdr["average"]) * 20 / 100, cominfo[Convert.ToInt32(rdr["commodity"])].info.bid); int amount = Convert.ToInt32(myUser.commodities[Scom] / 20) + 1; int commodity = Convert.ToInt32(rdr["commodity"]); int response = SR.SendSellRequest(price, commodity, amount); if (response != -1) { DateTime date = DateTime.Now; string sdate = date.ToString(); HistoryItem h = new HistoryItem("Sell", response, Convert.ToInt32(myUser.commodities[Scom] / 20) + 1, price, Convert.ToInt32(rdr["commodity"]), true, sdate); // MessageBox.Show("SellDone");//for test App.Current.Dispatcher.Invoke((Action) delegate { mainWin.History.Insert(0, h); }); string path = "..\\History.txt"; using (StreamWriter wr = File.AppendText(path)) { wr.WriteLine("Request"); wr.WriteLine("sell"); wr.WriteLine(response); wr.WriteLine(Convert.ToInt32(myUser.commodities[Scom] / 20) + 1); wr.WriteLine(price); wr.WriteLine(Convert.ToInt32(rdr["commodity"])); wr.WriteLine("true"); wr.WriteLine(sdate.ToString()); } } counterS++; } } rdr.Close(); SqlDataReader rdr2 = sql.sendCommand("SELECT top 100 commodity, AVG(price) as 'average' FROM (SELECT commodity, price, timestamp FROM items where seller = 20) commodity group by commodity order by commodity"); int counterB = 0; while (counterB < 10 && rdr2.Read()) { Scom = "" + rdr2["commodity"]; if (Convert.ToInt32(Scom) > 3 && myUser.funds > 5000) { BuyRequest SB = new BuyRequest(); int price = Math.Min(Convert.ToInt32(rdr2["average"]) - Convert.ToInt32(rdr2["average"]) * 20 / 100, cominfo[Convert.ToInt32(rdr2["commodity"])].info.ask); int response = SB.sendBuyRequest(price, Convert.ToInt32(rdr2["commodity"]), Convert.ToInt32(myUser.commodities[Scom] / 20) + 1); if (response != -1) { DateTime date = DateTime.Now; string sdate = date.ToString(); HistoryItem h = new HistoryItem("Buy", response, Convert.ToInt32(myUser.commodities[Scom] / 20) + 1, price, Convert.ToInt32(rdr2["commodity"]), true, sdate); //MessageBox.Show("BuyDone");//for test App.Current.Dispatcher.Invoke((Action) delegate { mainWin.History.Insert(0, h); }); string path = "..\\History.txt"; using (StreamWriter wr = File.AppendText(path)) { wr.WriteLine("Request"); wr.WriteLine("buy"); wr.WriteLine(response); wr.WriteLine(Convert.ToInt32(myUser.commodities[Scom] / 10) + 1); wr.WriteLine(price); wr.WriteLine(Convert.ToInt32(rdr2["commodity"])); wr.WriteLine("true"); wr.WriteLine(sdate.ToString()); } } } counterB++; } rdr2.Close(); sql.close(); }