public async void DoesNotAddIfAccountDoesNotExist() { var readings = new List <MeterReading>(); var accounts = new List <Account> { new Account { AccountId = 2 } }; var context = new Mock <SqlDbContext>( new DbContextOptions <SqlDbContext>() ); var queryableAccounts = accounts.AsQueryable().BuildMockDbSet(); context.Setup(m => m.Accounts) .Returns(queryableAccounts.Object); context.Setup(m => m.MeterReadings) .Returns(readings.AsQueryable().BuildMockDbSet().Object); var repo = new MeterReadingRepository(context.Object); var result = await repo.TryStoreReading(new MeterReading { AccountId = 1, MeterReadValue = 1, MeterReadingDateTime = new DateTime(2019, 1, 1) }); Assert.False(result); }
public async void ReturnsTrueIfAdded() { var readings = new List <MeterReading>(); var accounts = new List <Account>(); var context = new Mock <SqlDbContext>( new DbContextOptions <SqlDbContext>() ); var queryableAccounts = accounts.AsQueryable().BuildMockDbSet(); queryableAccounts.Setup(q => q.FindAsync(1)).ReturnsAsync( new Account { AccountId = 1 } ); context.Setup(m => m.Accounts) .Returns(queryableAccounts.Object); context.Setup(m => m.MeterReadings) .Returns(readings.AsQueryable().BuildMockDbSet().Object); var repo = new MeterReadingRepository(context.Object); var result = await repo.TryStoreReading(new MeterReading { AccountId = 1, MeterReadValue = 1, MeterReadingDateTime = new DateTime(2019, 1, 1) }); Assert.True(result); }
public async Task Get_MeterReading_By_Id() { // Arrange var meterReadingRepository = new MeterReadingRepository(DatabaseConnection); // Act var result = await meterReadingRepository.GetMeterReadingAsync(1); // Assert Assert.IsNotNull(meterReadingRepository); Assert.IsNotNull(result); }
public async Task Get_All_MeterReadings() { // Arrange var meterReadingRepository = new MeterReadingRepository(DatabaseConnection); // Act var results = await meterReadingRepository.GetAllMeterReadingsAsync(); // Assert Assert.IsNotNull(meterReadingRepository); Assert.IsNotNull(results); }
public void GetMeterReadings_Should_Return_ListOfMeterReadings() { // arrange var path = "TestData/MeterData.csv"; MeterReadingRepository meterReadingsRepository = new MeterReadingRepository(); // act var result = meterReadingsRepository.GetMeterReadings(path); // assert var meterReadings = result as IList <MeterReading> ?? result.ToList(); Assert.Equal(366, meterReadings.Count()); Assert.Equal((decimal)215.75, meterReadings[0].CumulativeConsumption); Assert.Equal(new DateTime(2016, 1, 1), meterReadings[0].Date); }
public void GetMeterReadingsForDates_Should_Return_ListOfMeterReadingsBetweenDates(string startDateString, decimal startExpectedValue, string endDateString, decimal endExpectedValue) { // arrange var path = "TestData/MeterData.csv"; MeterReadingRepository meterReadingsRepository = new MeterReadingRepository(); var startDate = DateTime.ParseExact(startDateString, "yyyy/M/d", System.Globalization.CultureInfo.InvariantCulture); var endDate = DateTime.ParseExact(endDateString, "yyyy/M/d", System.Globalization.CultureInfo.InvariantCulture); ; // act var result = meterReadingsRepository.GetMeterReadingsForDates(path, startDate, endDate); // assert var meterReadings = result as IList <MeterReading> ?? result.ToList(); Assert.Equal((endDate - startDate).TotalDays, meterReadings.Count - 1); Assert.Equal(startExpectedValue, meterReadings[0].CumulativeConsumption); Assert.Equal(endExpectedValue, meterReadings[meterReadings.Count - 1].CumulativeConsumption); }
public async Task Create_New_MeterReading() { // Arrange var meterReadingRepository = new MeterReadingRepository(DatabaseConnection); var meterReading = new MeterReading() { MeterReadValue = "3124", MeterReadingDateTime = new DateTime(2020, 06, 19, 5, 20, 45), AccountId = 1 }; // Act var result = await meterReadingRepository.CreateMeterReadingAsync(meterReading); // Assert Assert.IsNotNull(meterReadingRepository); Assert.IsNotNull(meterReading); Assert.IsTrue(result); }