public void GetTradingDatesGetsOnlyTradingDatesInOpenRangeOrderedAscending(List <Company> input) { // Arrange var testSettings = new TestProjectSettings(); DbContext testContext = null; StockQuoteRepository tested = null; try { testContext = new StockTestContext(testSettings); tested = new StockQuoteRepository(testContext); testContext.Database.EnsureCreated(); testContext.AddRange(input.SelectMany(x => x.Quotes)); testContext.SaveChanges(); // Act var result = tested.GetTradingDates(new DateTime(2017, 01, 01), new DateTime(2018, 01, 01)); // Assert Assert.Equal(250, result.Count); for (var i = 1; i < result.Count; i++) { Assert.True(result[i] > result[i - 1]); } } finally { testContext?.Database.EnsureDeleted(); tested?.Dispose(); testContext?.Dispose(); } }
public void AddAdds(Company input) { // Arrange var testSettings = new TestProjectSettings(); DbContext testContext = null; StockQuoteRepository tested = null; try { testContext = new StockTestContext(testSettings); tested = new StockQuoteRepository(testContext); testContext.Database.EnsureCreated(); // Act testContext.Add(input.FirstQuote); testContext.SaveChanges(); // Assert Assert.Equal(input.FirstQuote, testContext.Set <StockQuote>().First()); } finally { testContext?.Database.EnsureDeleted(); tested?.Dispose(); testContext?.Dispose(); } }
public void GetAllQuotesFromPreviousSessionGetsOnlyQuotesFromLastSession(List <Company> input) { // Arrange var testSettings = new TestProjectSettings(); DbContext testContext = null; StockQuoteRepository tested = null; try { testContext = new StockTestContext(testSettings); tested = new StockQuoteRepository(testContext); testContext.Database.EnsureCreated(); testContext.AddRange(input.SelectMany(x => x.Quotes)); testContext.SaveChanges(); var date = new DateTime(2017, 01, 01); // Act var result = tested.GetAllQuotesFromPreviousSession(date); // Assert Assert.Equal(3, result.Count); foreach (var quote in result) { Assert.Equal(new DateTime(2016, 12, 30), quote.DateParsed); } } finally { testContext?.Database.EnsureDeleted(); tested?.Dispose(); testContext?.Dispose(); } }
public void GetNTradingDatesGetsOnlyTradingDatesFromLastNSessionsOrderedDescending(List <Company> input) { // Arrange var testSettings = new TestProjectSettings(); DbContext testContext = null; StockQuoteRepository tested = null; try { testContext = new StockTestContext(testSettings); tested = new StockQuoteRepository(testContext); testContext.Database.EnsureCreated(); testContext.AddRange(input.Where(x => x.Ticker == "MBANK").SelectMany(x => x.Quotes)); testContext.SaveChanges(); // Act var result = tested.GetAllQuotesFromPreviousNDays(new DateTime(2017, 01, 01), 10); // Assert Assert.Equal(10, result.Count); for (var i = 1; i < result.Count; i++) { Assert.True(result[i].DateParsed > result[i - 1].DateParsed); } } finally { testContext?.Database.EnsureDeleted(); tested?.Dispose(); testContext?.Dispose(); } }
public async Task GetLatestSessionInDbDateReturnsLastSessionDateInDb(List <Company> input) { // Arrange var testSettings = new TestProjectSettings(); DbContext testContext = null; StockQuoteRepository tested = null; try { testContext = new StockTestContext(testSettings); tested = new StockQuoteRepository(testContext); await testContext.Database.EnsureCreatedAsync(); await testContext.AddRangeAsync(input.SelectMany(x => x.Quotes)); await testContext.SaveChangesAsync(); var date = new DateTime(2018, 02, 09); // Act var result = await tested.GetLatestSessionInDbDateAsync(); // Assert Assert.Equal(date.Date, result.Date); } finally { if (testContext != null) { await testContext.Database.EnsureDeletedAsync(); if (tested != null) { await tested.DisposeAsync(); } await testContext.DisposeAsync(); } } }
public DailyQuoteForm() { InitializeComponent(); quoteRepo = new StockQuoteRepository(); stockRepo = new StockRepository(); }
public ForeignChartForm() { InitializeComponent(); quoteRepo = new StockQuoteRepository(); }
private void DailyForeignNetBuyChartForm_Load(object sender, EventArgs e) { stockRepo = new StockRepository(); quoteRepo = new StockQuoteRepository(); DataHelper.LoadTickerComboBox(stockRepo, TickerComboBox); }
public static void EditQuoteFile(OpenFileDialog fileDialog, DateTime date) { StockQuoteRepository quoteRepo = new StockQuoteRepository(); StockRepository stockRepo = new StockRepository(); stock_quotes quote; bool success = false; bool flag = true; String ErrorMessage; AwaitForm waitForm = new AwaitForm(); string fileName = fileDialog.FileName; Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Workbook xlWorkbook = xlApp.Workbooks.Open(fileName); Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; if (xlRange[2, 2].Value2 != null) { for (int i = 2; i <= rowCount; i++) { string stockCode = xlRange[i, 1].Value2.ToString().ToUpper().Trim(); int stock_id = stockRepo.GetStockId(stockCode); if (stockCode.Length == 4) { bool isExisted = stockRepo.CheckCurrentStock(stockCode); if (!isExisted) { stock stock = new stock(); stock.code = stockCode; quote = new stock_quotes(); quote.stock_id = stockRepo.SaveStock(stock, out ErrorMessage); } quote = quoteRepo.FindStockQuoteByStockIdAndDate(stock_id, date); quote.quote_date = date.Date; quote.open = xlRange.Cells[i, 3].Value2 == 0 ? Decimal.Parse(xlRange.Cells[i, 2].Value2.ToString()) : Decimal.Parse(xlRange.Cells[i, 3].Value2.ToString()); quote.high = Decimal.Parse(xlRange.Cells[i, 4].Value2.ToString()); quote.low = Decimal.Parse(xlRange.Cells[i, 5].Value2.ToString()); quote.close = Decimal.Parse(xlRange.Cells[i, 6].Value2.ToString()); quote.volume = Decimal.Parse(xlRange.Cells[i, 7].Value2.ToString()) / 100; quote.value = Decimal.Parse(xlRange.Cells[i, 8].Value2.ToString()); quote.frequency = Decimal.Parse(xlRange.Cells[i, 9].Value2.ToString()); quote.foreign_sell = Decimal.Parse(xlRange.Cells[i, 10].Value2.ToString()) / 100; quote.foreign_buy = Decimal.Parse(xlRange.Cells[i, 11].Value2.ToString()) / 100; success = quoteRepo.UpdateStockQuote(quote, out ErrorMessage); if (!String.IsNullOrEmpty(ErrorMessage)) { MessageBox.Show(ErrorMessage); } if (flag) { waitForm.Show(); waitForm.Refresh(); } flag = false; } } if (success) { waitForm.Close(); MessageBox.Show("Data berhasil disimpan"); } } else { MessageBox.Show("File tidak memiliki data"); } }
public QuoteChartForm() { InitializeComponent(); quoteRepo = new StockQuoteRepository(); stockRepo = new StockRepository(); }