Beispiel #1
0
        /// <summary>
        /// Parses the raw text input and generates the reference values model
        /// </summary>
        /// <param name="line">The raw reference values input</param>
        /// <exception cref="ArgumentException">thermometerInputValue is null or whitespace</exception>
        /// <exception cref="ArgumentException">humidityInputValue is null or whitespace</exception>
        /// <exception cref="ArgumentException">monoxideInputValue is null or whitespace</exception>
        /// <exception cref="ArgumentException">thermometerInputValue cannot be parsed to a decimal</exception>
        /// <exception cref="ArgumentException">humidityInputValue cannot be parsed to a decimal</exception>
        /// <exception cref="ArgumentException">monoxideInputValue cannot be parsed to an integer</exception>
        /// <returns>Reference values model</returns>
        private ReferenceValuesModel HandleReferenceValuesLogRecord(string thermometerInputValue, string humidityInputValue, string monoxideInputValue)
        {
            if (string.IsNullOrWhiteSpace(thermometerInputValue))
            {
                _logger.LogError($"{Messages.NullWhitespaceString} (Parameter '{nameof(thermometerInputValue)}')");
                throw new ArgumentException(Messages.NullWhitespaceString, nameof(thermometerInputValue));
            }

            if (string.IsNullOrWhiteSpace(humidityInputValue))
            {
                _logger.LogError($"{Messages.NullWhitespaceString} (Parameter '{nameof(humidityInputValue)}')");
                throw new ArgumentException(Messages.NullWhitespaceString, nameof(humidityInputValue));
            }

            if (string.IsNullOrWhiteSpace(monoxideInputValue))
            {
                _logger.LogError($"{Messages.NullWhitespaceString} (Parameter '{nameof(monoxideInputValue)}')");
                throw new ArgumentException(Messages.NullWhitespaceString, nameof(monoxideInputValue));
            }

            if (!decimal.TryParse(thermometerInputValue, out decimal thermometerValue))
            {
                _logger.LogError($"{Messages.InvalidDecimalValue} (Parameter '{nameof(thermometerInputValue)}')");
                throw new ArgumentException(Messages.InvalidDecimalValue, nameof(thermometerInputValue));
            }

            if (!decimal.TryParse(humidityInputValue, out decimal humidityValue))
            {
                _logger.LogError($"{Messages.InvalidDecimalValue} (Parameter '{nameof(humidityInputValue)}')");
                throw new ArgumentException(Messages.InvalidDecimalValue, nameof(humidityInputValue));
            }

            if (!int.TryParse(monoxideInputValue, out int monoxideValue))
            {
                _logger.LogError($"{Messages.InvalidIntegerValue} (Parameter '{nameof(monoxideInputValue)}')");
                throw new ArgumentException(Messages.InvalidIntegerValue, nameof(monoxideInputValue));
            }

            ReferenceValuesModel model = new ReferenceValuesModel
            {
                ThermometerReferenceValue = thermometerValue,
                HumidityReferenceValue    = humidityValue,
                MonoxideReferenceValue    = monoxideValue
            };

            return(model);
        }
        public void HandleReferenceValuesLogRecordTest(string thermometerInputValue, string humidityInputValue, string monoxideInputValue, ReferenceValuesModel expected)
        {
            // Arrange
            MethodInfo methodInfo = _methodInfos
                                    .Where(x => x.Name.Equals("HandleReferenceValuesLogRecord") && x.IsPrivate)
                                    .First();

            // Act
            ReferenceValuesModel actual = (ReferenceValuesModel)methodInfo.Invoke(_logFile, new object[] { thermometerInputValue, humidityInputValue, monoxideInputValue });

            // Assert
            actual
            .Should()
            .NotBeNull()
            .And
            .Equals(expected);
        }
Beispiel #3
0
        public ParseInputLogFile()
        {
            ReferenceValuesModel referenceValuesModel = new ReferenceValuesModel
            {
                ThermometerReferenceValue = 70.0m,
                HumidityReferenceValue    = 45.0m,
                MonoxideReferenceValue    = 6
            };

            ThermometerModel thermometerModel = new ThermometerModel
            {
                Name     = "temp-1",
                Readings = new List <DecimalReadingModel> {
                    new DecimalReadingModel {
                        Timestamp = DateTime.Parse("2007-04-05T22:00"), Value = 72.4m
                    }
                }
            };

            HumidityModel humidityModel = new HumidityModel
            {
                Name     = "hum-1",
                Readings = new List <DecimalReadingModel> {
                    new DecimalReadingModel {
                        Timestamp = DateTime.Parse("2007-04-05T22:04"), Value = 45.2m
                    }
                }
            };

            MonoxideModel monoxideModel = new MonoxideModel
            {
                Name     = "mon-1",
                Readings = new List <IntegerReadingModel> {
                    new IntegerReadingModel {
                        Timestamp = DateTime.Parse("2007-04-05T22:04"), Value = 5
                    }
                }
            };

            sensorLogModel.ReferenceValues = referenceValuesModel;
            sensorLogModel.ThermometerReadings.Add(thermometerModel);
            sensorLogModel.HumidityReadings.Add(humidityModel);
            sensorLogModel.MonoxideReadings.Add(monoxideModel);
        }