public void PowerConsumptionCachedDataGoodConstructorParameters() { var pccd = new PowerConsumptionCachedData(new CacheManager <PowerConsumptionData>(), new UnitOfWork(new DatabaseContext())); Assert.IsNotNull(pccd); }
public void PowerConsumptionCachedDataSameDateTwiceTestCache() { var inputDate = new InputDate() { From = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour - 1, DateTime.Now.Minute, DateTime.Now.Second), To = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour + 1, DateTime.Now.Minute, DateTime.Now.Second), }; var mockUnitOfWork = new Mock <UnitOfWork>(); mockUnitOfWork.Setup(m => m.PowerConsumptionDataRepository.Find(It.IsAny <Expression <Func <PowerConsumptionData, bool> > >())).Returns(() => data.Where(x => x.Timestamp >= inputDate.From && x.Timestamp <= inputDate.To).ToList()); var pccd = new PowerConsumptionCachedData(new CacheManager <PowerConsumptionData>(), mockUnitOfWork.Object); var result = pccd.Get(inputDate); foreach (PowerConsumptionData d in result) { Assert.GreaterOrEqual(d.Timestamp, inputDate.From); Assert.LessOrEqual(d.Timestamp, inputDate.To); } var cachedResult = pccd.Get(inputDate); Assert.AreEqual(cachedResult, result); }
public void PowerConsumptionCacheDataDateOutOfBounds() { var inputDate = new InputDate() { From = new DateTime(DateTime.Now.Year + 1, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), To = new DateTime(DateTime.Now.Year + 1, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second) }; var mockUnitOfWork = new Mock <UnitOfWork>(); mockUnitOfWork.Setup(m => m.PowerConsumptionDataRepository.Find(It.IsAny <Expression <Func <PowerConsumptionData, bool> > >())).Returns(() => new List <PowerConsumptionData>()); var pccd = new PowerConsumptionCachedData(new CacheManager <PowerConsumptionData>(), mockUnitOfWork.Object); var result = pccd.Get(inputDate); Assert.IsEmpty(result); }
public void PowerConsumptionCachedDataNoDateEnteredGetAll() { var inputDate = new InputDate() { From = DateTime.MinValue, To = DateTime.MinValue }; var mockUnitOfWork = new Mock <UnitOfWork>(); mockUnitOfWork.Setup(x => x.PowerConsumptionDataRepository.GetAll()).Returns(data); var pccd = new PowerConsumptionCachedData(new CacheManager <PowerConsumptionData>(), mockUnitOfWork.Object); var result = pccd.Get(inputDate); //CollectionAssert.AreEqual(data, result); foreach (PowerConsumptionData d in result) { Assert.AreEqual(d, data.FirstOrDefault(x => x.Id == d.Id)); } }
public void PowerConsumptionCachedDataNoFromDateEnteredFind() { var inputDate = new InputDate() { From = new DateTime(1, 1, 1, 0, 0, 0, 0), To = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second + 1) }; var mockUnitOfWork = new Mock <UnitOfWork>(); mockUnitOfWork.Setup(m => m.PowerConsumptionDataRepository.Find(It.IsAny <Expression <Func <PowerConsumptionData, bool> > >())).Returns(() => data.Where(x => x.Timestamp <= inputDate.To).ToList()); var pccd = new PowerConsumptionCachedData(new CacheManager <PowerConsumptionData>(), mockUnitOfWork.Object); var result = pccd.Get(inputDate); foreach (PowerConsumptionData d in result) { Assert.LessOrEqual(d.Timestamp, inputDate.To); } }
public void PowerConsumptionCachedDataNullConstructorParameters() { var pccd = new PowerConsumptionCachedData(null as ICacheManager <PowerConsumptionData>, null as IUnitOfWork); Assert.IsNotNull(pccd); }