private async void LoadTrades_Click(object sender, RoutedEventArgs e) { Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync("sample.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting); var trademodels = await TradeProcessor.LoadTrades(); using (StreamWriter streamW = new StreamWriter(sampleFile.Path, true)) { streamW.WriteLine($"{DateTime.Now} Wczytano 300 tradow"); } Price.Text = $"Cena: {trademodels[0].R}"; Amoundof.Text = $"Ilosc: {trademodels[0].A}"; Time.Text = $"Czas: {trademodels[0].T}"; Type.Text = $"Typ: {trademodels[0].Ty}"; Id.Text = $"Id: {trademodels[0].Id}"; using (StreamWriter streamW = new StreamWriter(sampleFile.Path, true)) { streamW.WriteLine($"{DateTime.Now} Wyświetlono ostatni trade"); } var trades = new List <Trade>(); foreach (var trade in trademodels) { trades.Add(trade.ToTrade()); } TraderContext context = null; try { context = new TraderContext(); foreach (var trade in trades) { if (!context.Trades.Any(t => t.Tid == trade.Tid)) { context.Trades.Add(trade); using (StreamWriter streamW = new StreamWriter(sampleFile.Path, true)) { streamW.WriteLine($"{DateTime.Now} Dodano do bazy trade {trade}"); } } } context.SaveChanges(); } finally { if (context != null) { context.Dispose(); } } }
public async Task TestMethod1() { ApiHelper.InitializeClient(); List <int> numbers = new List <int> { 1, 26, 70, 5 }; List <Type> expected = new List <Type> { typeof(TradeModel[]), typeof(TradeModel[]), typeof(TradeModel[]), typeof(TradeModel[]) }; List <Type> actual = new List <Type>(); for (int i = 0; i < 4; i++) { var trades = await TradeProcessor.LoadTrades(numbers[i]); actual.Add(trades.GetType()); } CollectionAssert.AreEqual(expected, actual); }