Exemplo n.º 1
0
 /// <summary>
 /// Method , that will return statistic data for this day 
 /// </summary>
 /// <param name="year">Year of the needed date</param>
 /// <param name="month">Month of the needed date</param>
 /// <param name="day">Day of the needed date</param>
 /// <param name="company">Company (station) that need to recognize </param>
 public DayStats getDayStats(int year, int month, int day, string company)
 {
     try
     {
         string code = (from codes in workFacade.CompanyCodeList()
                       where codes.Company == company
                       select codes.Code).ToList().First();
         var data = from solardata in workFacade.DayDataList()
                    where solardata.Date.Value.Year == year
                    where solardata.Date.Value.Month == month
                    where solardata.Date.Value.Day == day
                    where solardata.Company == code
                    select solardata;
         List<string> InvertersCount = (from workingIP in workFacade.WorkingIPList()
                                        where workingIP.Company == company
                                        select workingIP.InvertersID).ToList();
         int range = 0;
         foreach (var item in InvertersCount)
         {
             range += item.Split(';').Count()-1;
         }
         DayStats DS = new DayStats(data.ToList(), range);
         return DS;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
        public void GetDayStatsTest()
        {
            DayData[] testArray = new DayData[] {
                new DayData {
                    ID = 1,
                    Date = new DateTime(2000,01,01,12,00,00),
                    Company = "Test",
                    AirTemperature = 10,
                    Insolation = 20,
                    PanelTemperature = 25,
                    SumPowerDay = 2000,
                    SumPowerMoment = 100,
                    WindSpeed = 3,
                    PowerMoment = "50;50;"
                },
                new DayData {
                    ID = 2,
                    Date = new DateTime(2000,01,01,12,05,00),
                    Company = "Test",
                    AirTemperature = 15,
                    Insolation = 25,
                    PanelTemperature = 30,
                    SumPowerDay = 3000,
                    SumPowerMoment = 200,
                    WindSpeed = 4,
                    PowerMoment = "100;100;"
                },
                new DayData {
                    ID = 3,
                    Date = new DateTime(2000,01,01,12,05,00),
                    Company = "NoTest",
                    AirTemperature = 10,
                    Insolation = 20,
                    PanelTemperature = 25,
                    SumPowerDay = 2000,
                    SumPowerMoment = 100,
                    WindSpeed = 3,
                    PowerMoment = "50;50;"
                },
                new DayData {
                    ID = 4,
                    Date = new DateTime(2000,01,01,12,05,00),
                    Company = "NoTest",
                    AirTemperature = 15,
                    Insolation = 25,
                    PanelTemperature = 30,
                    SumPowerDay = 3000,
                    SumPowerMoment = 200,
                    WindSpeed = 4,
                    PowerMoment = "100;100;"
                },
                new DayData {
                    ID = 5,
                    Date = new DateTime(2000,01,02,12,00,00),
                    Company = "NoTest",
                    AirTemperature = 10,
                    Insolation = 20,
                    PanelTemperature = 25,
                    SumPowerDay = 2000,
                    SumPowerMoment = 100,
                    WindSpeed = 3 },
            };

            test.Setup(m => m.DayDataList()).Returns(testArray.AsQueryable());

            DayStats ddExpected = new DayStats(testArray.ToList(), 20);
            DayStats ddTest = new DayStats(testArray.Take(2).ToList(), 2);

            manager = new DBManager(test.Object);

            ddExpected = manager.getDayStats(2000, 01, 01, "Test");

            Assert.AreEqual(ddExpected, ddTest);
        }