public static void TestSessionHistory() { //Directory.SetCurrentDirectory(@"./GUI/bin/Debug"); Random rnd = new Random(); BuyRequest b1 = new BuyRequest(rnd.Next(1, 10), rnd.Next(1, 100), rnd.Next(30, 200)); HistoryItem item1 = new HistoryItem(DateTime.Now, "BuyRequest", b1, rnd.Next(10000, 99999)); HistoryTable.Add(item1); bool found = false; foreach (HistoryItem item in HistoryTable.getHistoryList()) { if (item.Equals(item1)) { found = true; } } Assert.AreEqual(true, found); Assert.AreEqual(Status.pending, item1._status); HistoryTable.update(); Assert.AreEqual(Status.completed, item1._status); BuyRequest b2 = new BuyRequest(rnd.Next(1, 10), rnd.Next(1, 100), rnd.Next(30, 200)); HistoryItem item2 = new HistoryItem(DateTime.Now, "BuyRequest", b2, rnd.Next(10000, 99999)); bool found2 = false; foreach (HistoryItem item in HistoryTable.getHistoryList()) { if (item.Equals(item2)) { found2 = true; } } Assert.AreEqual(false, found2); HistoryTable.Add(item2); foreach (HistoryItem item in HistoryTable.getHistoryList()) { if (item.Equals(item2)) { found2 = true; } } Assert.AreEqual(true, found2); item2._status = Status.cancelled; bool found3 = false; foreach (HistoryItem item in HistoryTable.getHistoryList()) { if (item._status == Status.cancelled) { found3 = true; } } Assert.AreEqual(true, found3); HistoryTable.update(); Assert.AreEqual(true, item2._status == Status.cancelled); }
// send a buy request using the MarketClient project API public int SendBuyRequest(int price, int commodity, int amount) { string response = "Unknown error"; try { BuyRequest data = new BuyRequest(commodity, amount, price); response = SendRequest(data); int id = Convert.ToInt32(response); if (id >= 1) { HistoryItem newItem = new HistoryItem(DateTime.Now, data.type, data.ToString(), id); HistoryTable.Add(newItem); } return(id); } catch { printError(response); // Print the error return(-1); } }