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 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 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(); } }