Esempio n. 1
0
        public void ensureApplyAllRestrictionsReturnsNullIfProductArgumentNull()
        {
            ProductCategory cat = new ProductCategory("All Products");

            Color        black  = Color.valueOf("Deep Black", 0, 0, 0, 0);
            Color        white  = Color.valueOf("Blinding White", 255, 255, 255, 0);
            List <Color> colors = new List <Color>()
            {
                black, white
            };

            Finish        glossy   = Finish.valueOf("Glossy", 100);
            Finish        matte    = Finish.valueOf("Matte", 0);
            List <Finish> finishes = new List <Finish>()
            {
                glossy, matte
            };

            Material material = new Material("#001", "Really Expensive Wood", "ola.jpg", colors, finishes);

            Dimension heightDimension = new SingleValueDimension(50);
            Dimension widthDimension  = new DiscreteDimensionInterval(new List <double>()
            {
                60, 65, 70, 80, 90, 105
            });
            Dimension depthDimension = new ContinuousDimensionInterval(10, 25, 5);

            Measurement measurement = new Measurement(heightDimension, widthDimension, depthDimension);

            Product product = new Product("Test", "Shelf", "shelf.glb", cat, new List <Material>()
            {
                material
            }, new List <Measurement>()
            {
                measurement
            }, ProductSlotWidths.valueOf(4, 4, 4));

            CustomizedDimensions customDimension   = CustomizedDimensions.valueOf(50, 80, 25);
            CustomizedMaterial   customMaterial    = CustomizedMaterial.valueOf(material, white, matte);
            CustomizedProduct    customizedProduct = CustomizedProductBuilder.createCustomizedProduct("reference", product, customDimension).build();

            customizedProduct.changeCustomizedMaterial(customMaterial);

            customizedProduct.finalizeCustomization();

            Assert.Null(new RestrictableImpl().applyAllRestrictions(customizedProduct, null));
        }
        public void ensureApplyRemovesContinuousDimensions()
        {
            Color                       color        = Color.valueOf("Open the Steins Gate", 100, 100, 100, 100);
            Finish                      finish       = Finish.valueOf("der alte wurfelt nicht", 15);
            Material                    material     = new Material("#12", "K6205", "12.jpg", new List <Color>(new[] { color }), new List <Finish>(new[] { finish }));
            ProductCategory             cat          = new ProductCategory("AI");
            ContinuousDimensionInterval continuous1  = new ContinuousDimensionInterval(110.0, 150.0, 2.0);
            ContinuousDimensionInterval continuous2  = new ContinuousDimensionInterval(50.0, 80.0, 2.0);
            Measurement                 measurement1 = new Measurement(continuous1, continuous1, continuous1);
            Measurement                 measurement2 = new Measurement(continuous2, continuous2, continuous2);
            ContinuousDimensionInterval continuous3  = new ContinuousDimensionInterval(35.0, 45.0, 1.0);
            ContinuousDimensionInterval continuous4  = new ContinuousDimensionInterval(10.0, 20.0, 2.0);
            Measurement                 measurement3 = new Measurement(continuous3, continuous3, continuous3);
            Measurement                 measurement4 = new Measurement(continuous4, continuous4, continuous4);
            List <Measurement>          measurements = new List <Measurement>()
            {
                measurement1, measurement2
            };
            List <Measurement> measurements2 = new List <Measurement>()
            {
                measurement3, measurement4
            };

            Product component2 = new Product("#24", "Milky Way Corssing", "5.glb", cat, new List <Material>(new[] { material }), measurements2);
            Product component  = new Product("#5", "Solitude of the Astigmatism: Entangled Sheep", "5.glb", cat, new List <Material>(new[] { material }), measurements2, new List <Product>()
            {
                component2
            });
            Product product = new Product("#4", "Solitude of the Mournful Flow: A Stray Sheep", "4.gltf", cat, new List <Material>(new[] { material }), measurements, new List <Product>()
            {
                component
            });

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(110, 110, 110);
            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, color, finish);
            CustomizedProduct    custom = CustomizedProductBuilder.createCustomizedProduct("12345", product, customizedDimensions).withMaterial(customizedMaterial).build();

            WidthPercentageAlgorithm algorithm = new WidthPercentageAlgorithm();
            Input minInput = Input.valueOf("Minimum Percentage", "From 0 to 1");
            Input maxInput = Input.valueOf("Maximum Percentage", "From 0 to 1");
            Dictionary <Input, string> inputs = new Dictionary <Input, string>();

            inputs.Add(minInput, "0.9");
            inputs.Add(maxInput, "1.0");
            algorithm.setInputValues(inputs);
            Assert.Null(algorithm.apply(custom, component));
        }
        public void ensureApplyRestrictsSingleValueDimensions()
        {
            Finish finish = Finish.valueOf("der alte wurfelt nicht", 20);
            Color  color  = Color.valueOf("Missing Link of the Annihilator: Absolute Zero", 100, 100, 100, 100);

            Material material = new Material("#12", "K6205", "12.jpg", new List <Color>()
            {
                color
            }, new List <Finish>()
            {
                finish
            });
            ProductCategory cat          = new ProductCategory("AI");
            Measurement     measurement  = new Measurement(new SingleValueDimension(200), new SingleValueDimension(100), new SingleValueDimension(50));
            Measurement     measurement1 = new Measurement(new SingleValueDimension(100), new SingleValueDimension(200), new SingleValueDimension(50));
            Measurement     measurement2 = new Measurement(new SingleValueDimension(100), new SingleValueDimension(50), new SingleValueDimension(200));

            List <Measurement> measurements = new List <Measurement>()
            {
                measurement, measurement1, measurement2
            };
            Product component = new Product("#16", "Altair of the Point at Infinity: Vega and Altair", "16.gltf", cat, new List <Material>(new[] { material }), measurements);
            Product product   = new Product("#23", "Arclight of the Point at Infinity: Arclight of the Sky", "23.glb", cat, new List <Material>(new[] { material }), measurements, new List <Product>()
            {
                component
            });


            CustomizedDimensions customizedProductDimensions = CustomizedDimensions.valueOf(200, 100, 50);
            CustomizedMaterial   customizedMaterial          = CustomizedMaterial.valueOf(material, color, finish);
            CustomizedProduct    customizedProduct           = CustomizedProductBuilder.createCustomizedProduct("12345", product, customizedProductDimensions).withMaterial(customizedMaterial).build();

            WidthPercentageAlgorithm algorithm = new WidthPercentageAlgorithm();
            Input minInput = Input.valueOf("Minimum Percentage", "From 0 to 1");
            Input maxInput = Input.valueOf("Maximum Percentage", "From 0 to 1");
            Dictionary <Input, string> inputs = new Dictionary <Input, string>();

            inputs.Add(minInput, "0.9");
            inputs.Add(maxInput, "1.0");
            algorithm.setInputValues(inputs);
            Product alteredProduct = algorithm.apply(customizedProduct, component);

            Assert.Single(alteredProduct.productMeasurements);
            double remainingValue = ((SingleValueDimension)alteredProduct.productMeasurements[0].measurement.width).value;

            Assert.True(remainingValue == 100);
        }
        public void ensureAddCustomizedProductThrowsExceptionIfProductDoesNotFit()
        {
            Slot instance = new Slot("identifier 0", CustomizedDimensions.valueOf(100, 200, 70));

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(80, 200, 50);
            CustomizedProduct    customizedProduct    = buildCustomizedProduct("1234", customizedDimensions);

            instance.addCustomizedProduct(customizedProduct);

            CustomizedDimensions otherCustomizedDimensions = CustomizedDimensions.valueOf(80, 200, 70);
            CustomizedProduct    otherCustomizedProduct    = buildCustomizedProduct("1235", otherCustomizedDimensions);


            Action addCustomizedProductAction = () => instance.addCustomizedProduct(otherCustomizedProduct);

            Assert.Throws <ArgumentException>(addCustomizedProductAction);
        }
        public void ensureChangingDimensionsWhileSlotHasProductsDoesNotChangeDimensions()
        {
            Slot instance = new Slot("identifier 0", CustomizedDimensions.valueOf(100, 200, 300));

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(50, 200, 300);
            CustomizedProduct    customizedProduct    = buildCustomizedProduct("1234", customizedDimensions);

            instance.addCustomizedProduct(customizedProduct);

            CustomizedDimensions otherCustomizedDimensions = CustomizedDimensions.valueOf(80, 200, 250);

            try {
                instance.changeDimensions(otherCustomizedDimensions);
            } catch (Exception) { }

            Assert.NotEqual(instance.slotDimensions, otherCustomizedDimensions);
        }
