public void GetUnit_NotUniqueUnit_GetsFirstRegistered() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); Assert.AreEqual(Length.Metre, unitProvider.GetUnit("m")); }
public void GetUnit_NotUniqueUnit_GetsFirstRegistered() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); Assert.AreEqual(Length.Metre, unitProvider.GetUnit("m")); }
public void GetUnits_NotUniqueUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); var units = unitProvider.GetUnits(typeof(Length)); Assert.AreEqual(1, units.Count); Assert.AreEqual(Length.Metre, units["m"]); }
public void TryGetUnit_GenericOutputAndNotUniqueUnit_GetsFirstRegistered() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); IQuantity unit; Assert.IsTrue(unitProvider.TryGetUnit(typeof(Length), "m", out unit)); Assert.AreEqual(Length.Metre, unit); }
public void CustomFootUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Foot, "'"); Assert.That(Length.Parse("3'", unitProvider).ConvertTo(Length.Foot), Is.EqualTo(3)); }
public void RegisterUnit_ParseRegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); Assert.AreEqual(5 * Length.Metre, Length.Parse("5 m", unitProvider)); }
public void TrySetDisplayUnit_NotRegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); Assert.IsFalse(unitProvider.TrySetDisplayUnit <Length>("km")); }
public void RegisterUnit_ParseUnregisteredUnit_ThrowsException() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); Assert.Throws <FormatException>(() => Length.Parse("5 cm", unitProvider)); }
public void GetDisplayUnit_UnregisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); unitProvider.TrySetDisplayUnit <TypographicLength>("m"); Assert.Throws <InvalidOperationException>(() => unitProvider.GetDisplayUnit(typeof(Length))); string symbol; Assert.Throws <InvalidOperationException>(() => unitProvider.GetDisplayUnit(typeof(Length), out symbol)); }
public void GetDisplayUnit_RegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.TrySetDisplayUnit <Length>("m"); Assert.AreEqual("m", unitProvider.GetDisplayUnit(typeof(Length))); string symbol; Assert.AreEqual(Length.Metre, unitProvider.GetDisplayUnit(typeof(Length), out symbol)); }
public void TryGetDisplayUnit_UnregisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); unitProvider.TrySetDisplayUnit <TypographicLength>("m"); Length unit; string symbol; Assert.IsFalse(unitProvider.TryGetDisplayUnit(out unit, out symbol)); }
public void NumberGroup() { var culture = new CultureInfo("en-US"); culture.NumberFormat.NumberDecimalSeparator = "."; culture.NumberFormat.NumberGroupSeparator = ","; var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "metre"); Assert.That(Length.Parse("300,000.00 metre", unitProvider).ConvertTo(Length.Metre), Is.EqualTo(300000)); }
public void TryGetDisplayUnit_RegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.TrySetDisplayUnit <Length>("m"); Length unit; string symbol; Assert.IsTrue(unitProvider.TryGetDisplayUnit(out unit, out symbol)); Assert.AreEqual(Length.Metre, unit); Assert.AreEqual("m", symbol); }
public void SetDisplayUnit() { var unitProvider = new UnitProvider(typeof(UnitProvider).Assembly, CultureInfo.InvariantCulture); var unitSymbol = unitProvider.GetDisplayUnit(typeof(Length)); // Change the display unit unitProvider.RegisterUnit(627.48 * Length.Millimetre, "alen"); unitProvider.TrySetDisplayUnit <Length>("alen"); Assert.AreEqual("1 alen", (0.62748 * Length.Metre).ToString(null, unitProvider)); // Revert Assert.IsTrue(unitProvider.TrySetDisplayUnit <Length>(unitSymbol)); Assert.AreEqual("1 m", Length.Metre.ToString(null, unitProvider)); }
public void SetDisplayUnit() { var unitProvider = new UnitProvider(typeof(UnitProvider).Assembly, CultureInfo.InvariantCulture); var unitSymbol = unitProvider.GetDisplayUnit(typeof(Length)); // Change the display unit unitProvider.RegisterUnit(627.48 * Length.Millimetre, "alen"); unitProvider.TrySetDisplayUnit<Length>("alen"); Assert.AreEqual("1 alen", (0.62748 * Length.Metre).ToString(null, unitProvider)); // Revert Assert.IsTrue(unitProvider.TrySetDisplayUnit<Length>(unitSymbol)); Assert.AreEqual("1 m", Length.Metre.ToString(null, unitProvider)); }
public void TrySetDisplayUnit_NotRegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); Assert.IsFalse(unitProvider.TrySetDisplayUnit<Length>("km")); }
public void RegisterUnit_ParseUnregisteredUnit_ThrowsException() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); Assert.Throws<FormatException>(() => Length.Parse("5 cm", unitProvider)); }
public void NumberGroup() { var culture = new CultureInfo(1); culture.NumberFormat.NumberDecimalSeparator = "."; culture.NumberFormat.NumberGroupSeparator = ","; var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "metre"); Assert.That(Length.Parse("300,000.00 metre", unitProvider).ConvertTo(Length.Metre), Is.EqualTo(300000)); }
public void GetDisplayUnit_UnregisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); unitProvider.TrySetDisplayUnit<TypographicLength>("m"); Assert.Throws<InvalidOperationException>(() => unitProvider.GetDisplayUnit(typeof(Length))); string symbol; Assert.Throws<InvalidOperationException>(() => unitProvider.GetDisplayUnit(typeof(Length), out symbol)); }
public void GetDisplayUnit_RegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.TrySetDisplayUnit<Length>("m"); Assert.AreEqual("m", unitProvider.GetDisplayUnit(typeof(Length))); string symbol; Assert.AreEqual(Length.Metre, unitProvider.GetDisplayUnit(typeof(Length), out symbol)); }
public void TryGetDisplayUnit_UnregisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); unitProvider.TrySetDisplayUnit<TypographicLength>("m"); Length unit; string symbol; Assert.IsFalse(unitProvider.TryGetDisplayUnit(out unit, out symbol)); }
public void TryGetDisplayUnit_RegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.TrySetDisplayUnit<Length>("m"); Length unit; string symbol; Assert.IsTrue(unitProvider.TryGetDisplayUnit(out unit, out symbol)); Assert.AreEqual(Length.Metre, unit); Assert.AreEqual("m", symbol); }
public void TryGetUnit_GenericOutputAndNotUniqueUnit_GetsFirstRegistered() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); IQuantity unit; Assert.IsTrue(unitProvider.TryGetUnit(typeof(Length), "m", out unit)); Assert.AreEqual(Length.Metre, unit); }
public void GetUnits_NotUniqueUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); var units = unitProvider.GetUnits(typeof(Length)); Assert.AreEqual(1, units.Count); Assert.AreEqual(Length.Metre, units["m"]); }
public void RegisterUnit_ParseRegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); Assert.AreEqual(5 * Length.Metre, Length.Parse("5 m", unitProvider)); }
public void CustomFootUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Foot, "'"); Assert.That(Length.Parse("3'", unitProvider).ConvertTo(Length.Foot), Is.EqualTo(3)); }