Пример #1
0
        public async Task <IActionResult> Post([FromBody] OneHourElectricityInsert value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var oneHourElectricityContent = new OneHourElectricity
            {
                KiloWatt = value.KiloWatt,
                DateTime = DateTime.UtcNow,
                PanelId  = value.PanelId
            };

            await _analyticsRepository.InsertAsync(oneHourElectricityContent);

            var result = new OneHourElectricityModel
            {
                Id       = oneHourElectricityContent.Id,
                KiloWatt = oneHourElectricityContent.KiloWatt,
                DateTime = oneHourElectricityContent.DateTime,
                PanelId  = oneHourElectricityContent.PanelId
            };

            return(Created($"panel/{result.PanelId}/analytics/{result.Id}", result));
        }
        public Task UpdateAsync(OneHourElectricity entity)
        {
            int i = _data.FindIndex(delegate(OneHourElectricity check) { return(check.Id == entity.Id); });

            _data[i] = entity;
            return(null);
        }
Пример #3
0
        public async Task DayResults_ReturnsOK()
        {
            // Arrange
            var panel = new Panel
            {
                Id        = 1,
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };

            OneHourElectricity oneHourElectricity = new OneHourElectricity()
            {
                Id       = 1,
                DateTime = DateTime.Now.AddDays(-1),
                KiloWatt = 200,
                PanelId  = "AAAA1111BBBB2222"
            };

            _analyticsRepository.Setup(x => x.Query()).Returns(new OneHourElectricity[1] {
                oneHourElectricity
            }.AsQueryable());

            // Act
            var result = await _analyticsController.DayResults(panel.Serial);

            // Assert
            Assert.NotNull(result);

            var okResult = result as OkObjectResult;

            Assert.NotNull(okResult.Value);
            Assert.Equal(200, okResult.StatusCode);
        }
Пример #4
0
        public async Task Get_ShouldReturnOkObject()
        {
            var panel = new Panel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB-002"
            };

            var oneHourElectricity = new OneHourElectricity
            {
                PanelId  = "AAAA1111BBBB-002",
                KiloWatt = 1000,
                DateTime = DateTime.UtcNow
            };

            context.Panels.Add(panel);
            context.SaveChanges();

            context.OneHourElectricitys.Add(oneHourElectricity);
            context.SaveChanges();

            // Act
            var result = await _analyticsController.Get("AAAA1111BBBB-002");

            // Assert
            Assert.NotNull(result);

            var statusResult = result as OkObjectResult;

            Assert.NotNull(statusResult);
            Assert.Equal(200, statusResult.StatusCode);
        }
Пример #5
0
        public async Task <IActionResult> Post([FromRoute] int panelId, [FromBody] OneHourElectricityModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_panelRepository.Exist(panelId))
            {
                return(NotFound());
            }


            var oneHourElectricityContent = new OneHourElectricity
            {
                PanelId  = panelId,
                KiloWatt = value.KiloWatt,
                DateTime = value.DateTime
            };

            await _analyticsRepository.InsertAsync(oneHourElectricityContent);

            var result = new OneHourElectricityModel
            {
                Id       = oneHourElectricityContent.Id,
                KiloWatt = oneHourElectricityContent.KiloWatt,
                DateTime = oneHourElectricityContent.DateTime
            };

            return(Created($"panel/{panelId}/analytics/{result.Id}", result));
        }
Пример #6
0
        public async Task <IActionResult> Post([FromRoute] string panelId, [FromBody] OneHourElectricityModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            var oneHourElectricityContent = new OneHourElectricity
            {
                PanelId  = panelId,
                KiloWatt = value.KiloWatt,
                DateTime = DateTime.UtcNow
            };

            await _analyticsRepository.InsertAsync(oneHourElectricityContent);

            var result = new OneHourElectricityModel
            {
                Id       = oneHourElectricityContent.Id,
                KiloWatt = oneHourElectricityContent.KiloWatt,
                DateTime = oneHourElectricityContent.DateTime
            };

            return(Created($"panel/{panelId}/analytics/{result.Id}", result));
        }