Esempio n. 6
0
        private CustomizedProduct buildCustomizedProduct(string customizedProductReference)
        {
            var category = new ProductCategory("Drawers");
            //Creating Dimensions
            List <Double> values2 = new List <Double>();

            values2.Add(500.0); //Width

            DiscreteDimensionInterval d2 = new DiscreteDimensionInterval(values2);

            Measurement        measurement  = new Measurement(d2, d2, d2);
            List <Measurement> measurements = new List <Measurement>()
            {
                measurement
            };

            //Creating a material
            string reference   = "1160912";
            string designation = "FR E SH A VOCA DO";

            List <Color> colors = new List <Color>();
            Color        color  = Color.valueOf("AND READ-ER-BIBLE", 1, 2, 3, 0);

            colors.Add(color);

            List <Finish> finishes = new List <Finish>();
            Finish        finish   = Finish.valueOf("Amém", 12);

            finishes.Add(finish);

            Material        material  = new Material(reference, designation, "ola.jpg", colors, finishes);
            List <Material> materials = new List <Material>();

            materials.Add(material);

            IEnumerable <Material> matsList = materials;

            Product product = new Product("#666", "Shelf", "shelf666.glb", category, matsList, measurements);
            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(500.0, 500.0, 500.0);

            //Customized Material
            CustomizedMaterial custMaterial1 = CustomizedMaterial.valueOf(material, color, finish);

            return(CustomizedProductBuilder.createCustomizedProduct(customizedProductReference, product, customizedDimensions).withMaterial(custMaterial1).build());
        }
        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 ensureChangingDimensionsAfterRemovingAllCustomizedProductsDoesNotThrowException()
        {
            Slot instance = new Slot("identifier 0", CustomizedDimensions.valueOf(100, 200, 300));

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(50, 200, 300);
            CustomizedProduct    customizedProduct    = buildCustomizedProduct("1234", customizedDimensions);

            instance.addCustomizedProduct(customizedProduct);
            instance.removeCustomizedProduct(customizedProduct);

            CustomizedDimensions otherCustomizedDimensions = CustomizedDimensions.valueOf(80, 200, 250);

            Action changeDimensionsAction = () => instance.changeDimensions(otherCustomizedDimensions);

            Exception exception = Record.Exception(changeDimensionsAction);

            Assert.Null(exception);
        }
        public void ensureAddingCustomizedProductThatFitsInSlotAddsCustomizedProduct()
        {
            Slot instance = new Slot("identifier 0", CustomizedDimensions.valueOf(100, 200, 300));

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(50, 200, 300);
            CustomizedProduct    customizedProduct    = buildCustomizedProduct("1234", customizedDimensions);

            instance.addCustomizedProduct(customizedProduct);

            CustomizedDimensions otherCustomizedDimensions = CustomizedDimensions.valueOf(40, 200, 300);
            CustomizedProduct    otherCustomizedProduct    = buildCustomizedProduct("1235", otherCustomizedDimensions);

            instance.addCustomizedProduct(otherCustomizedProduct);

            //Add 2nd customized product to slot
            Assert.True(instance.hasCustomizedProduct(otherCustomizedProduct));
            Assert.True(instance.customizedProducts.Count == 2);
        }
        public void ensureAddingCustomizedProductThatFitsInSlotDoesNotThrowException()
        {
            Slot instance = new Slot("identifier 0", CustomizedDimensions.valueOf(100, 200, 300));

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(50, 200, 300);
            CustomizedProduct    customizedProduct    = buildCustomizedProduct("1234", customizedDimensions);

            instance.addCustomizedProduct(customizedProduct);

            CustomizedDimensions otherCustomizedDimensions = CustomizedDimensions.valueOf(40, 200, 300);
            CustomizedProduct    otherCustomizedProduct    = buildCustomizedProduct("1235", otherCustomizedDimensions);

            Action addCustomizedProductAction = () => instance.addCustomizedProduct(otherCustomizedProduct);

            Exception exception = Record.Exception(addCustomizedProductAction);

            Assert.Null(exception);
        }
        public void ensureAddingDuplicateCustomizedDoesNotAddCustomizedProduct()
        {
            Slot instance = new Slot("identifier 0", CustomizedDimensions.valueOf(100, 200, 70));

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(80, 200, 50);
            CustomizedProduct    customizedProduct    = buildCustomizedProduct("1234", customizedDimensions);

            instance.addCustomizedProduct(customizedProduct);

            CustomizedDimensions otherCustomizedDimensions = CustomizedDimensions.valueOf(40, 200, 40);
            CustomizedProduct    otherCustomizedProduct    = buildCustomizedProduct("1234", otherCustomizedDimensions);

            try {
                instance.addCustomizedProduct(otherCustomizedProduct);
            } catch (Exception) { }

            Assert.Single(instance.customizedProducts);
        }
        public void ensureAddCustomizedProductDoesNotAddCustomizedProductIfProductDoesNotFit()
        {
            Slot instance = new Slot("identifier 0", CustomizedDimensions.valueOf(100, 200, 70));

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(80, 200, 50);
            CustomizedProduct    customizedProduct    = buildCustomizedProduct("1234", customizedDimensions);

            instance.addCustomizedProduct(customizedProduct);

            CustomizedDimensions otherCustomizedDimensions = CustomizedDimensions.valueOf(80, 200, 70);
            CustomizedProduct    otherCustomizedProduct    = buildCustomizedProduct("1235", otherCustomizedDimensions);

            try {
                instance.addCustomizedProduct(otherCustomizedProduct);
            } catch (Exception) { }

            Assert.False(instance.hasCustomizedProduct(otherCustomizedProduct));
        }
        public void ensureRestrictProductDimensionsToFitInSlotAdaptsMeasurementsToFitInSlot()
        {
            Slot    instance = new Slot("identifier 0", CustomizedDimensions.valueOf(100, 200, 300));
            Product product  = buildProduct();

            product.addMeasurement(new Measurement(new DiscreteDimensionInterval(new List <Double> {
                100.0, 110.0
            }), new DiscreteDimensionInterval(new List <Double> {
                200.0, 110.0
            }), new ContinuousDimensionInterval(290, 310, 5)));
            product.removeMeasurement(product.productMeasurements[0].measurement);
            Product returned = instance.restrictProductDimensionsToFitInSlot(product);

            Assert.True(returned.productMeasurements.Count == 1);
            Assert.Equal(new SingleValueDimension(100.0), returned.productMeasurements[0].measurement.height);
            Assert.Equal(new SingleValueDimension(200.0), returned.productMeasurements[0].measurement.width);
            Assert.Equal(new DiscreteDimensionInterval(new List <Double> {
                290.0, 295.0, 300.0
            }), returned.productMeasurements[0].measurement.depth);
        }
        /// <summary>
        /// Adds a Slot to a CustomizedProduct.
        /// </summary>
        /// <param name="addSlotModelView">AddSlotModelView with the Slot's information</param>
        /// <returns>An instance of GetCustomizedProductModelView containing updated CustomizedProduct information.</returns>
        /// <exception cref="ResourceNotFoundException">Thrown when the CustomizedProduct could not be found.</exception>
        public GetCustomizedProductModelView addSlotToCustomizedProduct(AddSlotModelView addSlotModelView)
        {
            CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository();

            CustomizedProduct customizedProduct = customizedProductRepository.find(addSlotModelView.customizedProductId);

            if (customizedProduct == null)
            {
                throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_BY_ID, addSlotModelView.customizedProductId));
            }

            checkUserToken(customizedProduct, addSlotModelView.userAuthToken);

            CustomizedDimensions customizedDimensions = CustomizedDimensionsModelViewService.fromModelView(addSlotModelView.slotDimensions);

            customizedProduct.addSlot(customizedDimensions);

            customizedProduct = customizedProductRepository.update(customizedProduct);

            return(CustomizedProductModelViewService.fromEntity(customizedProduct));
        }
        /// <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);
        }
        /// <summary>
        /// Updates an instance of Slot.
        /// </summary>
        /// <param name="updateSlotModelView">Instance of UpdateSlotModelView.</param>
        /// <returns>Instance of GetCustomizedProductModelView with updated CustomizedProduct information.</returns>
        /// <exception cref="ResourceNotFoundException">Thrown when the CustomizedProduct or the Slot could not be found.</exception>
        /// <exception cref="System.ArgumentException">Thrown when none of the CustomizedProduct's properties are updated.</exception>
        public GetCustomizedProductModelView updateSlot(UpdateSlotModelView updateSlotModelView)
        {
            CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository();

            CustomizedProduct customizedProduct = customizedProductRepository.find(updateSlotModelView.customizedProductId);

            if (customizedProduct == null)
            {
                throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_BY_ID, updateSlotModelView.customizedProductId));
            }

            checkUserToken(customizedProduct, updateSlotModelView.userAuthToken);

            Slot slot = customizedProduct.slots.Where(s => s.Id == updateSlotModelView.slotId).SingleOrDefault();

            if (slot == null)
            {
                throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_SLOT, updateSlotModelView.slotId));
            }

            bool performedAtLeastOneUpdate = false;

            if (updateSlotModelView.dimensions != null)
            {
                CustomizedDimensions updatedDimensions = CustomizedDimensionsModelViewService.fromModelView(updateSlotModelView.dimensions);

                customizedProduct.resizeSlot(slot, updatedDimensions);

                performedAtLeastOneUpdate = true;
            }

            if (!performedAtLeastOneUpdate)
            {
                throw new ArgumentException(ERROR_NO_UPDATE_PERFORMED);
            }

            customizedProduct = customizedProductRepository.update(customizedProduct);

            return(CustomizedProductModelViewService.fromEntity(customizedProduct));
        }
        public void ensureApplyRemovesDiscreteDimensions()
        {
            Color                     color     = Color.valueOf("Durpa", 100, 100, 100, 100);
            Finish                    finish    = Finish.valueOf("der alte wurfelt nicht", 35);
            Material                  material  = new Material("#12", "K6205", "12.jpg", new List <Color>(new[] { color }), new List <Finish>(new[] { finish }));
            ProductCategory           cat       = new ProductCategory("AI");
            DiscreteDimensionInterval discrete  = new DiscreteDimensionInterval(new List <double>(new[] { 50.0, 110.0, 150.0 }));
            DiscreteDimensionInterval discrete2 = new DiscreteDimensionInterval(new List <double>(new[] { 50.0, 150.0, 150.0 }));

            Measurement measurement  = new Measurement(new SingleValueDimension(200), discrete, new SingleValueDimension(50));
            Measurement measurement2 = new Measurement(new SingleValueDimension(200), discrete2, new SingleValueDimension(50));

            List <Measurement> measurements = new List <Measurement>()
            {
                measurement
            };
            List <Measurement> measurements2 = new List <Measurement>()
            {
                measurement2
            };
            Product component = new Product("#10", "Pandora of Provable Existence: Forbidden Cubicle", "10.gltf", cat, new List <Material>(new[] { material }), measurements2);
            Product product   = new Product("#9", "Pandora of Eternal Return: Pandora's Box", "9.fbx", cat, new List <Material>(new[] { material }), measurements, new List <Product>()
            {
                component
            });

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(200, 110, 50);
            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, color, finish);
            CustomizedProduct    custom = CustomizedProductBuilder.createCustomizedProduct("12345", product, customizedDimensions).withMaterial(customizedMaterial).build();

            WidthPercentageAlgorithm algorithm = new WidthPercentageAlgorithm();
            Input minInput = Input.valueOf("Minimum Percentage", "From 0 to 1");
            Input maxInput = Input.valueOf("Maximum Percentage", "From 0 to 1");
            Dictionary <Input, string> inputs = new Dictionary <Input, string>();

            inputs.Add(minInput, "0.9");
            inputs.Add(maxInput, "1.0");
            algorithm.setInputValues(inputs);
            Assert.Null(algorithm.apply(custom, component));
        }
        public void ensureApplyRemovesValuesFromDiscreteDimensions()
        {
            Color  color  = Color.valueOf("Epigraph of the Closed Curve: Close Epigraph", 100, 100, 100, 100);
            Finish finish = Finish.valueOf("der alte wurfelt nicht", 20);

            Material                  material    = new Material("#24", "K6205", "12.jpg", new List <Color>(new[] { color }), new List <Finish>(new[] { finish }));
            ProductCategory           cat         = new ProductCategory("AI");
            DiscreteDimensionInterval discrete    = new DiscreteDimensionInterval(new List <double>(new[] { 50.0, 90.0, 100.0, 150.0 }));
            Measurement               measurement = new Measurement(new SingleValueDimension(200), discrete, new SingleValueDimension(50));

            List <Measurement> measurements = new List <Measurement>()
            {
                measurement
            };

            Product component = new Product("#13", "Mother Goose of Diffractive Recitavo: Diffraction Mother Goose", "13.glb", cat, new List <Material>(new[] { material }), measurements);
            Product product   = new Product("#12", "Mother Goose of Mutual Recursion: Recursive Mother Goose ", "12.fbx", cat, new List <Material>(new[] { material }), measurements, new List <Product>()
            {
                component
            });

            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, color, finish);
            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(200, 100, 50);
            CustomizedProduct    custom = CustomizedProductBuilder.createCustomizedProduct("12345", product, customizedDimensions).withMaterial(customizedMaterial).build();

            WidthPercentageAlgorithm algorithm = new WidthPercentageAlgorithm();
            Input minInput = Input.valueOf("Minimum Percentage", "From 0 to 1");
            Input maxInput = Input.valueOf("Maximum Percentage", "From 0 to 1");
            Dictionary <Input, string> inputs = new Dictionary <Input, string>();

            inputs.Add(minInput, "0.9");
            inputs.Add(maxInput, "1.0");
            algorithm.setInputValues(inputs);
            Product alteredProduct = algorithm.apply(custom, component);
            DiscreteDimensionInterval discreteDimension = (DiscreteDimensionInterval)alteredProduct.productMeasurements[0].measurement.width;
            DiscreteDimensionInterval expected          = new DiscreteDimensionInterval(new List <double>(new[] { 90.0, 100.0 }));

            Assert.True(discreteDimension.Equals(expected));
        }
        public void ensureApplyChangesContinuousDimensionsLimits()
        {
            Color                       color        = Color.valueOf("Open the Missing Link", 100, 100, 100, 100);
            Finish                      finish       = Finish.valueOf("der alte wurfelt nicht", 20);
            Material                    material     = new Material("#12", "K6205", "12.png", new List <Color>(new[] { color }), new List <Finish>(new[] { finish }));
            ProductCategory             cat          = new ProductCategory("AI");
            ContinuousDimensionInterval continuous   = new ContinuousDimensionInterval(50.0, 150.0, 20.0);
            Measurement                 measurement  = new Measurement(new SingleValueDimension(200), continuous, new SingleValueDimension(50));
            List <Measurement>          measurements = new List <Measurement>()
            {
                measurement
            };

            Product component = new Product("#19", "Altair of the Cyclic Coordinate: Time-leap Machine", "19.glb", cat, new List <Material>(new[] { material }), measurements);

            Product product = new Product("#18", "Altair of Translational Symmetry: Translational Symmetry", "18.glb", cat, new List <Material>(new[] { material }), measurements,
                                          new List <Product>()
            {
                component
            });

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(200, 100, 50);
            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, color, finish);
            CustomizedProduct    custom = CustomizedProductBuilder.createCustomizedProduct("12345", product, customizedDimensions).withMaterial(customizedMaterial).build();

            WidthPercentageAlgorithm algorithm = new WidthPercentageAlgorithm();
            Input minInput = Input.valueOf("Minimum Percentage", "From 0 to 1");
            Input maxInput = Input.valueOf("Maximum Percentage", "From 0 to 1");
            Dictionary <Input, string> inputs = new Dictionary <Input, string>();

            inputs.Add(minInput, "0.9");
            inputs.Add(maxInput, "1.0");
            algorithm.setInputValues(inputs);
            Product alteredProduct = algorithm.apply(custom, component);

            Assert.True(alteredProduct.productMeasurements[0].measurement.width.getMinValue() == 90);
            Assert.True(alteredProduct.productMeasurements[0].measurement.width.getMaxValue() == 100);
            Assert.True(((ContinuousDimensionInterval)alteredProduct.productMeasurements[0].measurement.width).increment == 10);
        }
        public void ensureApplyFailsIfAlgorithmNotReady()
        {
            Color                       color        = Color.valueOf("Open the Steins Gate", 100, 100, 100, 100);
            Finish                      finish       = Finish.valueOf("der alte wurfelt nicht", 15);
            Material                    material     = new Material("#12", "K6205", "12.jpg", new List <Color>(new[] { color }), new List <Finish>(new[] { finish }));
            ProductCategory             cat          = new ProductCategory("AI");
            ContinuousDimensionInterval continuous1  = new ContinuousDimensionInterval(110.0, 150.0, 2.0);
            ContinuousDimensionInterval continuous2  = new ContinuousDimensionInterval(50.0, 80.0, 2.0);
            Measurement                 measurement1 = new Measurement(continuous1, continuous1, continuous1);
            Measurement                 measurement2 = new Measurement(continuous2, continuous2, continuous2);
            ContinuousDimensionInterval continuous3  = new ContinuousDimensionInterval(35.0, 45.0, 1.0);
            ContinuousDimensionInterval continuous4  = new ContinuousDimensionInterval(10.0, 20.0, 2.0);
            Measurement                 measurement3 = new Measurement(continuous3, continuous3, continuous3);
            Measurement                 measurement4 = new Measurement(continuous4, continuous4, continuous4);
            List <Measurement>          measurements = new List <Measurement>()
            {
                measurement1, measurement2
            };
            List <Measurement> measurements2 = new List <Measurement>()
            {
                measurement3, measurement4
            };

            Product component = new Product("#5", "Solitude of the Astigmatism: Entangled Sheep", "5.glb", cat, new List <Material>(new[] { material }), measurements2);
            Product product   = new Product("#4", "Solitude of the Mournful Flow: A Stray Sheep", "4.gltf", cat, new List <Material>(new[] { material }), measurements, new List <Product>()
            {
                component
            });

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(110, 110, 110);
            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, color, finish);
            CustomizedProduct    custom = CustomizedProductBuilder.createCustomizedProduct("12345", product, customizedDimensions).withMaterial(customizedMaterial).build();

            WidthPercentageAlgorithm algorithm = new WidthPercentageAlgorithm();
            Action action = () => algorithm.apply(custom, component);

            Assert.Throws <ArgumentNullException>(action);
        }
        private CustomizedProduct buildCustomizedProduct()
        {
            Finish finish = Finish.valueOf("Glossy", 90);
            Color  color  = Color.valueOf("Deep Purple", 153, 50, 204, 0);

            Material material = new Material("materialid", "Metal", "ola.jpg", new List <Color>()
            {
                color
            }, new List <Finish>()
            {
                finish
            });

            ProductCategory productCategory = new ProductCategory("Bands");

            Dimension heightDimension = new SingleValueDimension(21.0);
            Dimension depthDimension  = new SingleValueDimension(15.6);
            Dimension widthDimension  = new SingleValueDimension(19);

            Measurement measurement = new Measurement(heightDimension, widthDimension, depthDimension);

            List <Measurement> measurements = new List <Measurement>()
            {
                measurement
            };

            Product product = new Product("productid", "Awesome shelf", "awesomeshelfyo.glb", productCategory, new List <Material>()
            {
                material
            }, measurements);

            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, color);
            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(21.0, 19, 15.6);

            return(CustomizedProductBuilder.createCustomizedProduct("reference", product, customizedDimensions).withMaterial(customizedMaterial).build());
        }
        public void ensureApplyCondensesDiscreteDimensions()
        {
            Color                     color        = Color.valueOf("Silver", 100, 100, 100, 100);
            Finish                    finish       = Finish.valueOf("der alte wurfelt nicht", 20);
            Material                  material     = new Material("#12", "K6205", "12.jpg", new List <Color>(new[] { color }), new List <Finish>(new[] { finish }));
            ProductCategory           cat          = new ProductCategory("AI");
            DiscreteDimensionInterval discrete     = new DiscreteDimensionInterval(new List <double>(new[] { 50.0, 100.0, 150.0 }));
            Measurement               measurement  = new Measurement(new SingleValueDimension(200), discrete, new SingleValueDimension(50));
            List <Measurement>        measurements = new List <Measurement>()
            {
                measurement
            };

            Product component = new Product("#21", "Rinascimento of Image Formation: Return of Phoenix", "21.glb", cat, new List <Material>(new[] { material }), measurements);
            Product product   = new Product("#20", "Rinascimento of the Unwavering Promise: Promised Rinascimento", "20.gltf", cat, new List <Material>(new[] { material }), measurements, new List <Product>()
            {
                component
            });

            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, color, finish);
            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(200, 100, 50);
            CustomizedProduct    custom = CustomizedProductBuilder.createCustomizedProduct("1235", product, customizedDimensions).withMaterial(customizedMaterial).build();

            WidthPercentageAlgorithm algorithm = new WidthPercentageAlgorithm();
            Input minInput = Input.valueOf("Minimum Percentage", "From 0 to 1");
            Input maxInput = Input.valueOf("Maximum Percentage", "From 0 to 1");
            Dictionary <Input, string> inputs = new Dictionary <Input, string>();

            inputs.Add(minInput, "0.9");
            inputs.Add(maxInput, "1.0");
            algorithm.setInputValues(inputs);
            Product alteredProduct = algorithm.apply(custom, component);

            Assert.True(alteredProduct.productMeasurements[0].measurement.width.GetType() == typeof(SingleValueDimension));
            Assert.True(((SingleValueDimension)alteredProduct.productMeasurements[0].measurement.width).value == 100);
        }
        public void ensureApplyCondensesContinuousDimensions()
        {
            Color    color    = Color.valueOf("Open the Steins Gate", 100, 100, 100, 100);
            Finish   finish   = Finish.valueOf("der alte wurfelt nicht", 45);
            Material material = new Material("#12", "K6205", "12.jpg", new List <Color>(new[] { color }), new List <Finish>(new[] { finish }));

            ProductCategory             cat        = new ProductCategory("AI");
            ContinuousDimensionInterval continuous = new ContinuousDimensionInterval(100.0, 150.0, 2.0);
            Measurement        measurement         = new Measurement(new SingleValueDimension(200), continuous, new SingleValueDimension(50));
            List <Measurement> measurements        = new List <Measurement>()
            {
                measurement
            };
            Product component = new Product("#5", "Solitude of the Astigmatism: Entangled Sheep", "5.gltf", cat, new List <Material>(new[] { material }), measurements);
            Product product   = new Product("#4", "Solitude of the Mournful Flow: A Stray Sheep", "4.fbx", cat, new List <Material>(new[] { material }), measurements, new List <Product>()
            {
                component
            });

            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(200, 100, 50);
            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, color, finish);
            CustomizedProduct    custom = CustomizedProductBuilder.createCustomizedProduct("12345", product, customizedDimensions).withMaterial(customizedMaterial).build();

            WidthPercentageAlgorithm algorithm = new WidthPercentageAlgorithm();
            Input minInput = Input.valueOf("Minimum Percentage", "From 0 to 1");
            Input maxInput = Input.valueOf("Maximum Percentage", "From 0 to 1");
            Dictionary <Input, string> inputs = new Dictionary <Input, string>();

            inputs.Add(minInput, "0.9");
            inputs.Add(maxInput, "1.0");
            algorithm.setInputValues(inputs);
            Product alteredProduct = algorithm.apply(custom, component);

            Assert.True(alteredProduct.productMeasurements[0].measurement.width.GetType() == typeof(SingleValueDimension));
            Assert.True(((SingleValueDimension)alteredProduct.productMeasurements[0].measurement.width).value == 100);
        }
        /// <summary>
        /// Builds an instance of CustomizedProduct based on the given Product with the data in the given instance of AddCustomizedProductModelView.
        /// </summary>
        /// <param name="addCustomizedProductModelView">AddCustomizedProductModelView containing the CustomizedProduct's information.</param>
        /// <param name="product">Instance of Product.</param>
        /// <returns>Built instance of CustomizedProduct.</returns>
        /// <exception cref="System.ArgumentException">
        /// Thrown when the Material referenced by the CustomizedMaterial is not found or when no CustomizedDimensions are provided.
        /// </exception>
        /// <returns>A new instance of CustomizedProduct.</returns>
        private static CustomizedProduct buildCustomizedProduct(AddCustomizedProductModelView addCustomizedProductModelView, Product product)
        {
            CustomizedProductBuilder customizedProductBuilder = null;

            if (addCustomizedProductModelView.customizedDimensions == null)
            {
                throw new ArgumentException(ERROR_NO_CUSTOMIZED_DIMENSIONS);
            }

            CustomizedDimensions customizedProductDimensions = CustomizedDimensionsModelViewService.fromModelView(addCustomizedProductModelView.customizedDimensions);

            if (addCustomizedProductModelView.userAuthToken == null)
            {
                customizedProductBuilder = CustomizedProductBuilder.createCustomizedProduct(addCustomizedProductModelView.reference, product, customizedProductDimensions);
            }
            else
            {
                customizedProductBuilder = CustomizedProductBuilder
                                           .createCustomizedProduct(addCustomizedProductModelView.userAuthToken, addCustomizedProductModelView.reference, product, customizedProductDimensions);
            }

            //build customized product with optional properties if they're defined
            if (addCustomizedProductModelView.customizedMaterial != null)
            {
                CustomizedMaterial customizedMaterial = CreateCustomizedMaterialService.create(addCustomizedProductModelView.customizedMaterial);

                customizedProductBuilder.withMaterial(customizedMaterial);
            }

            if (addCustomizedProductModelView.designation != null)
            {
                customizedProductBuilder.withDesignation(addCustomizedProductModelView.designation);
            }

            return(customizedProductBuilder.build());
        }
        /// <summary>
        /// Transforms a customized product dto into a customized product via service
        /// </summary>
        /// <param name="customizedProductDTO">CustomizedProductDTO with the customized product dto being transformed</param>
        /// <returns>CustomizedProduct with the of customized products transformed from the dto</returns>
        public static CustomizedProduct transform(CustomizedProductDTO customizedProductDTO)
        {
            CustomizedProduct customizedProduct = null;

            string reference   = customizedProductDTO.reference;
            string designation = customizedProductDTO.designation;

            //Fetch the product associated to this customized product by its id
            long    productId = customizedProductDTO.productDTO.id;
            Product product   = PersistenceContext.repositories().createProductRepository().find(productId);

            //Fetch the material associated to the customized material
            long     materialId = customizedProductDTO.customizedMaterialDTO.material.id;
            Material material   = PersistenceContext.repositories().createMaterialRepository().find(materialId);

            Finish customizedFinish = customizedProductDTO.customizedMaterialDTO.finish.toEntity();
            Color  customizedColor  = customizedProductDTO.customizedMaterialDTO.color.toEntity();

            CustomizedDimensions customizedDimensions = customizedProductDTO.customizedDimensionsDTO.toEntity();
            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, customizedColor, customizedFinish);

            //check if the dto contains slot information

            /* if (customizedProductDTO.slotListDTO == null)
             * {
             *  customizedProduct = new CustomizedProduct(reference, designation, customizedMaterial, customizedDimensions, product);
             * }
             * else
             * {
             *  //if the dto contains slot info, then create one with slots
             *  List<Slot> slots = new SlotDTOService().transform(customizedProductDTO.slotListDTO).ToList();
             *  customizedProduct = new CustomizedProduct(reference, designation, customizedMaterial, customizedDimensions, product, slots);
             * } */

            return(customizedProduct);
        }
