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

            unitProvider.RegisterUnit(Length.Metre, "m");
            Assert.IsFalse(unitProvider.TrySetDisplayUnit <Length>("km"));
        }
Exemplo n.º 4
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.º 5
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.º 6
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.º 7
0
        public void LoadFromList_Test1()
        {
            var up = new UnitProvider(typeof(UnitProvider).Assembly, CultureInfo.InvariantCulture);
            up.TrySetDisplayUnit<Length>("km");
            var file = CsvFile.Load(TestList, up);
            ValidateTest1(file);
            Assert.AreEqual(typeof(Length), file.Columns[2].Type);

            var outputStream = new MemoryStream();
            file.Save(outputStream, null, up);
            Assert.AreEqual(Test1Content, Encoding.UTF8.GetString(outputStream.ToArray()));
        }
Exemplo n.º 8
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.º 9
0
        public void LoadFromList_Test1()
        {
            var up = new UnitProvider(typeof(UnitProvider).Assembly, CultureInfo.InvariantCulture);

            up.TrySetDisplayUnit <Length>("km");
            var file = CsvFile.Load(TestList, up);

            ValidateTest1(file);
            Assert.AreEqual(typeof(Length), file.Columns[2].Type);

            var outputStream = new MemoryStream();

            file.Save(outputStream, null, up);
            Assert.AreEqual(Test1Content, Encoding.UTF8.GetString(outputStream.ToArray()));
        }
Exemplo n.º 10
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.º 11
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.º 12
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.º 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 TrySetDisplayUnit_NotRegisteredUnit()
 {
     var unitProvider = new UnitProvider(CultureInfo.InvariantCulture);
     unitProvider.RegisterUnit(Length.Metre, "m");
     Assert.IsFalse(unitProvider.TrySetDisplayUnit<Length>("km"));
 }