public void ConversionForUnitsOfCustomQuantity(double fromValue, HowMuchUnit fromUnit, HowMuchUnit toUnit, double expectedValue)
        {
            // Intentionally don't map conversion Some->Some, it is not necessary
            var unitConverter = new UnitConverter();

            unitConverter.SetConversionFunction <HowMuch>(HowMuchUnit.Some, HowMuchUnit.ATon, x => new HowMuch(x.Value * 2, HowMuchUnit.ATon));
            unitConverter.SetConversionFunction <HowMuch>(HowMuchUnit.Some, HowMuchUnit.AShitTon, x => new HowMuch(x.Value * 10, HowMuchUnit.AShitTon));

            var foundConversionFunction = unitConverter.GetConversionFunction <HowMuch>(fromUnit, toUnit);
            var converted = foundConversionFunction(new HowMuch(fromValue, fromUnit));

            Assert.Equal(expectedValue, converted.Value);
            Assert.Equal(toUnit, converted.Unit);
        }
Exemple #2
0
 public HowMuch(double value, HowMuchUnit unit)
 {
     Unit  = unit;
     Value = value;
 }