コード例 #1
0
        public void ensureConvertToUnitUsesMinimumUnitIfArgumentIsNull()
        {
            Console.WriteLine("ensureConvertToUnitUsesMinimumUnitIfArgumentIsNull");
            double value = 10;

            Assert.Equal(value, MeasurementUnitService.convertToUnit(value, null), 1);
        }
        public void ensureFromEntityWithUnitConvertsContinuousDimensionInterval()
        {
            double minValue  = 20;
            double maxValue  = 60;
            double increment = 2;

            Dimension continuousDimensionInterval = new ContinuousDimensionInterval(minValue, maxValue, increment);

            string unit = "dm";

            GetDimensionModelView getDimensionModelView = DimensionModelViewService.fromEntity(continuousDimensionInterval, unit);

            GetContinuousDimensionIntervalModelView result = (GetContinuousDimensionIntervalModelView)getDimensionModelView;

            GetContinuousDimensionIntervalModelView expected = new GetContinuousDimensionIntervalModelView();

            expected.minValue  = MeasurementUnitService.convertToUnit(minValue, unit);
            expected.maxValue  = MeasurementUnitService.convertToUnit(maxValue, unit);
            expected.increment = MeasurementUnitService.convertToUnit(increment, unit);
            expected.unit      = unit;

            Assert.Equal(expected.minValue, result.minValue);
            Assert.Equal(expected.maxValue, result.maxValue);
            Assert.Equal(expected.increment, result.increment);
            Assert.Equal(expected.unit, result.unit);
        }
        public void ensureFromEntityWithUnitConvertsDiscreteDimensionInterval()
        {
            List <double> values = new List <double>()
            {
                21, 35, 42
            };

            Dimension discreteDimensionInterval = new DiscreteDimensionInterval(values);

            string unit = "dm";

            GetDimensionModelView getDimensionModelView = DimensionModelViewService.fromEntity(discreteDimensionInterval, unit);

            GetDiscreteDimensionIntervalModelView result = (GetDiscreteDimensionIntervalModelView)getDimensionModelView;

            GetDiscreteDimensionIntervalModelView expected = new GetDiscreteDimensionIntervalModelView();
            List <double> expectedValues = new List <double>();

            foreach (double dimensionValue in values)
            {
                double convertedValue = MeasurementUnitService.convertToUnit(dimensionValue, unit);
                expectedValues.Add(convertedValue);
            }

            expected.values = expectedValues;
            expected.unit   = unit;

            Assert.Equal(expected.values, result.values);
            Assert.Equal(expected.unit, result.unit);
        }
コード例 #4
0
        public void ensureConvertToUnitThrowsArgumentException()
        {
            Console.WriteLine("ensureConvertToUnitThrowsArgumentException");
            double value  = 1;
            Action action = () => MeasurementUnitService.convertToUnit(value, "der alte würfelt nicht");

            Assert.Throws <ArgumentException>(action);
        }
コード例 #5
0
        public void ensureConvertToUnitSucceeds()
        {
            Console.WriteLine("ensureConvertToUnitSucceeds");
            double value = 10;
            string unit  = "cm";

            Assert.Equal(1, MeasurementUnitService.convertToUnit(value, unit), 1);
        }
コード例 #6
0
        /// <summary>
        /// Creates a model view with a dimension information
        /// </summary>
        /// <param name="dimension">Dimension with the dimension being created the model view</param>
        /// <param name="unit">Unit to which the values will be converted</param>
        /// <returns>GetDimensionModelView with the dimension information model view</returns>
        /// <exception cref="System.ArgumentNullException">Throw when the provided Dimension is null.</exception>
        public static GetDimensionModelView fromEntity(Dimension dimension, string unit)
        {
            if (dimension == null)
            {
                throw new ArgumentNullException(ERROR_NULL_DIMENSION);
            }
            //if no unit is provided, use the default implementation
            if (Strings.isNullOrEmpty(unit))
            {
                return(fromEntity(dimension));
            }

            Type dimensionType = dimension.GetType();

            if (dimensionType == typeof(SingleValueDimension))
            {
                SingleValueDimension             singleValueDimension = (SingleValueDimension)dimension;
                GetSingleValueDimensionModelView singleMV             = new GetSingleValueDimensionModelView();
                singleMV.id    = singleValueDimension.Id;
                singleMV.unit  = unit;
                singleMV.value = MeasurementUnitService.convertToUnit(singleValueDimension.value, unit);

                return(singleMV);
            }
            else if (dimensionType == typeof(DiscreteDimensionInterval))
            {
                DiscreteDimensionInterval             discreteDimension = (DiscreteDimensionInterval)dimension;
                GetDiscreteDimensionIntervalModelView discreteMV        = new GetDiscreteDimensionIntervalModelView();
                discreteMV.id   = discreteDimension.Id;
                discreteMV.unit = unit;

                List <double> values = new List <double>();
                foreach (double value in discreteDimension.values)
                {
                    values.Add(MeasurementUnitService.convertToUnit(value, unit));
                }
                discreteMV.values = values;

                return(discreteMV);
            }
            else if (dimensionType == typeof(ContinuousDimensionInterval))
            {
                ContinuousDimensionInterval             continuousDimension = (ContinuousDimensionInterval)dimension;
                GetContinuousDimensionIntervalModelView continuousMV        = new GetContinuousDimensionIntervalModelView();
                continuousMV.id        = continuousDimension.Id;
                continuousMV.unit      = unit;
                continuousMV.minValue  = MeasurementUnitService.convertToUnit(continuousDimension.minValue, unit);
                continuousMV.maxValue  = MeasurementUnitService.convertToUnit(continuousDimension.maxValue, unit);
                continuousMV.increment = MeasurementUnitService.convertToUnit(continuousDimension.increment, unit);

                return(continuousMV);
            }
            else
            {
                throw new NotImplementedException(ERROR_NO_IMPLEMENTATION_UNKNOWN_DIMENSION);
            }
        }