Пример #7
0
        public async Task <IActionResult> Post(string panelId, OneHourElectricityModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var oneHourElectricityContent = new OneHourElectricity
            {
                PanelId  = panelId,
                KiloWatt = value.KiloWatt,
                DateTime = DateTime.UtcNow
            };

            await _analyticsRepository.InsertAsync(oneHourElectricityContent);

            //var result = new OneHourElectricityModel
            //{
            //    Id = oneHourElectricityContent.Id,
            //    KiloWatt = oneHourElectricityContent.KiloWatt,
            //    DateTime = oneHourElectricityContent.DateTime
            //};

            return(Created($"panel/{panelId}/analytics/{oneHourElectricityContent.Id}", oneHourElectricityContent));
        }
        public async Task Get_ShouldReturnOneHourElectricity()
        {
            // Arrange
            var panel = new Panel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };

            var OneHourElectricity = new OneHourElectricity
            {
                Id       = 123,
                KiloWatt = 12345678,
                DateTime = DateTime.Now,
                PanelId  = "AAAA1111BBBB2222"
            };

            AnalyticsController mockController = MockPanelAndAnalyticsImplementation(panel, OneHourElectricity);

            // Act
            var result = await mockController.Get("AAAA1111BBBB2222");

            // Assert
            Assert.NotNull(result);
        }
Пример #9
0
        public async Task UpdateAsync()
        {
            var oneHourElectricity = new OneHourElectricity
            {
                DateTime = DateTime.UtcNow,
                KiloWatt = 12312,
                PanelId  = 1
            };

            var insertResponse = await _repository.InsertAsync(oneHourElectricity);

            Assert.NotEqual(default(int), oneHourElectricity.Id);

            var result = await _repository.GetAsync(oneHourElectricity.Id);

            result.KiloWatt = 23;
            result.PanelId  = 2;

            await _repository.UpdateAsync(result);

            var updateResult = await _repository.GetAsync(result.Id);

            Assert.True(result.KiloWatt == 23);

            Assert.True(result.PanelId == 2);
        }
Пример #10
0
        public async Task <IActionResult> Post([FromRoute] string panelId, [FromBody] OneHourElectricityModel value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var oneHourElectricityContent = new OneHourElectricity
                {
                    PanelId  = panelId,
                    KiloWatt = value.KiloWatt,
                    DateTime = DateTime.UtcNow
                };

                await _analyticsRepository.InsertAsync(oneHourElectricityContent);

                var result = new OneHourElectricityModel
                {
                    Id       = oneHourElectricityContent.Id,
                    KiloWatt = oneHourElectricityContent.KiloWatt,
                    DateTime = oneHourElectricityContent.DateTime
                };

                return(Created($"panel/{panelId}/analytics/{result.Id}", result));
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #11
0
        public CrossSolarInMemoryDbContextProvider()
        {
            var options = new DbContextOptionsBuilder <CrossSolarDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            _context = new CrossSolarDbContext(options);

            Random rnd = new Random(DateTime.Now.Millisecond);

            List <OneHourElectricity> list = new List <OneHourElectricity>();

            for (int i = 0; i < 10; i++)
            {
                Panel p = CreateRandom(rnd);

                list = new List <OneHourElectricity>();

                for (int e = 0; e < rnd.Next(10); e++)
                {
                    OneHourElectricity el = CreateRandomOneHourElectricity(p.Id);
                    list.Add(el);
                }

                p.OneHourElectricitys = list;

                _context.Panels.Add(p);
            }

            _context.SaveChanges();
        }
Пример #12
0
        public async Task <IActionResult> Post([FromRoute, StringLength(16), Required] string panelId, [FromBody] OneHourElectricityModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // BUG FIX - Check Exists Panel
            if (!_panelRepository.Query().Any(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase)))
            {
                return(BadRequest());
            }

            var oneHourElectricityContent = new OneHourElectricity
            {
                PanelId  = panelId,
                KiloWatt = value.KiloWatt,
                DateTime = DateTime.UtcNow
            };

            await _analyticsRepository.InsertAsync(oneHourElectricityContent);

            var result = new OneHourElectricityModel
            {
                Id       = oneHourElectricityContent.Id,
                KiloWatt = oneHourElectricityContent.KiloWatt,
                DateTime = oneHourElectricityContent.DateTime
            };

            return(Created($"panel/{panelId}/analytics/{result.Id}", result));
        }
 private void FullCompare(OneHourElectricity expected, OneHourElectricity current)
 {
     Assert.NotNull(current);
     Assert.Equal(expected.DateTime, current.DateTime);
     Assert.Equal(expected.KiloWatt, current.KiloWatt);
     Assert.Equal(expected.PanelId, current.PanelId);
 }
