public void GetCodeTest()
        {
            IQueryable<StatusCodeInfo> SCIL = new StatusCodeInfo[]
            {
               new StatusCodeInfo() {Advice="advice1", CodeIndex=432, GroupDescription="", ID=1, Information="smth happened1" },
               new StatusCodeInfo() {Advice="advice2", CodeIndex=332, GroupDescription="", ID=2, Information="smth happened2" },
               new StatusCodeInfo() {Advice="advice3", CodeIndex=439, GroupDescription="", ID=3, Information="smth happened3" },
            }.AsQueryable();

            test.Setup(m => m.StatusCodeInfoList()).Returns(SCIL);
            StatusCodeInfo expected = SCIL.ElementAt(0);

            manager = new DBManager(test.Object);

            Assert.AreEqual(expected,manager.getCode(432));
        }
        public ActionResult Index()
        {
            ViewData.Clear();
            DBManager DBMn = new DBManager(new EFFacade());

            string company = (User.Identity as ClaimsIdentity).Claims.First(x => x.Type == ClaimTypes.UserData).Value;
            DayReport DR = DBMn.getDayReport(DateTime.Now.Date, company);
            if (DR != null)
            {
                ViewData["Note"] = DR.Message;
                ViewData["Back"] = true;
            }
            string OperatorName = ((ClaimsIdentity)User.Identity).Claims.First(x => x.Type == ClaimTypes.Surname).Value;

            ViewData["Operator"] = OperatorName;
            return View();
        }
 void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
 {
     DBManager DBMn = new DBManager(new EFFacade());
     ClaimsIdentity user = filterContext.Controller.ControllerContext.HttpContext.User.Identity as ClaimsIdentity;
     string role = user.Claims.First(x => x.Type == ClaimTypes.Role).Value;
     string company = user.Claims.First(x => x.Type == ClaimTypes.UserData).Value;
     if (role == "Operator")
     {
         if (DBMn.getDayReport(DateTime.Now.Date, company) == null)
         {
             filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary{
                 { "controller", "Form" },
                 { "action", "Index" }
              });
         }
     }
 }
        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);
        }
        public void GetYearStatsTest()
        {
            IQueryable<MonthData> MD = new MonthData[]
            {
                new MonthData() {Company="Company",ID=1,Month=1,RegisteredPower=20000,TheoryPower=30000,Year=2016 },
                new MonthData() {Company="Company",ID=2,Month=2,RegisteredPower=30000,TheoryPower=40000,Year=2016 },
                new MonthData() {Company="Company",ID=3,Month=3,RegisteredPower=40000,TheoryPower=50000,Year=2016 },
                new MonthData() {Company="Company",ID=4,Month=4,RegisteredPower=50000,TheoryPower=60000,Year=2016 },
                new MonthData() {Company="Company",ID=5,Month=5,RegisteredPower=60000,TheoryPower=70000,Year=2016 },
                new MonthData() {Company="Company",ID=6,Month=6,RegisteredPower=50000,TheoryPower=80000,Year=2015 },
                new MonthData() {Company="awd",ID=7,Month=7,RegisteredPower=40000,TheoryPower=60000,Year=2016 },
                new MonthData() {Company="OtherCompany",ID=8,Month=8,RegisteredPower=30000,TheoryPower=50000,Year=2016 },
                new MonthData() {Company="OtherCompany",ID=9,Month=9,RegisteredPower=20000,TheoryPower=40000,Year=2016 },
                new MonthData() {Company="OtherCompany",ID=10,Month=10,RegisteredPower=10000,TheoryPower=30000,Year=2016 },
            }.AsQueryable();

            test.Setup(m => m.MonthDataList()).Returns(MD);

            List<int> expectedRegistred = MD.Take(5).Select(x => x.RegisteredPower).Cast<int>().ToList();
            List<int> expectedTheory = MD.Take(5).Select(x => x.TheoryPower).Cast<int>().ToList();

            manager = new DBManager(test.Object);

            //List<int> getRegistered = manager.GetYearStats(2016,"Company", "records");
            //List<int> getTheory = manager.GetYearStats(2016, "Company", "theory");

            //Assert.IsTrue(getRegistered.SequenceEqual(expectedRegistred));
            //Assert.IsTrue(getTheory.SequenceEqual(expectedTheory));
        }
 public WorkAreaController()
 {
     DBMn = new DBManager(new EFFacade());
 }