Beispiel #1
0
        public void ensureCatalogueCollectionCanBeCreatedIfAllCustomizedProductsWereAddedToCustomizedProductCollection()
        {
            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("Closets Spring 2019");

            CustomizedProduct customizedProduct1 = buildCustomizedProduct("1234");

            customizedProduct1.finalizeCustomization();     //!customized products added to collections need to be finished

            customizedProductCollection.addCustomizedProduct(customizedProduct1);

            CustomizedProduct customizedProduct2 = buildCustomizedProduct("1235");

            customizedProduct2.finalizeCustomization();     //!customized products added to collections need to be finished

            customizedProductCollection.addCustomizedProduct(customizedProduct2);

            List <CustomizedProduct> customizedProducts = new List <CustomizedProduct>()
            {
                customizedProduct1, customizedProduct2
            };

            CatalogueCollection catalogueCollection = new CatalogueCollection(customizedProductCollection, customizedProducts);

            Assert.NotNull(catalogueCollection);
        }
Beispiel #2
0
        public void ensureNotEqualCustomizedProductCollectionsAreNotEqual()
        {
            var category = new ProductCategory("It's-a-me again");

            //Creating Dimensions
            Dimension heightDimension = new SingleValueDimension(21);
            Dimension widthDimension  = new SingleValueDimension(30);
            Dimension depthDimension  = new SingleValueDimension(17);

            Measurement        measurement  = new Measurement(heightDimension, widthDimension, depthDimension);
            List <Measurement> measurements = new List <Measurement>()
            {
                measurement
            };

            //Creating a material
            string reference   = "Just referencing";
            string designation = "Doin' my thing";

            List <Color> colors = new List <Color>();
            Color        color  = Color.valueOf("Goin' to church", 1, 2, 3, 0);
            Color        color1 = Color.valueOf("Burro quando foge", 1, 2, 3, 4);

            colors.Add(color);
            colors.Add(color1);

            List <Finish> finishes = new List <Finish>();
            Finish        finish   = Finish.valueOf("Prayin'", 3);
            Finish        finish2  = Finish.valueOf("Estragado", 9);

            finishes.Add(finish);
            finishes.Add(finish2);

            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("Kinda dead", "So tired", "riperino.gltf", category, matsList, measurements);
            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(21, 30, 17);

            //Customized Material
            CustomizedMaterial mat = CustomizedMaterial.valueOf(material, color1, finish2);


            CustomizedProduct cp = CustomizedProductBuilder
                                   .createCustomizedProduct("reference", product, customizedDimensions)
                                   .withMaterial(mat).build();

            cp.finalizeCustomization();
            List <CustomizedProduct> products = new List <CustomizedProduct>();

            products.Add(cp);

            Assert.NotEqual(new CustomizedProductCollection("Mario", products), new CustomizedProductCollection("Luigi", products));
        }
Beispiel #3
0
        public void ensureApplyAllRestrictionsReturnsNullIfProductDoesNotObeyRestrictions()
        {
            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
            }, new List <Measurement>()
            {
                measurement
            }, ProductSlotWidths.valueOf(4, 4, 4));

            CustomizedDimensions customDimension   = CustomizedDimensions.valueOf(50, 80, 25);
            CustomizedMaterial   customMaterial    = CustomizedMaterial.valueOf(material2, 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()));
            Assert.Null(instance.applyAllRestrictions(customizedProduct, product2));
        }
Beispiel #4
0
        private CustomizedProduct buildFinishedCustomizedProductInstance()
        {
            string reference = "123";

            CustomizedMaterial customizedMaterial = buildCustomizedMaterial();

            CustomizedDimensions selectedDimensions = buildCustomizedDimensions();

            CustomizedProduct customizedProduct = CustomizedProductBuilder.createCustomizedProduct(reference, buildValidProduct(), selectedDimensions).build();

            customizedProduct.changeCustomizedMaterial(customizedMaterial);

            customizedProduct.finalizeCustomization();

            return(customizedProduct);
        }