Esempio n. 26
0
        public void ensureApplyReturnsNullIfComponentDoesNotHaveRequiredFinish()
        {
            Console.WriteLine("ensureApplyReturnsNullIfComponentDoesNotHaveRequiredFinish");
            Color                     color         = Color.valueOf("Epigraph of the Closed Curve: Close Epigraph", 100, 100, 100, 100);
            Finish                    finish        = Finish.valueOf("der alte wurfelt nicht", 12);
            Material                  material      = new Material("#24", "K6205", "ola.jpg", new List <Color>(new[] { color }), new List <Finish>(new[] { finish, Finish.valueOf("schrödinger's box", 12) }));
            Material                  otherMaterial = new Material("#24", "K6205", "ola.jpg", new List <Color>(new[] { color }), new List <Finish>(new[] { Finish.valueOf("schrödinger's box", 12) }));
            ProductCategory           cat           = new ProductCategory("AI");
            DiscreteDimensionInterval discrete      = new DiscreteDimensionInterval(new List <double>(new[] { 50.0, 90.0, 100.0, 150.0 }));
            Measurement               measurement   = new Measurement(discrete, discrete, discrete);
            List <Measurement>        measurements  = new List <Measurement>()
            {
                measurement
            };
            Product           product   = new Product("#12", "Mother Goose of Mutual Recursion: Recursive Mother Goose", "product12.glb", cat, new List <Material>(new[] { material }), measurements);
            Product           component = new Product("#13", "Mother Goose of Diffractive Recitavo: Diffraction Mother Goose", "product13.gltf", cat, new List <Material>(new[] { otherMaterial }), measurements);
            CustomizedProduct custom    = CustomizedProductBuilder.createCustomizedProduct("#8", product, CustomizedDimensions.valueOf(100, 100, 100)).withMaterial(CustomizedMaterial.valueOf(material, Color.valueOf("Epigraph of the Closed Curve: Close Epigraph", 100, 100, 100, 100), Finish.valueOf("der alte wurfelt nicht", 12))).build();
            Algorithm         algorithm = new AlgorithmFactory().createAlgorithm(RestrictionAlgorithm.SAME_MATERIAL_AND_FINISH_ALGORITHM);

            Assert.Null(algorithm.apply(custom, component));
        }