Пример #14
0
        public async Task <IActionResult> Post([FromRoute] int panelId, [FromBody] OneHourElectricityModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_panelRepository.Query().Where(p => p.Id == panelId).SingleOrDefault() == null)
            {
                return(new UnauthorizedResult());
            }
            var oneHourElectricityContent = new OneHourElectricity
            {
                PanelId  = panelId,
                KiloWatt = value.KiloWatt,
                DateTime = value.DateTime
            };

            await _analyticsRepository.InsertAsync(oneHourElectricityContent);

            var result = new OneHourElectricityModel
            {
                Id       = oneHourElectricityContent.Id,
                KiloWatt = oneHourElectricityContent.KiloWatt,
                DateTime = oneHourElectricityContent.DateTime
            };

            return(Created($"panel/{panelId}/analytics/{result.Id}", result));
        }
        public async Task GetPanelsByPanelId_ShouldGetPanelist()
        {
            // Arrange
            var id = 1;
            await _analyticsRepository.GetAsync(id);

            var temp = new OneHourElectricity()
            {
                KiloWatt = 1,
                PanelId  = "AAAA1111BBBB2222",
                DateTime = DateTime.Now
            };
            await _analyticsRepository.InsertAsync(temp);

            // Act
            _analyticsRepository.GetOneDayMetrics(temp.PanelId);
            var panel = new Panel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };
            await _panelRepository.InsertAsync(panel);

            // Act
            var result = _panelRepository.GetPanelsByPanelId(panel.Serial);

            // Assert
            Assert.NotNull(result);
        }
        public Task UpdateAsync(OneHourElectricity entity)
        {
            var entityToUpdate = _analiticsData.First(x => x.Id == entity.Id);

            entityToUpdate = entity;

            return(Task.CompletedTask);
        }
Пример #17
0
        public void DailyAnalyticsCheck()
        {
            List <OneDayElectricityModel> listMust = new List <OneDayElectricityModel>();
            List <OneHourElectricity>     list     = new List <OneHourElectricity>();
            OneDayElectricityModel        lcOneDayElectricityModel;
            OneHourElectricity            lcOneHourElectricity = new OneHourElectricity();

            lcOneHourElectricity.Id       = 1;
            lcOneHourElectricity.KiloWatt = 100;
            lcOneHourElectricity.PanelId  = 2;
            lcOneHourElectricity.DateTime = new System.DateTime(2018, 8, 24);
            list.Add(lcOneHourElectricity);

            lcOneHourElectricity          = new OneHourElectricity();
            lcOneHourElectricity.Id       = 2;
            lcOneHourElectricity.KiloWatt = 200;
            lcOneHourElectricity.PanelId  = 2;
            lcOneHourElectricity.DateTime = new System.DateTime(2018, 8, 24);
            list.Add(lcOneHourElectricity);

            lcOneHourElectricity          = new OneHourElectricity();
            lcOneHourElectricity.Id       = 3;
            lcOneHourElectricity.KiloWatt = 200;
            lcOneHourElectricity.PanelId  = 2;
            lcOneHourElectricity.DateTime = new System.DateTime(2018, 8, 23);
            list.Add(lcOneHourElectricity);

            lcOneDayElectricityModel          = new OneDayElectricityModel();
            lcOneDayElectricityModel.DateTime = new System.DateTime(2018, 8, 24);
            lcOneDayElectricityModel.Sum      = 300;
            lcOneDayElectricityModel.Average  = 150;
            lcOneDayElectricityModel.Minimum  = 100;
            lcOneDayElectricityModel.Maximum  = 200;
            listMust.Add(lcOneDayElectricityModel);


            lcOneDayElectricityModel          = new OneDayElectricityModel();
            lcOneDayElectricityModel.DateTime = new System.DateTime(2018, 8, 23);
            lcOneDayElectricityModel.Sum      = 200;
            lcOneDayElectricityModel.Average  = 200;
            lcOneDayElectricityModel.Minimum  = 200;
            lcOneDayElectricityModel.Maximum  = 200;
            listMust.Add(lcOneDayElectricityModel);

            var result = _analyticsController.Calculate(list);

            // Assert
            for (int i = 0; i < result.Count; i++)
            {
                Assert.Equal(result[i].Average, listMust[i].Average);
                Assert.Equal(result[i].Maximum, listMust[i].Maximum);
                Assert.Equal(result[i].Minimum, listMust[i].Minimum);
                Assert.Equal(result[i].Sum, listMust[i].Sum);
                Assert.Equal(result[i].DateTime, listMust[i].DateTime);
            }
        }
