예제 #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));
        }
예제 #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));
        }
예제 #3
0
        public void TrySetDisplayUnit_NotRegisteredUnit()
        {
            var unitProvider = new UnitProvider(CultureInfo.InvariantCulture);

            unitProvider.RegisterUnit(Length.Metre, "m");
            Assert.IsFalse(unitProvider.TrySetDisplayUnit <Length>("km"));
        }
예제 #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));
        }
예제 #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));
        }
예제 #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));
        }
예제 #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()));
        }
예제 #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);
        }
예제 #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()));
        }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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);
 }
예제 #14
0
 public void TrySetDisplayUnit_NotRegisteredUnit()
 {
     var unitProvider = new UnitProvider(CultureInfo.InvariantCulture);
     unitProvider.RegisterUnit(Length.Metre, "m");
     Assert.IsFalse(unitProvider.TrySetDisplayUnit<Length>("km"));
 }