Exemplo n.º 1
0
 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"));
 }
Exemplo n.º 2
0
        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"));
        }
Exemplo n.º 3
0
        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"]);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        public void TrySetDisplayUnit_NotRegisteredUnit()
        {
            var unitProvider = new UnitProvider(CultureInfo.InvariantCulture);

            unitProvider.RegisterUnit(Length.Metre, "m");
            Assert.IsFalse(unitProvider.TrySetDisplayUnit <Length>("km"));
        }
Exemplo n.º 8
0
        public void RegisterUnit_ParseUnregisteredUnit_ThrowsException()
        {
            var unitProvider = new UnitProvider(CultureInfo.InvariantCulture);

            unitProvider.RegisterUnit(Length.Metre, "m");
            Assert.Throws <FormatException>(() => Length.Parse("5 cm", unitProvider));
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
 public void TrySetDisplayUnit_NotRegisteredUnit()
 {
     var unitProvider = new UnitProvider(CultureInfo.InvariantCulture);
     unitProvider.RegisterUnit(Length.Metre, "m");
     Assert.IsFalse(unitProvider.TrySetDisplayUnit<Length>("km"));
 }
Exemplo n.º 17
0
 public void RegisterUnit_ParseUnregisteredUnit_ThrowsException()
 {
     var unitProvider = new UnitProvider(CultureInfo.InvariantCulture);
     unitProvider.RegisterUnit(Length.Metre, "m");
     Assert.Throws<FormatException>(() => Length.Parse("5 cm", unitProvider));
 }
Exemplo n.º 18
0
 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));
 }
Exemplo n.º 19
0
 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));
 }
Exemplo n.º 20
0
 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));
 }
Exemplo n.º 21
0
 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));
 }
Exemplo n.º 22
0
 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);
 }
Exemplo n.º 23
0
 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);
 }
Exemplo n.º 24
0
 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"]);
 }
Exemplo n.º 25
0
 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));
 }
Exemplo n.º 26
0
 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));
 }