Ejemplo n.º 1
0
        public static TMeasurement Parse <TMeasurement>(double value, string type)
            where TMeasurement : IMeasurement
        {
            var runtimeType = typeof(TMeasurement);

            if (runtimeType == typeof(IEnergy))
            {
                return((TMeasurement)EnergyParser.Parse(value, type));
            }

            if (runtimeType == typeof(IPower))
            {
                return((TMeasurement)PowerParser.Parse(value, type));
            }

            if (runtimeType == typeof(IRatio))
            {
                return((TMeasurement)RatioParser.Parse(value, type));
            }

            if (runtimeType == typeof(ITemperature))
            {
                return((TMeasurement)TemperatureParser.Parse(value, type));
            }

            if (runtimeType == typeof(IHumidity))
            {
                return((TMeasurement)HumidityParser.Parse(value, type));
            }

            if (runtimeType == typeof(IIlluminance))
            {
                return((TMeasurement)IlluminanceParser.Parse(value, type));
            }

            if (runtimeType == typeof(IMeasurement))
            {
                return((TMeasurement)(IMeasurement) new ReadOnlyMeasurement(value, type));
            }

            throw new Exception("Could not determine type " + runtimeType.Name);
        }
Ejemplo n.º 2
0
        public void ItParsesTheTypeProperly(string input, Type type)
        {
            var result = IlluminanceParser.Parse(input);

            Assert.That(result.GetType(), Is.EqualTo(type));
        }
Ejemplo n.º 3
0
        public void ItParsesTheValueProperly(string input, double expected)
        {
            var result = IlluminanceParser.Parse(input);

            Assert.That(result.Value, Is.EqualTo(expected));
        }
Ejemplo n.º 4
0
 public void ItThrowsAnExceptionWhenParsingInvalidValues(string input)
 {
     IlluminanceParser.Parse(input);
 }
Ejemplo n.º 5
0
 public void ItDoesNotThrowAnExceptionWhenParsingValidValues(string input)
 {
     IlluminanceParser.Parse(input);
 }