コード例 #7
0
        /// <summary>
        /// Converts the value from a unit to another unit.
        /// </summary>
        /// <param name="convertUnitMV">ConvertUnitModelView containing unit conversion data.</param>
        /// <returns>ConvertUnitModelView with converted value.</returns>
        public ConvertUnitModelView convertValue(ConvertUnitModelView convertUnitMV)
        {
            double valueInMM = MeasurementUnitService.convertFromUnit(convertUnitMV.value, convertUnitMV.fromUnit);

            double newValue = MeasurementUnitService.convertToUnit(valueInMM, convertUnitMV.toUnit);

            convertUnitMV.value = newValue;

            return(convertUnitMV);
        }
コード例 #8
0
        public override DimensionDTO toDTO(string unit)
        {
            if (unit == null)
            {
                return(this.toDTO());
            }
            SingleValueDimensionDTO dto = new SingleValueDimensionDTO();

            dto.id    = Id;
            dto.value = MeasurementUnitService.convertToUnit(value, unit);
            dto.unit  = unit;

            return(dto);
        }
コード例 #9
0
        /// <summary>
        /// Builds a CustomizedDimensionsDTO out of a CustomizedDimensions instance
        /// </summary>
        /// <param name="unit">Desired unit</param>
        /// <returns>DimensionDTO instance</returns>
        public CustomizedDimensionsDTO toDTO(string unit)
        {
            if (unit == null)
            {
                return(this.toDTO());
            }

            CustomizedDimensionsDTO customizedDimensionsDTO = new CustomizedDimensionsDTO();

            customizedDimensionsDTO.Id     = this.Id;
            customizedDimensionsDTO.width  = MeasurementUnitService.convertToUnit(width, unit);
            customizedDimensionsDTO.depth  = MeasurementUnitService.convertToUnit(depth, unit);
            customizedDimensionsDTO.height = MeasurementUnitService.convertToUnit(height, unit);
            customizedDimensionsDTO.unit   = unit;
            return(customizedDimensionsDTO);
        }
        public void ensureFromEntityConvertsValuesToProvidedUnit()
        {
            double height = 30;
            double width  = 50;
            double depth  = 15;

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(height, width, depth);

            string unit = "m";

            GetCustomizedDimensionsModelView getCustomizedDimensionsModelView = CustomizedDimensionsModelViewService.fromEntity(customizedDimensions, unit);

            Assert.Equal(getCustomizedDimensionsModelView.height, MeasurementUnitService.convertToUnit(height, unit));
            Assert.Equal(getCustomizedDimensionsModelView.width, MeasurementUnitService.convertToUnit(width, unit));
            Assert.Equal(getCustomizedDimensionsModelView.depth, MeasurementUnitService.convertToUnit(depth, unit));
        }
