Beispiel #1
0
        public async Task <IActionResult> Get([FromRoute] string panelId)

        {
            var panel = await _panelRepository.Query()
                        .FirstOrDefaultAsync(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase));

            if (panel == null)
            {
                return(NotFound());
            }

            int panelTemp = panel.Id;
            var analytics = await _analyticsRepository.Query()
                            .Where(x => x.PanelId.Equals(panelTemp)).ToListAsync();

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                })
            };

            return(Ok(result));
        }
Beispiel #2
0
        public void TestModels()
        {
            OneHourElectricityModel oneHourElectricityModel = new OneHourElectricityModel();

            oneHourElectricityModel.DateTime = DateTime.Now;
            oneHourElectricityModel.Id       = 1;
            oneHourElectricityModel.KiloWatt = 234;

            OneHourElectricityListModel oneHourElectricityListModel = new OneHourElectricityListModel();

            oneHourElectricityListModel.OneHourElectricitys.Add(oneHourElectricityModel);

            Assert.NotNull(oneHourElectricityListModel.OneHourElectricitys);
            Assert.NotNull(oneHourElectricityModel);



            OneDayElectricityModel oneDayElectricityModel = new OneDayElectricityModel();

            oneDayElectricityModel.Average  = 23;
            oneDayElectricityModel.DateTime = DateTime.UtcNow;
            oneDayElectricityModel.Maximum  = 344;
            oneDayElectricityModel.Minimum  = 24255;
            oneDayElectricityModel.Sum      = 234446;

            Assert.NotNull(oneDayElectricityModel);
        }
Beispiel #3
0
        public async Task <IActionResult> Get([FromRoute] int panelId)
        {
            var panel = await _panelRepository.FindAsync(x =>
                                                         x.Id.Equals(panelId));

            if (panel == null)
            {
                return(NotFound());
            }

            var analytics = await _analyticsRepository
                            .FindAllAsync(x => x.PanelId.Equals(panelId));

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                })
            };

            return(Ok(result));
        }
Beispiel #4
0
        public async Task <IActionResult> Get([FromRoute] string panelId)
        {
            if (string.IsNullOrWhiteSpace(panelId))
            {
                return(BadRequest());
            }
            if (panelId.Trim().Length != 16)
            {
                return(BadRequest("Panel ID should have 16 characters"));
            }
            var panel = await _panelRepository.Query()
                        .FirstOrDefaultAsync(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase));

            if (panel == null)
            {
                return(NotFound());
            }

            var analytics = await _analyticsRepository.Query()
                            .Where(x => x.PanelId.Equals(panelId, StringComparison.CurrentCultureIgnoreCase)).ToListAsync();

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                })
            };

            return(Ok(result));
        }
Beispiel #5
0
        public void OneHourElectricityListModelTest()
        {
            OneHourElectricityListModel listModel = new OneHourElectricityListModel();
            OneHourElectricityModel     oneHourElectricityModel = new OneHourElectricityModel()
            {
                Id = 1, KiloWatt = 23, DateTime = DateTime.Today
            };

            listModel.OneHourElectricitys = new List <OneHourElectricityModel>()
            {
                oneHourElectricityModel
            };

            var result = listModel.OneHourElectricitys;
            IEnumerable <OneHourElectricityModel> expected = new List <OneHourElectricityModel>()
            {
                (new OneHourElectricityModel()
                {
                    Id = 1, KiloWatt = 23, DateTime = DateTime.Today
                })
            };

            Assert.All(expected, x =>
            {
                foreach (var hourElectricityModel in result)
                {
                    Assert.Equal(1, hourElectricityModel.Id);
                    Assert.Equal(23, hourElectricityModel.KiloWatt);
                    Assert.Equal(DateTime.Today, hourElectricityModel.DateTime);
                }
            });

            Assert.Collection <OneHourElectricityModel>(result,
                                                        elem1 => Assert.Equal(1, elem1.Id));
        }
        public async Task <IActionResult> Get([FromRoute] string panelId, DateTime hour)
        {
            try
            {
                var analytics = await _analyticsRepository.Query().Where(x => x.PanelId == panelId && x.DateTime.Date.Equals(hour.Date) && x.DateTime.TimeOfDay.Hours.Equals(hour.TimeOfDay.Hours)).ToListAsyncSafe();

                if (!analytics.Any() || analytics == null)
                {
                    return(NotFound());
                }

                var result = new OneHourElectricityListModel
                {
                    OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                    {
                        Id       = c.Id,
                        KiloWatt = c.KiloWatt,
                        DateTime = c.DateTime
                    })
                };

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> Get([FromRoute] string panelId)
        {
            var panelIdint = Convert.ToInt32(panelId);
            var panel      = await _panelRepository.Query().FirstOrDefaultAsync(x => x.Id == panelIdint);

            //var panel = await _panelRepository.GetAsync(panelId);
            if (panel == null)
            {
                return(NotFound());
            }

            var analytics = await _analyticsRepository.Query()
                            .Where(x => x.PanelId == panelIdint).ToListAsync();

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                })
            };

            return(Ok(result));
        }
        public void Eval_TypeModelOneHourElectricity()
        {
            List <OneHourElectricityModel> _pruebas1 = new List <OneHourElectricityModel>();

            _pruebas1.Add(new OneHourElectricityModel {
                Id       = 0,
                KiloWatt = 2000,
                DateTime = DateTime.Now
            });

            var _pruebas = new OneHourElectricityListModel
            {
                OneHourElectricitys = _pruebas1
            };

            Assert.NotNull(_pruebas);
        }
        public async Task <IActionResult> Get(string panelId)
        {
            var analytics = await _analyticsRepository.Query()
                            .Where(x => x.PanelId.Equals(panelId, StringComparison.CurrentCultureIgnoreCase)).ToListAsync();

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                }).ToList()
            };

            return(Ok(result));
        }