Esempio n. 27
0
        public void ensureApplyRemovesUnnecessaryMaterials()
        {
            Console.WriteLine("ensureApplyRemovesUnnecessaryMaterials");
            Material                  material     = new Material("#24", "K6205", "ola.jpg", new List <Color>(new[] { Color.valueOf("Epigraph of the Closed Curve: Close Epigraph", 100, 100, 100, 100) }), new List <Finish>(new[] { Finish.valueOf("der alte wurfelt nicht", 12) }));
            Material                  material1    = new Material("#22", "Amadeus", "ola.jpg", new List <Color>(new[] { Color.valueOf("Epigraph of the Closed Curve: Close Epigraph", 100, 100, 100, 100) }), new List <Finish>(new[] { Finish.valueOf("der alte wurfelt nicht", 12) }));
            ProductCategory           cat          = new ProductCategory("AI");
            DiscreteDimensionInterval discrete     = new DiscreteDimensionInterval(new List <double>(new[] { 50.0, 90.0, 100.0, 150.0 }));
            Measurement               measurement  = new Measurement(discrete, discrete, discrete);
            List <Measurement>        measurements = new List <Measurement>()
            {
                measurement
            };
            Product           product   = new Product("#12", "Mother Goose of Mutual Recursion: Recursive Mother Goose", "product12.glb", cat, new List <Material>(new[] { material }), measurements);
            Product           component = new Product("#13", "Mother Goose of Diffractive Recitavo: Diffraction Mother Goose", "product13.gltf", cat, new List <Material>(new[] { material1, material }), measurements);
            CustomizedProduct custom    = CustomizedProductBuilder.createCustomizedProduct("#8", product, CustomizedDimensions.valueOf(100, 100, 100)).withMaterial(CustomizedMaterial.valueOf(material, Color.valueOf("Epigraph of the Closed Curve: Close Epigraph", 100, 100, 100, 100), Finish.valueOf("der alte wurfelt nicht", 12))).build();
            Algorithm         algorithm = new AlgorithmFactory().createAlgorithm(RestrictionAlgorithm.SAME_MATERIAL_AND_FINISH_ALGORITHM);

            Assert.True(algorithm.apply(custom, component).productMaterials[0].material.Equals(material));
        }