コード例 #11
0
        /// <summary>
        /// Builds a DimensionDTO out of a ContinuousDimensionInterval instance
        /// </summary>
        /// <param name="unit">Desired unit</param>
        /// <returns>DimensionDTO instance</returns>
        public override DimensionDTO toDTO(string unit)
        {
            if (unit == null)
            {
                return(this.toDTO());
            }

            ContinuousDimensionIntervalDTO dto = new ContinuousDimensionIntervalDTO();

            dto.id        = Id;
            dto.minValue  = MeasurementUnitService.convertToUnit(minValue, unit);
            dto.maxValue  = MeasurementUnitService.convertToUnit(maxValue, unit);
            dto.increment = MeasurementUnitService.convertToUnit(increment, unit);
            dto.unit      = unit;

            return(dto);
        }
        public void ensureFromModelViewConvertsValuesToProvidedUnit()
        {
            AddCustomizedDimensionsModelView addCustomizedDimensionsModelView = new AddCustomizedDimensionsModelView();

            string unit = "cm";

            addCustomizedDimensionsModelView.height = 30;
            addCustomizedDimensionsModelView.width  = 50;
            addCustomizedDimensionsModelView.depth  = 15;
            addCustomizedDimensionsModelView.unit   = unit;

            //the customized dimensions' values should be in the minimum unit
            CustomizedDimensions customizedDimensions = CustomizedDimensionsModelViewService.fromModelView(addCustomizedDimensionsModelView);

            Assert.Equal(addCustomizedDimensionsModelView.height, MeasurementUnitService.convertToUnit(customizedDimensions.height, unit));
            Assert.Equal(addCustomizedDimensionsModelView.width, MeasurementUnitService.convertToUnit(customizedDimensions.width, unit));
            Assert.Equal(addCustomizedDimensionsModelView.depth, MeasurementUnitService.convertToUnit(customizedDimensions.depth, unit));
        }
        public void ensureFromEntityWithUnitConvertsSingleValueDimension()
        {
            double value = 15;

            Dimension singleValueDimension = new SingleValueDimension(value);

            string unit = "cm";

            GetDimensionModelView getDimensionModelView = DimensionModelViewService.fromEntity(singleValueDimension, unit);

            GetSingleValueDimensionModelView expected = new GetSingleValueDimensionModelView();

            expected.value = MeasurementUnitService.convertToUnit(value, unit);
            expected.unit  = unit;

            GetSingleValueDimensionModelView result = (GetSingleValueDimensionModelView)getDimensionModelView;

            Assert.Equal(expected.value, result.value);
            Assert.Equal(expected.unit, result.unit);
        }
        /// <summary>
        /// Converts an instance of CustomizedDimensions into an instance of GetCustomizedModelView.
        /// </summary>
        /// <param name="customizedDimensions">Instance of CustomizedDimensions.</param>
        /// <param name="unit">Unit to which the values will be converted.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">Thrown when the provided CustomizedDimensions is null.</exception>
        public static GetCustomizedDimensionsModelView fromEntity(CustomizedDimensions customizedDimensions, string unit)
        {
            if (customizedDimensions == null)
            {
                throw new ArgumentException(ERROR_NULL_CUSTOMIZED_DIMENSIONS);
            }
            //if no unit is provided resort to the default implementation
            if (Strings.isNullOrEmpty(unit))
            {
                return(fromEntity(customizedDimensions));
            }

            GetCustomizedDimensionsModelView modelView = new GetCustomizedDimensionsModelView();

            modelView.unit   = unit;
            modelView.height = MeasurementUnitService.convertToUnit(customizedDimensions.height, unit);
            modelView.width  = MeasurementUnitService.convertToUnit(customizedDimensions.width, unit);
            modelView.depth  = MeasurementUnitService.convertToUnit(customizedDimensions.depth, unit);

            return(modelView);
        }
コード例 #15
0
        /// <summary>
        /// Converts an instance of ProductSlotWidths into an instance of GetProductSlotWidthsModelView.
        /// </summary>
        /// <param name="productSlotWidths">Instance of ProductSlotWidths.</param>
        /// <param name="unit">Unit to which the values will be converted.</exception>
        /// <returns>The created instance of GetProductSlotWidthsModelView.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the provided instance of ProductSlotWidths is null.</exception>
        public static GetProductSlotWidthsModelView fromEntity(ProductSlotWidths productSlotWidths, string unit)
        {
            if (productSlotWidths == null)
            {
                throw new ArgumentNullException(ERROR_NULL_PRODUCT_SLOT_WIDTHS);
            }

            //if no unit is specified, resort to the default implementation
            if (Strings.isNullOrEmpty(unit))
            {
                return(fromEntity(productSlotWidths));
            }
            GetProductSlotWidthsModelView productSlotWidthsModelView = new GetProductSlotWidthsModelView();

            productSlotWidthsModelView.unit             = unit;
            productSlotWidthsModelView.minWidth         = MeasurementUnitService.convertToUnit(productSlotWidths.minWidth, unit);
            productSlotWidthsModelView.maxWidth         = MeasurementUnitService.convertToUnit(productSlotWidths.maxWidth, unit);
            productSlotWidthsModelView.recommendedWidth = MeasurementUnitService.convertToUnit(productSlotWidths.recommendedWidth, unit);

            return(productSlotWidthsModelView);
        }
        public void ensureFromEntityWithUnitConvertsValues()
        {
            double minWidth         = 25;
            double maxWidth         = 50;
            double recommendedWidth = 35;

            ProductSlotWidths slotWidths = ProductSlotWidths.valueOf(minWidth, maxWidth, recommendedWidth);

            string unit = "dm";

            GetProductSlotWidthsModelView result = ProductSlotWidthsModelViewService.fromEntity(slotWidths, unit);

            GetProductSlotWidthsModelView expected = new GetProductSlotWidthsModelView();

            expected.minWidth         = MeasurementUnitService.convertToUnit(minWidth, unit);
            expected.maxWidth         = MeasurementUnitService.convertToUnit(maxWidth, unit);
            expected.recommendedWidth = MeasurementUnitService.convertToUnit(recommendedWidth, unit);
            expected.unit             = unit;

            Assert.Equal(expected.minWidth, result.minWidth);
            Assert.Equal(expected.maxWidth, result.maxWidth);
            Assert.Equal(expected.recommendedWidth, result.recommendedWidth);
            Assert.Equal(expected.unit, result.unit);
        }