コード例 #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));
        }
コード例 #2
0
        public async Task Analytics_Add()
        {
            // Arrange
            var panel = new OneHourElectricityInsert
            {
                KiloWatt = 195,
                PanelId  = "Panel10009"
            };
            var controller = new AnalyticsController(_analyticsRepositoryMock.Object, _panelRepositoryMock.Object);
            var result     = await controller.Post(panel);

            // Assert
            Assert.NotNull(result);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.Equal(201, createdResult.StatusCode);
        }