Example #1
0
 /// <summary>
 /// Converts the String input to the correct string value.
 /// </summary>
 /// <typeparam name="TInput"> The temperature type to be converted to. </typeparam>
 /// <param name="input"> The value to be converted. </param>
 /// <exception cref="ArgumentException"> The TInput type is not a valid type for this method. </exception>
 /// <returns>
 /// The result of the conversion.
 /// </returns>
 public static string To <TInput>(this StringBase input)
     where TInput : TemperatureBase
 {
     return(typeof(TInput).Name switch
     {
         nameof(Celsius) when input is CelsiusString castInput => StringParser(castInput.Temperature, CelsiusConverter.CelsiusToCelsius),
         nameof(Celsius) when input is FahrenheitString castInput => StringParser(castInput.Temperature, FahrenheitConverter.FahrenheitToCelsius),
         nameof(Celsius) when input is KelvinString castInput => StringParser(castInput.Temperature, KelvinConverter.KelvinToCelsius),
         nameof(Celsius) when input is GasString castInput => StringParser(castInput.Temperature, GasConverter.GasToCelsius),
         nameof(Celsius) when input is RankineString castInput => StringParser(castInput.Temperature, RankineConverter.RankineToCelsius),
         nameof(Fahrenheit) when input is CelsiusString castInput => StringParser(castInput.Temperature, CelsiusConverter.CelsiusToFahrenheit),
         nameof(Fahrenheit) when input is FahrenheitString castInput => StringParser(castInput.Temperature, FahrenheitConverter.FahrenheitToFahrenheit),
         nameof(Fahrenheit) when input is KelvinString castInput => StringParser(castInput.Temperature, KelvinConverter.KelvinToFahrenheit),
         nameof(Fahrenheit) when input is GasString castInput => StringParser(castInput.Temperature, GasConverter.GasToFahrenheit),
         nameof(Fahrenheit) when input is RankineString castInput => StringParser(castInput.Temperature, RankineConverter.RankineToFahrenheit),
         nameof(Kelvin) when input is CelsiusString castInput => StringParser(castInput.Temperature, CelsiusConverter.CelsiusToKelvin),
         nameof(Kelvin) when input is FahrenheitString castInput => StringParser(castInput.Temperature, FahrenheitConverter.FahrenheitToKelvin),
         nameof(Kelvin) when input is KelvinString castInput => StringParser(castInput.Temperature, KelvinConverter.KelvinToKelvin),
         nameof(Kelvin) when input is GasString castInput => StringParser(castInput.Temperature, GasConverter.GasToKelvin),
         nameof(Kelvin) when input is RankineString castInput => StringParser(castInput.Temperature, RankineConverter.RankineToKelvin),
         nameof(Gas) when input is CelsiusString castInput => StringParser(castInput.Temperature, CelsiusConverter.CelsiusToGas),
         nameof(Gas) when input is FahrenheitString castInput => StringParser(castInput.Temperature, FahrenheitConverter.FahrenheitToGas),
         nameof(Gas) when input is KelvinString castInput => StringParser(castInput.Temperature, KelvinConverter.KelvinToGas),
         nameof(Gas) when input is GasString castInput => StringParser(castInput.Temperature, GasConverter.GasToGas),
         nameof(Gas) when input is RankineString castInput => StringParser(castInput.Temperature, RankineConverter.RankineToGas),
         nameof(Rankine) when input is CelsiusString castInput => StringParser(castInput.Temperature, CelsiusConverter.CelsiusToRankine),
         nameof(Rankine) when input is FahrenheitString castInput => StringParser(castInput.Temperature, FahrenheitConverter.FahrenheitToRankine),
         nameof(Rankine) when input is KelvinString castInput => StringParser(castInput.Temperature, KelvinConverter.KelvinToRankine),
         nameof(Rankine) when input is GasString castInput => StringParser(castInput.Temperature, GasConverter.GasToRankine),
         nameof(Rankine) when input is RankineString castInput => StringParser(castInput.Temperature, RankineConverter.RankineToRankine),
         _ => throw new ArgumentException($"Invalid type: {typeof(TInput).Name}")
     });
        public void Test_to_gas_generic_from_gas_returns_same_value()
        {
            // Arrange.
            var input = new GasString("7");

            // Act.
            var result = input.To <Gas>();

            // Assert.
            result.Should().Be(input.Temperature);
        }
        public void Test_to_rankine_generic_from_gas_returns_correct_value()
        {
            // Arrange.
            const string expected = "851.6699999999998";
            var          input    = new GasString("6");

            // Act.
            var result = input.To <Rankine>();

            // Assert.
            result.Should().Be(expected);
        }
        public void Test_to_celsius_generic_from_gas_returns_correct_value()
        {
            // Arrange.
            const string expected = "220";
            var          input    = new GasString("7");

            // Act.
            var result = input.To <Celsius>();

            // Assert.
            result.Should().Be(expected);
        }
        public void Test_to_kelvin_generic_from_gas_returns_correct_value()
        {
            // Arrange.
            const string expected = "473.15";
            var          input    = new GasString("6");

            // Act.
            var result = input.To <Kelvin>();

            // Assert.
            result.Should().Be(expected);
        }
        public void Test_to_fahrenheit_generic_from_gas_returns_correct_value()
        {
            // Arrange.
            const string expected = "428";
            var          input    = new GasString("7");

            // Act.
            var result = input.To <Fahrenheit>();

            // Assert.
            result.Should().Be(expected);
        }
Example #7
0
 /// <summary>
 /// Converts the GasConverter <paramref name="input"/> to Celsius
 /// </summary>
 /// <param name="input"> The value to be converted. </param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">Temp too low or too high for gas mark!</exception>
 /// <returns>
 /// The Celsius string result.
 /// </returns>
 public static string ToCelsius(this GasString input)
 {
     return(StringParser(input.Temperature, GasConverter.GasToCelsius));
 }
Example #8
0
 /// <summary>
 /// Converts the GasConverter <paramref name="input"/> to RankineConverter
 /// </summary>
 /// <param name="input"> The value to be converted. </param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">Temp too low or too high for gas mark!</exception>
 /// <returns>
 /// The RankineConverter string result.
 /// </returns>
 public static string ToRankine(this GasString input)
 {
     return(StringParser(input.Temperature, GasConverter.GasToRankine));
 }
Example #9
0
 /// <summary>
 /// Converts the GasConverter <paramref name="input"/> to KelvinConverter
 /// </summary>
 /// <param name="input"> The value to be converted. </param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">Temp too low or too high for gas mark!</exception>
 /// <returns>
 /// The KelvinConverter string result.
 /// </returns>
 public static string ToKelvin(this GasString input)
 {
     return(StringParser(input.Temperature, GasConverter.GasToKelvin));
 }
Example #10
0
 /// <summary>
 /// Converts the GasConverter <paramref name="input"/> to FahrenheitConverter
 /// </summary>
 /// <param name="input"> The value to be converted. </param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">Temp too low or too high for gas mark!</exception>
 /// <returns>
 /// The FahrenheitConverter string result.
 /// </returns>
 public static string ToFahrenheit(this GasString input)
 {
     return(StringParser(input.Temperature, GasConverter.GasToFahrenheit));
 }