예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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));
            }
        }
예제 #4
0
        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);
            }
        }