コード例 #1
0
        public void Can_Get_Correct_Data_With_Missing_Periods()
        {
            var timezoneMock = new Mock<TimeZone>();

            timezoneMock.Setup(s => s.StandardName).Returns("Iran Standard Time");

            Plant p = new Plant()
            {
                Id = "PLT1",

                TimeZone = timezoneMock.Object.StandardName,

            };

            var isappMock = new Mock<ISAPProvider>();

            IList<Meter> meterList = new List<Meter>()
            {
                new Meter()
                {
                    IdMeter = "ABAGI01000",
                    LosingRate = 0,
                    Power = 50,
                    IdPlant = p.Id,
                    PowerPercentage = 1
                },
                new Meter()
                {
                    IdMeter = "ABAGI01001",
                    LosingRate = 0,
                    Power = 50,
                    IdPlant = p.Id,
                    PowerPercentage = 1
                }
            };

            isappMock.Setup(s => s.GetMeterListByPlant(p)).Returns(meterList);

            IList<SigmaMeasure> listSigmaMeasure = new List<SigmaMeasure>();

            DateTime date1 = new DateTime(2012, 9, 21);

            for (int i = 0; i < 24; i++)
            {
                SigmaMeasure sm = new SigmaMeasure()
                {
                    Id_Meter = "ABAGI01000",
                    NumPeriod = i + 1,
                    ProductionDate = date1,
                    ProductionValue = 50
                };

                if (sm.NumPeriod != 3)
                {
                    listSigmaMeasure.Add(sm);
                }

                sm = new SigmaMeasure()
                {
                    Id_Meter = "ABAGI01001",
                    NumPeriod = i + 1,
                    ProductionDate = date1,
                    ProductionValue = 40
                };

                if (sm.NumPeriod != 3)
                {
                    listSigmaMeasure.Add(sm);
                }
            }

            Mock<SigmaMeasureService> sigmaMeasureServMock = new Mock<SigmaMeasureService>(null);

            sigmaMeasureServMock.Setup(s => s.GetByMeterListInDateRange(meterList, date1, date1)).Returns(listSigmaMeasure);

            SigmaMeasureFilterStart smfs = new SigmaMeasureFilterStart();

            smfs.ISAPProv = isappMock.Object;

            smfs.SigmaMeasureService = sigmaMeasureServMock.Object;

            var webApiProvMock = new Mock<IWebAPIProvider>();

            webApiProvMock.Setup(s => s.PutJSONMeasureList(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

            smfs.IWepAPIProv = webApiProvMock.Object;

            smfs.Plants = new List<Plant>() { p };

            smfs.SigmaMeasureFilterBeginningDate = date1;

            smfs.SigmaMeasureFilterEndingDate = date1;

            smfs.StartExecution();

            List<SMeasure> correctList = new List<SMeasure>();

            DateTime d2 = new DateTime(2012, 9, 21, 19, 30, 0, DateTimeKind.Utc);
            DateTime notIncludedDate = new DateTime(2012, 9, 20, 22, 30, 0, DateTimeKind.Utc);

            for (DateTime di = new DateTime(2012, 9, 20, 20, 30, 0, DateTimeKind.Utc); di <= d2; di = di.AddHours(1))
            {
                if (di != notIncludedDate)
                    correctList.Add(new SMeasure(p.Id, di, di.Hour, di.Minute, 90,1));
            }

            bool dif = false;

            if (smfs.ListOfSMeasures.Count != correctList.Count)
                dif = true;

            for (int i = 0; i < smfs.ListOfSMeasures.Count && !dif; i++)
            {
                SMeasure sm = smfs.ListOfSMeasures[i];
                if (!correctList.Contains(sm))
                {
                    dif = true;
                }
            }

            Assert.AreEqual(false, dif);
        }
コード例 #2
0
        public void Can_Get_Correct_Data_In_Summer_Daylight_Time_Change_In_Rare_TimeZone()
        {
            var timezoneMock = new Mock<TimeZone>();

            timezoneMock.Setup(s => s.StandardName).Returns("Iran Standard Time");

            Plant p = new Plant()
            {
                Id = "PLT1",

                TimeZone = timezoneMock.Object.StandardName,

            };

            var isappMock = new Mock<ISAPProvider>();

            IList<Meter> meterList = new List<Meter>()
            {
                new Meter()
                {
                    IdMeter = "ABAGI01000",
                    LosingRate = 0,
                    Power = 50,
                    IdPlant = p.Id,
                    PowerPercentage = 1
                },
                new Meter()
                {
                    IdMeter = "ABAGI01001",
                    LosingRate = 0,
                    Power = 50,
                    IdPlant = p.Id,
                    PowerPercentage = 1
                }
            };

            isappMock.Setup(s => s.GetMeterListByPlant(p)).Returns(meterList);

            IList<SigmaMeasure> listSigmaMeasure = new List<SigmaMeasure>();

            DateTime date1 = new DateTime(2012, 9, 21);

            for (int i = 0; i < 24; i++)
            {
                SigmaMeasure sm = new SigmaMeasure()
                {
                    Id_Meter = "ABAGI01000",
                    NumPeriod = i + 1,
                    ProductionDate = date1,
                    ProductionValue = 50
                };

                listSigmaMeasure.Add(sm);

                sm = new SigmaMeasure()
                {
                    Id_Meter = "ABAGI01001",
                    NumPeriod = i + 1,
                    ProductionDate = date1,
                    ProductionValue = 40
                };

                listSigmaMeasure.Add(sm);
            }

            Mock<SigmaMeasureService> sigmaMeasureServMock = new Mock<SigmaMeasureService>(null);

            sigmaMeasureServMock.Setup(s => s.GetByMeterListInDateRange(meterList, date1, date1)).Returns(listSigmaMeasure);

            SigmaMeasureFilterStart smfs = new SigmaMeasureFilterStart();

            smfs.ISAPProv = isappMock.Object;

            smfs.SigmaMeasureService = sigmaMeasureServMock.Object;

            var webApiProvMock = new Mock<IWebAPIProvider>();

            webApiProvMock.Setup(s => s.PutJSONMeasureList(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

            smfs.IWepAPIProv = webApiProvMock.Object;

            smfs.Plants = new List<Plant>() { p };

            smfs.SigmaMeasureFilterBeginningDate = date1;

            smfs.SigmaMeasureFilterEndingDate = date1;

            smfs.StartExecution();

            List<SMeasure> correctList = new List<SMeasure>();

            for (int i = 20; i < 24; i++)
            {
                correctList.Add(new SMeasure(p.Id, date1.AddDays(-1), i, 30, 90,1));
            }

            for (int i = 0; i < 20; i++)
            {
                correctList.Add(new SMeasure(p.Id, date1, i, 30, 90,1));
            }

            bool dif = false;

            if (smfs.ListOfSMeasures.Count != correctList.Count)
                dif = true;

            for (int i = 0; i < smfs.ListOfSMeasures.Count && !dif; i++)
            {
                SMeasure sm = smfs.ListOfSMeasures[i];
                if (!correctList.Contains(sm))
                {
                    dif = true;
                }
            }

            Assert.AreEqual(false, dif);
        }