Esempio n. 28
0
 private CustomizedDimensions buildCustomizedDimensions()
 {
     return(CustomizedDimensions.valueOf(76, 80, 25));
 }
 /// <summary>
 /// Converts an instance of CustomizedDimensions into an instance of GetCustomizedModelView.
 /// </summary>
 /// <param name="customizedDimensions">Instance of CustomizedDimensions.</param>
 /// <returns>The created instance of GetCustomizedDimensionsModelView.</returns>
 /// <exception cref="System.ArgumentException">Thrown when the provided CustomizedDimensions is null.</exception>
 public static GetCustomizedDimensionsModelView fromEntity(CustomizedDimensions customizedDimensions)
 {
     return(fromEntity(customizedDimensions, MeasurementUnitService.getMinimumUnit()));
 }
Esempio n. 30
0
        public void ensureApplyAllRestrictionsReturnsRestrictedProduct()
        {
            ProductCategory cat = new ProductCategory("All Products");

            Color        black  = Color.valueOf("Deep Black", 0, 0, 0, 0);
            Color        white  = Color.valueOf("Blinding White", 255, 255, 255, 0);
            List <Color> colors = new List <Color>()
            {
                black, white
            };

            Finish        glossy   = Finish.valueOf("Glossy", 100);
            Finish        matte    = Finish.valueOf("Matte", 0);
            List <Finish> finishes = new List <Finish>()
            {
                glossy, matte
            };

            Material material  = new Material("#001", "Really Expensive Wood", "ola.jpg", colors, finishes);
            Material material2 = new Material("#002", "Expensive Wood", "ola.jpg", colors, finishes);

            Dimension heightDimension = new SingleValueDimension(50);
            Dimension widthDimension  = new DiscreteDimensionInterval(new List <double>()
            {
                60, 65, 70, 80, 90, 105
            });
            Dimension depthDimension = new ContinuousDimensionInterval(10, 25, 5);

            Measurement measurement = new Measurement(heightDimension, widthDimension, depthDimension);

            Product product = new Product("Test", "Shelf", "shelf.glb", cat, new List <Material>()
            {
                material, material2
            }, new List <Measurement>()
            {
                measurement
            }, ProductSlotWidths.valueOf(4, 4, 4));
            Product product2 = new Product("Test", "Shelf", "shelf.glb", cat, new List <Material>()
            {
                material, material2
            }, new List <Measurement>()
            {
                measurement
            }, ProductSlotWidths.valueOf(4, 4, 4));

            CustomizedDimensions customDimension   = CustomizedDimensions.valueOf(50, 80, 25);
            CustomizedMaterial   customMaterial    = CustomizedMaterial.valueOf(material, white, matte);
            CustomizedProduct    customizedProduct = CustomizedProductBuilder.createCustomizedProduct("reference", product, customDimension).build();

            customizedProduct.changeCustomizedMaterial(customMaterial);

            customizedProduct.finalizeCustomization();
            RestrictableImpl instance = new RestrictableImpl();

            instance.addRestriction(new Restriction("same material", new SameMaterialAndFinishAlgorithm()));

            WidthPercentageAlgorithm algorithm = new WidthPercentageAlgorithm();
            Input minInput = Input.valueOf("Minimum Percentage", "From 0 to 1");
            Input maxInput = Input.valueOf("Maximum Percentage", "From 0 to 1");
            Dictionary <Input, string> inputs = new Dictionary <Input, string>();

            inputs.Add(minInput, "0.8");
            inputs.Add(maxInput, "1.0");
            algorithm.setInputValues(inputs);
            instance.addRestriction(new Restriction("width percentage", algorithm));

            Product returned = instance.applyAllRestrictions(customizedProduct, product2);

            Assert.True(returned.productMaterials.Count == 1);
            Assert.True(returned.productMaterials[0].material.Equals(material));
            Assert.True(returned.productMeasurements[0].measurement.width.getMinValue() == 65);
            Assert.True(returned.productMeasurements[0].measurement.width.getMaxValue() == 80);
        }