Пример #18
0
        public async Task InsertAsync()
        {
            var oneHourElectricity = new OneHourElectricity
            {
                DateTime = DateTime.UtcNow,
                KiloWatt = 12312,
                PanelId  = 1
            };

            var insertResponse = await _repository.InsertAsync(oneHourElectricity);

            Assert.NotEqual(default(int), oneHourElectricity.Id);
        }
Пример #19
0
        public void TestAnalyticsRepository()
        {
            IAnalyticsRepository analytics = new AnalyticsRepository(new CrossSolarDbContext());

            OneHourElectricity oneHourElectricity = new OneHourElectricity()
            {
                DateTime = DateTime.Now,
                KiloWatt = 312,
                PanelId  = "12"
            };

            analytics.InsertAsync(oneHourElectricity);

            var result = analytics.GetByPanelIdAsync("12");

            Assert.NotNull(result);
        }
Пример #20
0
        public async Task <IActionResult> Post([FromRoute, StringLength(16), Required] string panelId, [FromBody] OneHourElectricityAmountModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_panelRepository.Query().Any(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase)))
            {
                return(BadRequest());
            }

            double amountKiloWatt = 0;

            switch (value.TypeWatt)
            {
            case UnitTypeWatt.KiloWatt:
                amountKiloWatt = value.Amount;
                break;

            case UnitTypeWatt.Watt:
                amountKiloWatt = value.Amount / 1000;
                break;
            }

            var oneHourElectricityContent = new OneHourElectricity
            {
                PanelId  = panelId,
                KiloWatt = amountKiloWatt,
                DateTime = DateTime.UtcNow
            };

            await _analyticsRepository.InsertAsync(oneHourElectricityContent);

            var result = new OneHourElectricityAmountModel
            {
                Id       = oneHourElectricityContent.Id,
                Amount   = oneHourElectricityContent.KiloWatt,
                TypeWatt = UnitTypeWatt.KiloWatt,
                DateTime = oneHourElectricityContent.DateTime
            };

            return(Created($"panel/v2/{panelId}/analytics/{result.Id}", result));
        }
