コード例 #1
0
ファイル: UnitSystemTests.cs プロジェクト: mludlum/UnitsNet
        public AreaUnit Parse_ReturnsUnitMappedByCustomAbbreviationOrUndefined(string unitAbbreviationToParse)
        {
            UnitSystem unitSystem = GetCachedUnitSystem();

            unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2");
            return(unitSystem.Parse <AreaUnit>(unitAbbreviationToParse));
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #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"));
        }
コード例 #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);
        }
コード例 #7
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(UnitSystem.Parse <TUnit>((string)value, culture));
 }