public void TradingTest(int[] prices, int best) { StockTrading tradingClass = new StockTrading(); int bestPrice = tradingClass.FindBestTrade(prices); Assert.AreEqual(bestPrice, best); }
static void Main(string[] args) { StockTrading stonks = new StockTrading(); Console.WriteLine("FreeMoney:" + stonks.User.FreeMoney); Console.WriteLine(); stonks.BuyStock("AMZN", 1000); stonks.BuyStock("FB", 5000); stonks.BuyStock("AMZN", 500); Console.WriteLine("FreeMoney:" + stonks.User.FreeMoney); foreach (var entry in stonks.User.Entries) { Console.WriteLine(entry.Stock.Symbol + ": " + entry.GetActualValue()); } Console.WriteLine(); stonks.SellStock(stonks.User.Entries.First().Id); Console.WriteLine("FreeMoney:" + stonks.User.FreeMoney); foreach (var entry in stonks.User.Entries) { Console.WriteLine(entry.Stock.Symbol + ": " + entry.GetActualValue()); } Console.WriteLine(); Console.ReadKey(); }
private void buttonSubmit_Click(object sender, EventArgs e) { StockDbContext stockDbContext = new StockDbContext(); Shareholder shareholder = listShareholder.Find(s => s.Name == comboBoxName.SelectedItem.ToString()); Symbol stockInfo = listSymbol.Find(s => s.NamePersian == comboBoxStockInfo.SelectedItem.ToString()); TradeType tradeType = radioButtonBuy.Checked ? TradeType.Buy : TradeType.Sell; int volume = int.Parse(textBoxVolume.Text); double pricePerShare = double.Parse(textBoxPricePerShare.Text); double totalPrice = double.Parse(textBoxTotalPrice.Text); DateTime date = dateTimePicker1.Value.Date; StockTrading newStockTrading = new StockTrading(); newStockTrading.ShareholderId = shareholder.Id; newStockTrading.SymbolId = stockInfo.Id; newStockTrading.TradeType = tradeType; newStockTrading.Volume = volume; newStockTrading.PricePerShare = pricePerShare; newStockTrading.TotalPrice = totalPrice; newStockTrading.Date = date; try { stockDbContext.StockTradings.Add(newStockTrading); stockDbContext.SaveChanges(); labelMessage.Text = "OK" + DateTime.Now.ToLongTimeString(); } catch (Exception ex) { labelMessage.Text = ex.Message; } }