public AreaUnit Parse_ReturnsUnitMappedByCustomAbbreviationOrUndefined(string unitAbbreviationToParse) { UnitSystem unitSystem = GetCachedUnitSystem(); unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2"); return(unitSystem.Parse <AreaUnit>(unitAbbreviationToParse)); }
public void GetDefaultAbbreviationFallsBackToUsEnglishCulture() { CultureInfo oldCurrentCulture = CultureInfo.CurrentCulture; CultureInfo oldCurrentUICulture = CultureInfo.CurrentUICulture; try { // CurrentCulture affects number formatting, such as comma or dot as decimal separator. // CurrentUICulture affects localization, in this case the abbreviation. // Zulu (South Africa) var zuluCulture = new CultureInfo("zu-ZA"); UnitSystem zuluUnits = UnitSystem.GetCached(zuluCulture); CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = zuluCulture; UnitSystem usUnits = UnitSystem.GetCached(AmericanCultureName); usUnits.MapUnitToAbbreviation(CustomUnit.Unit1, "US english abbreviation for Unit1"); // Act string abbreviation = zuluUnits.GetDefaultAbbreviation(CustomUnit.Unit1); // Assert Assert.Equal("US english abbreviation for Unit1", abbreviation); } finally { CultureInfo.CurrentCulture = oldCurrentCulture; CultureInfo.CurrentUICulture = oldCurrentUICulture; } }
public void MapUnitToAbbreviation_AddCustomUnit_DoesNotOverrideDefaultAbbreviationForAlreadyMappedUnits() { UnitSystem unitSystem = UnitSystem.GetCached(AmericanCultureName); unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2"); Assert.Equal("m²", unitSystem.GetDefaultAbbreviation(AreaUnit.SquareMeter)); }
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); }
public void MapUnitToAbbreviation_AddCustomUnit_DoesNotOverrideDefaultAbbreviationForAlreadyMappedUnits() { CultureInfo cultureInfo = CultureInfo.GetCultureInfo("en-US"); UnitSystem unitSystem = UnitSystem.GetCached(cultureInfo); unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2"); Assert.AreEqual("m²", unitSystem.GetDefaultAbbreviation(AreaUnit.SquareMeter)); }
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)); }
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); }
public void TryParseLengthSpecialCharacters(string s) { string abbrev = $"m{s}s"; UnitSystem unitSystem = UnitSystem.GetCached(); unitSystem.MapUnitToAbbreviation(LengthUnit.Meter, abbrev); // Act bool ok = Length.TryParse($"10 {abbrev}", out Length result); // Assert Assert.True(ok, $"TryParse \"10 {abbrev}\""); Assert.Equal(10, result.Meters); }
public void TryParseLengthUnitAbbreviationSpecialCharacters(string s) { string abbrev = $"m{s}s"; UnitSystem unitSystem = UnitSystem.GetCached(); unitSystem.MapUnitToAbbreviation(LengthUnit.Meter, abbrev); // Act bool ok = unitSystem.TryParse(abbrev, out LengthUnit result); // Assert Assert.True(ok, "TryParse " + abbrev); Assert.Equal(LengthUnit.Meter, result); }
public void GetDefaultAbbreviationFallsBackToUsEnglishCulture() { // CurrentCulture affects number formatting, such as comma or dot as decimal separator. // CurrentUICulture affects localization, in this case the abbreviation. // Zulu (South Africa) UnitSystem zuluUnits = UnitSystem.GetCached(CultureInfo.GetCultureInfo("zu-ZA")); Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = zuluUnits.Culture; UnitSystem usUnits = UnitSystem.GetCached(CultureInfo.GetCultureInfo("en-US")); usUnits.MapUnitToAbbreviation(CustomUnit.Unit1, "US english abbreviation for Unit1"); // Act string abbreviation = zuluUnits.GetDefaultAbbreviation(CustomUnit.Unit1); // Assert Assert.AreEqual("US english abbreviation for Unit1", abbreviation); }