Beispiel #5
0
        public void ensureAddingValidCustomizedProductAddsCustomizedProduct()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProductCollection customizedProductCollection = catalogueCollection.customizedProductCollection;

            CustomizedProduct customizedProduct = buildCustomizedProduct("123545");

            customizedProduct.finalizeCustomization();

            customizedProductCollection.addCustomizedProduct(customizedProduct);

            catalogueCollection.addCustomizedProduct(customizedProduct);

            Assert.Equal(3, catalogueCollection.catalogueCollectionProducts.Count);
            Assert.True(catalogueCollection.hasCustomizedProduct(customizedProduct));
        }
Beispiel #6
0
        private CustomizedProductCollection buildCustomizedProductCollection()
        {
            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("Closets Spring 2019");

            CustomizedProduct customizedProduct1 = buildCustomizedProduct("1234");

            customizedProduct1.finalizeCustomization();     //!customized products added to collections need to be finished

            customizedProductCollection.addCustomizedProduct(customizedProduct1);

            CustomizedProduct customizedProduct2 = buildCustomizedProduct("1235");

            customizedProduct2.finalizeCustomization();     //!customized products added to collections need to be finished

            customizedProductCollection.addCustomizedProduct(customizedProduct2);

            return(customizedProductCollection);
        }
Beispiel #7
0
        public void ensureAddingValidCustomizedProductDoesNotThrowException()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProductCollection customizedProductCollection = catalogueCollection.customizedProductCollection;

            CustomizedProduct customizedProduct = buildCustomizedProduct("123545");

            customizedProduct.finalizeCustomization();

            customizedProductCollection.addCustomizedProduct(customizedProduct);

            Action addValidCustomizedProduct = () => catalogueCollection.addCustomizedProduct(customizedProduct);

            Exception exception = Record.Exception(addValidCustomizedProduct);

            Assert.Null(exception);
        }
Beispiel #8
0
        public void ensureCreatingCatalogueCollectionWithCustomizedProductCollectionAddsAllCustomizedProducts()
        {
            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("Closets Spring 2019");

            CustomizedProduct customizedProduct1 = buildCustomizedProduct("1234");

            customizedProduct1.finalizeCustomization();     //!customized products added to collections need to be finished

            customizedProductCollection.addCustomizedProduct(customizedProduct1);

            CustomizedProduct customizedProduct2 = buildCustomizedProduct("1235");

            customizedProduct2.finalizeCustomization();     //!customized products added to collections need to be finished

            customizedProductCollection.addCustomizedProduct(customizedProduct2);

            CatalogueCollection catalogueCollection = new CatalogueCollection(customizedProductCollection);

            Assert.True(catalogueCollection.hasCustomizedProduct(customizedProduct1));
            Assert.True(catalogueCollection.hasCustomizedProduct(customizedProduct2));
        }
Beispiel #9
0
        public void ensureCatalogueCollectionCantBeCreatedWithDuplicateCustomizedProductsInCustomizedProductEnumerable()
        {
            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("Closets Spring 2019");

            CustomizedProduct customizedProduct1 = buildCustomizedProduct("1234");

            customizedProduct1.finalizeCustomization();     //!customized products added to collections need to be finished

            customizedProductCollection.addCustomizedProduct(customizedProduct1);

            CustomizedProduct customizedProduct2 = buildCustomizedProduct("1235");

            List <CustomizedProduct> customizedProducts = new List <CustomizedProduct>()
            {
                customizedProduct1, customizedProduct2, customizedProduct1
            };

            Action createCatalogueCollection = () => new CatalogueCollection(customizedProductCollection, customizedProducts);

            Assert.Throws <ArgumentException>(createCatalogueCollection);
        }
Beispiel #10
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);
        }
