示例#1
0
        public async void PostSensorLogBatch()
        {
            //Given
            var createSensor    = this.CreateSensor();
            var sensorDto       = this.DbContext.GetSensorDto(createSensor.Id);
            var log_at_15_20_00 = "1574608800;1;2;3";
            var log_end_line    = "|";
            var log_at_15_20_15 = "1574608815;2;3;4";
            var log_at_15_20_30 = "1574608830;2;3;4";
            var sensorLogBatch  = new SensorLogBatchDto()
            {
                SensorId       = sensorDto.Id,
                SecretApiToken = sensorDto.SecretApiToken,
                Content        = $"{log_at_15_20_00}{log_end_line}{log_at_15_20_15}{log_end_line}{log_at_15_20_30}"
            };

            //When
            var result = await this._controllerAllowAnonymous.PostSensorLogBatch(sensorLogBatch);

            var resultValue     = Assert.IsType <ObjectResult>(((ObjectResult)result));
            var sensorLogBatchs = this.DbContext.GetSensorLogBatchPending(sensorDto.Id);

            //Then
            Assert.Equal(201, resultValue.StatusCode);
            Assert.NotEmpty(sensorLogBatchs);
            Assert.Equal(sensorLogBatch.Content, sensorLogBatchs[0].Content);
        }
示例#2
0
        public async void GetSensorLogsToCsv()
        {
            //Given
            var createSensor    = this.CreateSensor();
            var sensorDto       = this.DbContext.GetSensorDto(createSensor.Id);
            var log_at_15_20_00 = "1574608800;1;2;3";
            var log_end_line    = "|";
            var log_at_15_20_15 = "1574608815;2;3;4";
            var log_at_15_20_30 = "1574608830;2;3;4";
            var sensorLogBatch  = new SensorLogBatchDto()
            {
                SensorId       = sensorDto.Id,
                SecretApiToken = sensorDto.SecretApiToken,
                Content        = $"{log_at_15_20_00}{log_end_line}{log_at_15_20_15}{log_end_line}{log_at_15_20_30}"
            };

            //When
            await this._controllerAllowAnonymous.PostSensorLogBatch(sensorLogBatch);

            var sensor = await this.DbContext.GetSensorAsync(sensorDto.Id);

            this.DbContext.PerformContentSensorLogBatch(sensor);
            var result = await this._controllerAllowAnonymous.GetSensorLogsToCsv(sensorDto.Id, 2019, 11, sensorDto.SecretApiToken);

            //Then
            var resultValue = Assert.IsType <FileContentResult>(result);

            Assert.NotEmpty(resultValue.FileContents);
            var rows = Encoding.UTF8.GetString(resultValue.FileContents).Split(Environment.NewLine);

            Assert.Equal("Day,Hour,PeriodOfDay,DayOfWeek,UnixTime,Duration,Watts1,Watts2,Watts3,WattsTotal", rows[0]);
            Assert.Equal("24,15,Noon,Sunday,1574608800,14,26.378,52.756,79.134,158.268", rows[1]);
            Assert.Equal("24,15,Noon,Sunday,1574608815,15,52.756,79.134,105.512,237.40201", rows[2]);
            Assert.Equal("24,15,Noon,Sunday,1574608830,15,52.756,79.134,105.512,237.40201", rows[3]);
        }
示例#3
0
        public async Task <IActionResult> PostSensorLogBatch(SensorLogBatchDto sensorLogBatch)
        {
            var sensor = await this._dbContext.GetSensorAsync(sensorLogBatch.SensorId);

            if (sensor == null)
            {
                return(NotFound());
            }
            var secretApiTokenValid = sensor.SecretApiToken.ToString();

            if (sensorLogBatch.SecretApiToken.Equals(secretApiTokenValid))
            {
                await this._dbContext.CreateSensorLogBatch(sensor, sensorLogBatch.Content);

                return(new ObjectResult(null)
                {
                    StatusCode = 201
                });
            }
            return(NotFound());
        }
示例#4
0
        public async void PostSensorLogBatchNotFoundSecretApiToken()
        {
            //Given
            var createSensor                  = this.CreateSensor();
            var sensorDto                     = this.DbContext.GetSensorDto(createSensor.Id);
            var log_at_15_20_00               = "1574608800;1;2;3";
            var SecretApiTokenInvalid         = "bd6cb0ca-24a1-4064-97f8-b95f3cfeb1cf";
            var logBatchSecretApiTokenInvalid = new SensorLogBatchDto()
            {
                SensorId       = sensorDto.Id,
                SecretApiToken = SecretApiTokenInvalid,
                Content        = $"{log_at_15_20_00}"
            };
            //When
            var result = await this._controllerAllowAnonymous.PostSensorLogBatch
                         (
                logBatchSecretApiTokenInvalid
                         );

            //Then
            Assert.IsType <NotFoundResult>(result);
        }