private static void CheckIfUnitsAreTheSameType(ScalarUnitOfMeasure sourceUom, ScalarUnitOfMeasure targetUom)
 {
     if (sourceUom.UnitDimension.DomainID != targetUom.UnitDimension.DomainID)
     {
         throw new InvalidOperationException("Cannot convert between units of different types.");
     }
 }
        public void GivenUnitOfMeasureWhenGetDomainIdThenDomainId()
        {
            _unitOfMeasure.domainID = "Branch";

            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);
            Assert.AreEqual("Branch", unitOfMeasure.DomainID);
        }
 private double Convert(CompositeUnitOfMeasure sourceUom, ScalarUnitOfMeasure targetUom, double sourceValue)
 {
     foreach (var conversionFactor in targetUom.UnitDimension.CompositeEquivalents)
     {
         var compositeSourceValue = (sourceValue * conversionFactor.Scale + conversionFactor.BaseOffset - targetUom.BaseOffset) / targetUom.Scale;
         var compositeTargetUom   = new CompositeUnitOfMeasure(conversionFactor.DomainID);
         return(Convert(sourceUom, compositeTargetUom, compositeSourceValue));
     }
     throw new InvalidOperationException("Cannot convert between units of different types.");
 }
 private double Convert(CompositeUnitOfMeasure sourceUom, ScalarUnitOfMeasure targetUom, double sourceValue)
 {
     foreach (var conversionFactor in targetUom.UnitDimension.CompositeEquivalents)
     {
         var compositeSourceValue = (sourceValue * conversionFactor.Scale + conversionFactor.BaseOffset - targetUom.BaseOffset) / targetUom.Scale;
         var compositeTargetUom = new CompositeUnitOfMeasure(conversionFactor.DomainID);
         return Convert(sourceUom, compositeTargetUom, compositeSourceValue);
     }
     throw new InvalidOperationException("Cannot convert between units of different types.");
 }
        public void GivenUnitOfMeasureWhenGetPluralThenPluralForCultureIsFound()
        {
            _unitOfMeasure.Name = new[]
            {
                new UnitSystemUnitDimensionUnitDimensionRepresentationUnitOfMeasureName
                {
                    locale = "de",
                    plural = "Ursprünge"
                },
                new UnitSystemUnitDimensionUnitDimensionRepresentationUnitOfMeasureName
                {
                    locale = CultureInfoDefault.DefaultCulture,
                    plural = "Origins"
                }
            };

            var culture = CultureInfo.GetCultureInfo("de");
            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension, culture);
            Assert.AreEqual("Ursprünge", unitOfMeasure.LabelPlural);
        }
        public void GivenUnitOfMeasureWhenGetLabelThenLabelForCultureIsFound()
        {
            _unitOfMeasure.Name = new[]
            {
                new UnitSystemUnitDimensionUnitDimensionRepresentationUnitOfMeasureName
                {
                    locale = "de",
                    label = "Herkunft"
                },
                new UnitSystemUnitDimensionUnitDimensionRepresentationUnitOfMeasureName
                {
                    locale = CultureInfoDefault.DefaultCulture,
                    label = "Origin"
                }
            };

            var culture = CultureInfo.GetCultureInfo("de");
            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension, culture);
            Assert.AreEqual("Herkunft", unitOfMeasure.Label);
        }
        private double Convert(ScalarUnitOfMeasure sourceUom, ScalarUnitOfMeasure targetUom, double sourceValue)
        {
            CheckIfUnitsAreTheSameType(sourceUom, targetUom);

            return((sourceValue * sourceUom.Scale + sourceUom.BaseOffset - targetUom.BaseOffset) / targetUom.Scale);
        }
        public void GivenUnitOfMeasureWhenGetBaseOffsetThenBaseOffset()
        {
            _unitOfMeasure.baseOffset = 5.516;

            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);
            Assert.AreEqual(5.516, unitOfMeasure.BaseOffset);
        }
        public void GivenUnitOfMeasureWhenGetUomIdThenUomId()
        {
            _unitOfMeasure.uomID = 5;

            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);
            Assert.AreEqual(5, unitOfMeasure.UomId);
        }
 public void GivenUnitDimensionWhenGetUnitDimensionThenUnitDimension()
 {
     var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);
     Assert.AreSame(_unitDimension, unitOfMeasure.UnitDimension);
 }
        public void GivenUnitOfMeasureWhenGetScaleThenScale()
        {
            _unitOfMeasure.scale = 783681;

            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);
            Assert.AreEqual(783681, unitOfMeasure.Scale);
        }
 private static void CheckIfUnitsAreTheSameType(ScalarUnitOfMeasure sourceUom, ScalarUnitOfMeasure targetUom)
 {
     if(sourceUom.UnitDimension.DomainID != targetUom.UnitDimension.DomainID)
         throw new InvalidOperationException("Cannot convert between units of different types.");
 }
        private double Convert(ScalarUnitOfMeasure sourceUom, ScalarUnitOfMeasure targetUom, double sourceValue)
        {
            CheckIfUnitsAreTheSameType(sourceUom, targetUom);

            return (sourceValue * sourceUom.Scale + sourceUom.BaseOffset - targetUom.BaseOffset) / targetUom.Scale;
        }