コード例 #1
0
        /// <summary>
        /// Converts an instance of CustomizedProduct into an instance of GetCustomizedProductModelView.
        /// </summary>
        /// <param name="customizedProduct">Instance of CustomizedProduct being converted.</param>
        /// <param name="unit">String representing the unit to which the CustomizedProduct's dimensions will be converted to.</param>
        /// <returns>Instance of GetCustomizedProductModelView.</returns>
        /// <exception cref="System.ArgumentException">Thrown when the provided instance of CustomizedProduct is null.</exception>
        public static GetCustomizedProductModelView fromEntity(CustomizedProduct customizedProduct, string unit)
        {
            if (customizedProduct == null)
            {
                throw new ArgumentException(ERROR_NULL_CUSTOMIZED_PRODUCT);
            }

            GetCustomizedProductModelView customizedProductModelView = new GetCustomizedProductModelView();

            customizedProductModelView.customizedProductId = customizedProduct.Id;
            customizedProductModelView.reference           = customizedProduct.reference;
            customizedProductModelView.designation         = customizedProduct.designation;
            customizedProductModelView.status = customizedProduct.status;
            customizedProductModelView.customizedDimensions = CustomizedDimensionsModelViewService.fromEntity(customizedProduct.customizedDimensions, unit);

            if (customizedProduct.customizedMaterial != null)
            {
                customizedProductModelView.customizedMaterial = CustomizedMaterialModelViewService.fromEntity(customizedProduct.customizedMaterial);
            }

            customizedProductModelView.product = ProductModelViewService.fromEntityAsBasic(customizedProduct.product);
            customizedProductModelView.slots   = SlotModelViewService.fromCollection(customizedProduct.slots, unit);


            return(customizedProductModelView);
        }
        public void ensureFromEntityDoesNotConvertValuesIfNoUnitIsProvided()
        {
            double height = 30;
            double width  = 50;
            double depth  = 15;

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

            GetCustomizedDimensionsModelView getCustomizedDimensionsModelView = CustomizedDimensionsModelViewService.fromEntity(customizedDimensions);

            Assert.Equal(getCustomizedDimensionsModelView.height, height);
            Assert.Equal(getCustomizedDimensionsModelView.width, width);
            Assert.Equal(getCustomizedDimensionsModelView.depth, depth);
        }
        public void ensureFromEntityThrowsExceptionIfCustomizedDimensionsIsNull()
        {
            CustomizedDimensions customizedDimensions = null;

            Action fromEntity = () => CustomizedDimensionsModelViewService.fromEntity(customizedDimensions);

            Assert.Throws <ArgumentException>(fromEntity);


            //Make sure overload has the same behaviour
            fromEntity = () => CustomizedDimensionsModelViewService.fromEntity(customizedDimensions, "m");

            Assert.Throws <ArgumentException>(fromEntity);
        }
        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));
        }
コード例 #5
0
        /// <summary>
        /// Converts an instance of Slot into an instance of GetSlotModelView.
        /// </summary>
        /// <param name="slot">Instance of Slot being converted.</param>
        /// <param name="unit">String representing the unit to which the Slot's dimensions will be converted to.</param>
        /// <returns>Instance of GetSlotModelView.</returns>
        /// <exception cref="System.ArgumentException">Thrown when the provided instance of Slot is null.</exception>
        public static GetSlotModelView fromEntity(Slot slot, string unit)
        {
            if (slot == null)
            {
                throw new ArgumentException(ERROR_NULL_SLOT);
            }

            GetSlotModelView slotModelView = new GetSlotModelView();

            slotModelView.slotId         = slot.Id;
            slotModelView.slotDimensions = CustomizedDimensionsModelViewService.fromEntity(slot.slotDimensions, unit);

            if (slot.customizedProducts.Any())
            {
                slotModelView.customizedProducts = CustomizedProductModelViewService.fromCollection(slot.customizedProducts);
            }

            return(slotModelView);
        }