Beispiel #10
0
        public async Task <IActionResult> Get([FromRoute] string serial)
        {
            var analytics = _analyticsRepository.Query()
                            .Where(x => x.PanelId.Equals(serial)).ToList();

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                })
            };

            return(Ok(result));
        }
        public async Task <IActionResult> Get([FromRoute] int panelId)
        {
            //easier to use int instead of string
            //var panel = await _panelRepository.Query()
            //    .FirstOrDefaultAsync(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase));
            var analytics = _analyticsRepository.GetPanel(panelId);

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                })
            };

            return(Ok(result));
        }
Beispiel #12
0
        public async Task <IActionResult> Get([FromRoute] int panelId)
        {
            if (!_panelRepository.Exist(panelId))
            {
                return(NotFound());
            }

            var analytics = await _analyticsRepository.GetByPanelId(panelId);

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                })
            };

            return(Ok(result));
        }
Beispiel #13
0
        public async Task <IActionResult> Get([FromRoute] string panelId)
        {
            var panel = await _panelRepository.GetPanelBySerial(panelId);

            if (panel == null)
            {
                return(NotFound());
            }

            var analytics = await _analyticsRepository.ReturnOneHourElectricity(panelId);

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                })
            };

            return(Ok(result));
        }
Beispiel #14
0
        public async Task <IActionResult> Get([FromRoute] string panelId)
        {
            var panel = await _panelRepository.GetAsync(panelId); //Changed the Query() to GetAsync()

            if (panel == null)
            {
                return(NotFound());
            }

            var analytics = _analyticsRepository.Query().Where(x => x.PanelId.Equals(panelId, StringComparison.CurrentCultureIgnoreCase)).AsEnumerable();

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                }).ToList()
            };

            return(Ok(result));
        }
        public async Task Get_ShouldGetOneHourElectricityList(string panelId)
        {
            // Arrange
            OneHourElectricityListModel oneHourElectricityListModel = new OneHourElectricityListModel();

            List <OneHourElectricityModel> oneHourElectricityModels = new List <OneHourElectricityModel>();

            OneHourElectricityModel oneHourElectricityModel1 = new OneHourElectricityModel
            {
                Id       = 1,
                KiloWatt = 6,
                DateTime = new DateTime()
            };
            OneHourElectricityModel oneHourElectricityModel2 = new OneHourElectricityModel
            {
                Id       = 2,
                KiloWatt = 10,
                DateTime = new DateTime()
            };

            oneHourElectricityModels.Add(oneHourElectricityModel1);
            oneHourElectricityModels.Add(oneHourElectricityModel2);

            oneHourElectricityListModel.OneHourElectricitys = oneHourElectricityModels.AsEnumerable();

            try
            {
                if (panelId == "1")
                {
                    // Act
                    var result = await _analyticsController.Get(panelId);

                    // Assert
                    Assert.NotNull(result);

                    var okResult = result as OkObjectResult;
                    Assert.NotNull(okResult);
                    Assert.Equal(200, okResult.StatusCode);

                    var valueResult = okResult.Value as OneHourElectricityListModel;
                    Assert.Equal(oneHourElectricityListModel.ToString(), valueResult.ToString());
                }
                else if (panelId == "1")
                {
                    // Act
                    var result = await _analyticsController.Get(panelId);

                    // Assert
                    Assert.NotNull(result);

                    var notFoundResult = result as NotFoundResult;
                    Assert.NotNull(notFoundResult);
                    Assert.Equal(404, notFoundResult.StatusCode);
                }
            }
            catch (Exception exc)
            {
                // exc.Message is "The provider for the source IQueryable doesn't implement IAsyncQueryProvider. Only providers that implement IEntityQueryProvider can be used for Entity Framework asynchronous operations."
                // This error is only present in unitTest, this error is not taken in the Crossolar endpoint.


                // Coverage HttpStatusCodeException
                int dummyStatusCode = 400;

                var tryCoverage_HttpStatusCodeException1 = new HttpStatusCodeException(dummyStatusCode);
                var tryCoverage_HttpStatusCodeException2 = new HttpStatusCodeException(dummyStatusCode, "The provider for the source IQueryable doesn't implement IAsyncQueryProvider. Only providers that implement IEntityQueryProvider can be used for Entity Framework asynchronous operations.");
                var tryCoverage_HttpStatusCodeException3 = new HttpStatusCodeException(dummyStatusCode, exc);
                var tryCoverage_HttpStatusCodeException4 = new HttpStatusCodeException(dummyStatusCode, new JObject());

                Assert.NotNull(tryCoverage_HttpStatusCodeException1);
                Assert.NotNull(tryCoverage_HttpStatusCodeException2);
                Assert.NotNull(tryCoverage_HttpStatusCodeException3);
                Assert.NotNull(tryCoverage_HttpStatusCodeException4);

                Assert.NotEqual(exc.Message, tryCoverage_HttpStatusCodeException1.Message);
                Assert.Equal(exc.Message, tryCoverage_HttpStatusCodeException2.Message);
                Assert.NotEqual(exc.Message, tryCoverage_HttpStatusCodeException3.Message);
                Assert.Contains(exc.Message, tryCoverage_HttpStatusCodeException3.Message);
                Assert.NotEqual(exc.Message, tryCoverage_HttpStatusCodeException4.Message);
            }
        }