Ejemplo n.º 1
0
        public AreaUnit Parse_ReturnsUnitMappedByCustomAbbreviationOrUndefined(string unitAbbreviationToParse)
        {
            UnitSystem unitSystem = GetCachedUnitSystem();

            unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2");
            return(unitSystem.Parse <AreaUnit>(unitAbbreviationToParse));
        }
Ejemplo n.º 2
0
        public void Parse_ReturnsUnitMappedByCustomAbbreviation(string customAbbreviation, AreaUnit expected)
        {
            UnitSystem unitSystem = UnitSystem.Default;

            unitSystem.MapUnitToAbbreviation(expected, customAbbreviation);
            var actual = unitSystem.Parse <AreaUnit>(customAbbreviation);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 3
0
        public AreaUnit Parse_ReturnsUnitMappedByCustomAbbreviationOrUndefined(string unitAbbreviationToParse)
        {
            CultureInfo cultureInfo = CultureInfo.GetCultureInfo("en-US");
            UnitSystem  unitSystem  = UnitSystem.GetCached(cultureInfo);

            unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2");

            return(unitSystem.Parse <AreaUnit>(unitAbbreviationToParse));
        }
Ejemplo n.º 4
0
        public void Parse_ReturnsUnitMappedByCustomAbbreviationOrUndefined(string unitAbbreviationToParse, AreaUnit expected)
        {
            UnitSystem unitSystem = GetCachedUnitSystem();

            unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2");
            var actual = unitSystem.Parse <AreaUnit>(unitAbbreviationToParse);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 5
0
        public void Parse_AmbiguousUnitsThrowsException()
        {
            UnitSystem unitSystem = GetCachedUnitSystem();

            // Act 1
            Assert.Throws <AmbiguousUnitParseException>(() => unitSystem.Parse <VolumeUnit>("tsp"));

            // Act 2
            Assert.Throws <AmbiguousUnitParseException>(() => Volume.Parse("1 tsp"));
        }
Ejemplo n.º 6
0
        public void Parse_AmbiguousUnitsThrowsException()
        {
            UnitSystem unitSystem = UnitSystem.Default;

            // Act 1
            var exception1 = Assert.Throws <AmbiguousUnitParseException>(() => unitSystem.Parse <VolumeUnit>("tsp"));

            // Act 2
            var exception2 = Assert.Throws <AmbiguousUnitParseException>(() => Volume.Parse("1 tsp"));

            // Assert
            Assert.Equal("Cannot parse \"tsp\" since it could be either of these: MetricTeaspoon, Teaspoon", exception1.Message);
            Assert.Equal("Cannot parse \"tsp\" since it could be either of these: MetricTeaspoon, Teaspoon", exception2.Message);
        }
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(UnitSystem.Parse <TUnit>((string)value, culture));
 }