Пример #21
0
        public async Task Get_ShouldRetrieveAnalytics()
        {
            //Setup Analytics Repository
            var testAnalytic = new OneHourElectricity()
            {
                Id       = 1,
                PanelId  = this.panelId,
                KiloWatt = 454673,
                DateTime = DateTime.Now
            };
            OneHourElectricityModel testAnalyticModel = new OneHourElectricityModel()
            {
                Id       = testAnalytic.Id,
                DateTime = testAnalytic.DateTime,
                KiloWatt = testAnalytic.KiloWatt
            };

            var analytics = new List <OneHourElectricity>()
            {
                testAnalytic
            };
            var anMock = analytics.AsQueryable().BuildMock();

            _analyticsRepositoryMock.Setup(repo => repo.Query())
            .Returns(anMock.Object);

            _anaController = new AnalyticsController(_analyticsRepositoryMock.Object, _panelRepositoryMock.Object);

            //Act
            var result = await _anaController.Get(panelId);

            //Assert
            var contentResult = Assert.IsType <OkObjectResult>(result);
            var model         = Assert.IsType <OneHourElectricityListModel>(contentResult.Value);

            Assert.NotEmpty(model.OneHourElectricitys);
            Assert.Single(model.OneHourElectricitys);
            var m = model.OneHourElectricitys.FirstOrDefault();

            Assert.Equal(testAnalyticModel.Id, m.Id);
            Assert.Equal(testAnalyticModel.KiloWatt, m.KiloWatt);
            Assert.Equal(testAnalyticModel.DateTime, m.DateTime);
        }
        public async Task DayResults_ShouldReturnOneHourElectricityModelList()
        {
            // Arrange
            var panel = new Panel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };
            var OneHourElectricity = new OneHourElectricity
            {
                Id       = 123,
                KiloWatt = 12345678,
                DateTime = DateTime.Now,
                PanelId  = "AAAA1111BBBB2222"
            };

            AnalyticsController mockController = MockPanelAndAnalyticsImplementation(panel, OneHourElectricity);

            var expectedResult    = new List <OneDayElectricityModel>();
            var OneDayElectricity = new OneDayElectricityModel
            {
                Sum      = 123,
                Average  = 12345678,
                Maximum  = 10,
                Minimum  = 10,
                DateTime = DateTime.Now,
            };

            expectedResult.Add(OneDayElectricity);


            // Act
            var result = await _analyticsController.DayResults("AAAA1111BBBB2222");

            // Assert
            var createdResult = result as OkObjectResult;

            Assert.Equal(200, createdResult.StatusCode);
            Assert.NotNull(result);
        }
        public Task <int> InsertAsync(OneHourElectricity entity)
        {
            _data.Add(entity);

            return(Task.Run(delegate(){ return 1; }));
        }
        private static AnalyticsController MockPanelAndAnalyticsImplementation(Panel panel, OneHourElectricity OneHourElectricity)
        {
            var oneHourElectricitys = new List <OneHourElectricity>();

            oneHourElectricitys.Add(OneHourElectricity);
            IQueryable <OneHourElectricity> queryableElectricities = oneHourElectricitys.AsQueryable();

            // Force DbSet to return the IQueryable members of our converted list object as its data source
            var mockSet = new Mock <DbSet <OneHourElectricity> >();

            mockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.Provider).Returns(queryableElectricities.Provider);
            mockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.Expression).Returns(queryableElectricities.Expression);
            mockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.ElementType).Returns(queryableElectricities.ElementType);
            mockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.GetEnumerator()).Returns(queryableElectricities.GetEnumerator());

            var crossSolarDbContext = new CrossSolarDbContext();

            crossSolarDbContext.OneHourElectricitys = mockSet.Object;

            var mockAnalyticsRepository        = new Mock <IAnalyticsRepository>();
            var mockPanelRepository            = new Mock <IPanelRepository>();
            var mockPanelGenericRepository     = new Mock <GenericRepository <Panel> >();
            var mockAnalyticsGenericRepository = new Mock <GenericRepository <OneHourElectricity> >();

            var mockController = new AnalyticsController(mockAnalyticsRepository.Object, mockPanelRepository.Object);

            mockPanelRepository.Setup(x => x.GetAsync("AAAA1111BBBB2222")).Returns(Task.FromResult(panel));
            mockAnalyticsRepository.Setup(x => x.Query()).Returns(queryableElectricities);
            return(mockController);
        }
        public Task <int> InsertAsync(OneHourElectricity entity)
        {
            _analiticsData.Add(entity);

            return(Task.FromResult(1));
        }