Beispiel #11
0
        public void ensureObjectIsNotCreatedForNullCatalogueCollection()
        {
            Color        color  = Color.valueOf("Somebody", 1, 2, 3, 4);
            List <Color> colors = new List <Color>();

            colors.Add(color);

            Finish        finish   = Finish.valueOf("once", 1);
            List <Finish> finishes = new List <Finish>();

            finishes.Add(finish);

            List <Double> values = new List <Double>();

            values.Add(500.0);

            Material        material     = new Material("told", "me", "ola.jpg", colors, finishes);
            List <Material> materialList = new List <Material>();

            materialList.Add(material);

            ProductCategory productCategory = new ProductCategory("the");

            Dimension heightDimension = new SingleValueDimension(21);
            Dimension widthDimension  = new SingleValueDimension(30);
            Dimension depthDimension  = new SingleValueDimension(17);

            Measurement        measurement  = new Measurement(heightDimension, widthDimension, depthDimension);
            List <Measurement> measurements = new List <Measurement>()
            {
                measurement
            };

            IEnumerable <Material> materialEnumerable = materialList;

            Product product = new Product("world", "is", "world.glb", productCategory, materialEnumerable,
                                          measurements);

            CustomizedMaterial   customizedMaterial   = CustomizedMaterial.valueOf(material, color, finish);
            CustomizedDimensions customizedDimensions = CustomizedDimensions.valueOf(21, 30, 17);
            CustomizedProduct    customizedProduct    = CustomizedProductBuilder
                                                        .createCustomizedProduct("reference", product, customizedDimensions)
                                                        .withMaterial(customizedMaterial).build();

            customizedProduct.finalizeCustomization();

            List <CustomizedProduct> customizedProductList = new List <CustomizedProduct>();

            customizedProductList.Add(customizedProduct);

            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("me",
                                                                                                      customizedProductList);
            List <CustomizedProductCollection> collectionList = new List <CustomizedProductCollection>();

            collectionList.Add(customizedProductCollection);

            CatalogueCollection catalogueCollection = new CatalogueCollection(customizedProductCollection,
                                                                              customizedProductList);
            List <CatalogueCollection> catalogueCollectionList = new List <CatalogueCollection>();

            catalogueCollectionList.Add(catalogueCollection);

            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("I", "ain't", catalogueCollectionList);

            Assert.Throws <ArgumentException>(() => new CommercialCatalogueCatalogueCollection(commercialCatalogue,
                                                                                               null));
        }
        /// <summary>
        /// Updates an instance of CustomizedProduct with the data provided in the given UpdateCustomizedProductModelView.
        /// </summary>
        /// <param name="updateCustomizedProductModelView">Instance of UpdateCustomizedProductModelView containing updated CustomizedProduct information.</param>
        /// <returns>An instance of GetCustomizedProductModelView with the updated CustomizedProduct information.</returns>
        /// <exception cref="ResourceNotFoundException">Thrown when the CustomizedProduct could not be found.</exception>
        /// <exception cref="System.ArgumentException">Thrown when none of the CustomizedProduct's properties are updated.</exception>
        public GetCustomizedProductModelView updateCustomizedProduct(UpdateCustomizedProductModelView updateCustomizedProductModelView)
        {
            CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository();

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

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

            checkUserToken(customizedProduct, updateCustomizedProductModelView.userAuthToken);

            bool performedAtLeastOneUpdate = false;

            if (updateCustomizedProductModelView.reference != null)
            {
                customizedProduct.changeReference(updateCustomizedProductModelView.reference);
                performedAtLeastOneUpdate = true;
            }

            if (updateCustomizedProductModelView.designation != null)
            {
                customizedProduct.changeDesignation(updateCustomizedProductModelView.designation);
                performedAtLeastOneUpdate = true;
            }

            if (updateCustomizedProductModelView.customizedMaterial != null)
            {
                //TODO: check if only the finish or the color are being updated
                CustomizedMaterial customizedMaterial = CreateCustomizedMaterialService.create(updateCustomizedProductModelView.customizedMaterial);

                customizedProduct.changeCustomizedMaterial(customizedMaterial);
                performedAtLeastOneUpdate = true;
            }

            if (updateCustomizedProductModelView.customizedDimensions != null)
            {
                customizedProduct.changeDimensions(CustomizedDimensionsModelViewService.fromModelView(updateCustomizedProductModelView.customizedDimensions));
                performedAtLeastOneUpdate = true;
            }

            if (updateCustomizedProductModelView.customizationStatus == CustomizationStatus.FINISHED)
            {
                customizedProduct.finalizeCustomization();
                performedAtLeastOneUpdate = true;
            }

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

            customizedProduct = customizedProductRepository.update(customizedProduct);

            if (customizedProduct == null)
            {
                throw new ArgumentException(ERROR_UNABLE_TO_SAVE_CUSTOMIZED_PRODUCT);
            }

            return(CustomizedProductModelViewService.fromEntity(customizedProduct));
        }