public void ParseWithUnitProvider() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnits(typeof(Length)); Assert.AreEqual(1.2 * Length.Metre, Length.Parse("1.2 m", unitProvider)); }
public void ParseWithDifferentFormatProvider() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnits(typeof(Length)); Assert.AreEqual(1.2 * Length.Metre, Length.Parse("1,2 m", this.customCulture, unitProvider)); }
public void RegisterUnitsByAssembly_AndParseRegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnits(typeof(Length).Assembly); Assert.AreEqual(5 * Length.Kilometre, Length.Parse("5 km", unitProvider)); }
public void RegisterUnitsByType_ParseUnregisteredUnit_ThrowsException() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnits(typeof(Length)); Assert.Throws <FormatException>(() => Mass.Parse("5 kg", unitProvider)); }
public void ImperialUnits() { var imperialUnitProvider = new UnitProvider(CultureInfo.InvariantCulture); imperialUnitProvider.RegisterUnits(typeof(Imperial)); Assert.AreEqual(Imperial.Gallon, Volume.Parse("1 gal", imperialUnitProvider)); Assert.AreEqual(Imperial.FluidOunce, Volume.Parse("1 floz", imperialUnitProvider)); Assert.AreNotEqual(Imperial.Gallon, Volume.Gallon); }
public void Parse_CustomCulture2() { using (CurrentCulture.TemporaryChangeTo(this.customCulture)) { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnits(typeof(Length)); using (DefaultUnitProvider.TemporaryChangeTo(unitProvider)) { Assert.AreEqual(1.2 * Length.Metre, Length.Parse("1,2 m")); } } }
public void RegisterUnitsByType_ParseUnregisteredUnit_ThrowsException() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnits(typeof(Length)); Assert.Throws<FormatException>(() => Mass.Parse("5 kg", unitProvider)); }