コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        public void RegisterUnitsByType_ParseUnregisteredUnit_ThrowsException()
        {
            var unitProvider = new UnitProvider(CultureInfo.InvariantCulture);

            unitProvider.RegisterUnits(typeof(Length));
            Assert.Throws <FormatException>(() => Mass.Parse("5 kg", unitProvider));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 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"));
         }
     }
 }
コード例 #7
0
 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));
 }
コード例 #8
0
 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));
 }
コード例 #9
0
 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"));
         }
     }
 }
コード例 #10
0
 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));
 }
コード例 #11
0
 public void RegisterUnitsByType_ParseUnregisteredUnit_ThrowsException()
 {
     var unitProvider = new UnitProvider(CultureInfo.InvariantCulture);
     unitProvider.RegisterUnits(typeof(Length));
     Assert.Throws<FormatException>(() => Mass.Parse("5 kg", unitProvider));
 }