Пример #26
0
        public async Task DayResults_ShouldReturnOkObject()
        {
            var panel = new Panel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB-004"
            };

            var oneHourElectricity = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 10,
                DateTime = DateTime.UtcNow.Date.AddDays(-5).AddHours(1).AddMinutes(10)
            };

            var oneHourElectricity2 = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 20,
                DateTime = DateTime.UtcNow.Date.AddDays(-5).AddHours(2).AddMinutes(20)
            };

            var oneHourElectricity3 = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 30,
                DateTime = DateTime.UtcNow.Date.AddDays(-5).AddHours(2).AddMinutes(30)
            };

            var oneHourElectricity4 = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 40,
                DateTime = DateTime.UtcNow.Date.AddHours(3).AddMinutes(40)
            };

            var oneHourElectricity5 = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 50,
                DateTime = DateTime.UtcNow.Date.AddHours(4)
            };


            var oneHourElectricity6 = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 23,
                DateTime = DateTime.UtcNow.Date.AddDays(-4).AddHours(2).AddMinutes(58)
            };

            var oneHourElectricity7 = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 17,
                DateTime = DateTime.UtcNow.Date.AddDays(-4).AddHours(2).AddMinutes(59)
            };

            var oneHourElectricity8 = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 234,
                DateTime = DateTime.UtcNow.Date.AddDays(-4).AddHours(5).AddSeconds(1)
            };

            var oneHourElectricity9 = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 741,
                DateTime = DateTime.UtcNow.Date.AddDays(-4).AddHours(5).AddMinutes(2)
            };

            var oneHourElectricity10 = new OneHourElectricity
            {
                //Id = 1,
                PanelId  = "AAAA1111BBBB-004",
                KiloWatt = 8,
                DateTime = DateTime.UtcNow.Date.AddDays(-4).AddHours(5)
            };


            context.Panels.Add(panel);
            context.SaveChanges();

            context.OneHourElectricitys.Add(oneHourElectricity);
            context.OneHourElectricitys.Add(oneHourElectricity2);
            context.OneHourElectricitys.Add(oneHourElectricity3);
            context.OneHourElectricitys.Add(oneHourElectricity4);
            context.OneHourElectricitys.Add(oneHourElectricity5);
            context.OneHourElectricitys.Add(oneHourElectricity6);
            context.OneHourElectricitys.Add(oneHourElectricity7);
            context.OneHourElectricitys.Add(oneHourElectricity8);
            context.OneHourElectricitys.Add(oneHourElectricity9);
            context.OneHourElectricitys.Add(oneHourElectricity10);
            context.SaveChanges();



            // Act
            var result = await _analyticsController.DayResults("AAAA1111BBBB-004");

            // Assert
            Assert.NotNull(result);

            var statusResult = result as OkObjectResult;

            Assert.NotNull(statusResult);
            Assert.Equal(200, statusResult.StatusCode);
        }
Пример #27
0
        public async Task DayResults_ShouldRetrieveSumMixMaxAvg()
        {
            //Setup Analytics Repository
            var day1 = DateTime.Now;
            var day2 = day1.AddDays(1);

            var e1_100KW_day1_hour1 = new OneHourElectricity()
            {
                Id       = 1,
                KiloWatt = 100,
                DateTime = day1,
                PanelId  = this.panelId,
            };

            var e1_150KW_day1_hour2 = new OneHourElectricity()
            {
                Id       = 2,
                KiloWatt = 150,
                DateTime = day1.AddHours(1),
                PanelId  = this.panelId,
            };

            var e1_200KW_day2_hour1 = new OneHourElectricity()
            {
                Id       = 3,
                KiloWatt = 200,
                DateTime = day2,
                PanelId  = this.panelId,
            };

            var e1_250KW_day2_hour2 = new OneHourElectricity()
            {
                Id       = 4,
                KiloWatt = 250,
                DateTime = day2.AddHours(1),
                PanelId  = this.panelId,
            };

            var analytics = new List <OneHourElectricity>()
            {
                e1_100KW_day1_hour1, e1_150KW_day1_hour2, e1_200KW_day2_hour1, e1_250KW_day2_hour2
            };

            _analyticsRepositoryMock.Setup(repo => repo.Query())
            .Returns(analytics.AsQueryable().BuildMock().Object);

            _anaController = new AnalyticsController(_analyticsRepositoryMock.Object, _panelRepositoryMock.Object);

            //Act
            var result = await _anaController.DayResults(panelId);

            //Asserts
            var okResult    = Assert.IsType <OkObjectResult>(result);
            var resultModel = Assert.IsType <List <OneDayElectricityModel> >(okResult.Value);

            Assert.Equal(2, resultModel.Count);

            var firstDay = resultModel.FirstOrDefault();//Check for the first day values

            Assert.NotNull(firstDay);

            Assert.Equal(day1.Date, firstDay.DateTime.Date);
            Assert.Equal(e1_100KW_day1_hour1.KiloWatt + e1_150KW_day1_hour2.KiloWatt, firstDay.Sum);
            Assert.Equal((e1_100KW_day1_hour1.KiloWatt + e1_150KW_day1_hour2.KiloWatt) / 2, firstDay.Average);
            Assert.Equal(e1_150KW_day1_hour2.KiloWatt, firstDay.Maximum);
            Assert.Equal(e1_100KW_day1_hour1.KiloWatt, firstDay.Minimum);
        }