public static GetCustomizedProductCollectionModelView fromEntity(CustomizedProductCollection customizedProductCollection)
        {
            if (customizedProductCollection == null)
            {
                throw new ArgumentNullException(INVALID_CUSTOMIZED_PRODUCT_COLLECTION);
            }

            GetCustomizedProductCollectionModelView customizedProductCollectionModelView = new GetCustomizedProductCollectionModelView();

            customizedProductCollectionModelView.id   = customizedProductCollection.Id;
            customizedProductCollectionModelView.name = customizedProductCollection.name;

            if (!Collections.isEnumerableNullOrEmpty(customizedProductCollection.collectionProducts))
            {
                customizedProductCollectionModelView.customizedProducts = new List <GetBasicCustomizedProductModelView>();

                foreach (CollectionProduct collectionProduct in customizedProductCollection.collectionProducts)
                {
                    GetBasicCustomizedProductModelView basicCustomizedProductModelView =
                        CustomizedProductModelViewService.fromEntityAsBasic(collectionProduct.customizedProduct);

                    customizedProductCollectionModelView.customizedProducts.Add(basicCustomizedProductModelView);
                }
            }

            return(customizedProductCollectionModelView);
        }
コード例 #2
0
        /// <summary>
        /// Updates a customized product collection's basic information
        /// </summary>
        /// <param name="modelView">model view with the updates for a customized product collection</param>
        /// <returns>Updated customized product collection or throws an exception if an error occurs</returns>
        public static CustomizedProductCollection update(UpdateCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollectionRepository customizedProductCollectionRepository =
                PersistenceContext.repositories()
                .createCustomizedProductCollectionRepository();


            CustomizedProductCollection customizedProductCollection =
                customizedProductCollectionRepository.find(modelView.customizedProductCollectionId);

            checkIfCustomizedProductCollectionWasFound(
                customizedProductCollection, modelView.customizedProductCollectionId
                );

            customizedProductCollection.changeName(modelView.name);

            CustomizedProductCollection updatedCustomizedProductCollection =
                customizedProductCollectionRepository.update(customizedProductCollection);

            checkIfUpdatedCustomizedProductCollectionWasSaved(
                updatedCustomizedProductCollection, modelView.customizedProductCollectionId
                );

            return(updatedCustomizedProductCollection);
        }
コード例 #3
0
        /// <summary>
        /// Deletes a customized product from a customized product collection
        /// </summary>
        /// <param name="modelView"> model view with the necessary information to perform the request</param>
        public static void delete(DeleteCustomizedProductFromCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollectionRepository customizedProductCollectionRepository =
                PersistenceContext.repositories()
                .createCustomizedProductCollectionRepository();

            CustomizedProductCollection customizedProductCollection =
                customizedProductCollectionRepository.find(modelView.customizedProductCollectionId);

            checkIfCustomizedProductCollectionWasFound(customizedProductCollection, modelView.customizedProductCollectionId);

            CustomizedProduct customizedProduct =
                PersistenceContext.repositories()
                .createCustomizedProductRepository()
                .find(modelView.customizedProductId);

            if (customizedProduct == null)
            {
                throw new ArgumentException(
                          string.Format(
                              UNABLE_TO_FIND_CUSTOMIZED_PRODUCT,
                              modelView.customizedProductId)
                          );
            }

            customizedProductCollection.removeCustomizedProduct(customizedProduct);

            customizedProductCollectionRepository.update(customizedProductCollection);
        }
        public void ensureFromCollectionReturnsModelViewIfCollectionIsValid()
        {
            CustomizedProductCollection customizedProductCollection =
                createCustomizedProductCollection();

            CustomizedProductCollection otherCustomizedProductCollection =
                createCustomizedProductCollection();

            GetAllCustomizedProductCollectionsModelView expectedModelView =
                new GetAllCustomizedProductCollectionsModelView();

            expectedModelView =
                new GetAllCustomizedProductCollectionsModelView()
            {
                CustomizedProductCollectionModelViewService.fromEntityAsBasic(customizedProductCollection),
                CustomizedProductCollectionModelViewService.fromEntityAsBasic(otherCustomizedProductCollection)
            };

            List <CustomizedProductCollection> collection =
                new List <CustomizedProductCollection>()
            {
                customizedProductCollection, otherCustomizedProductCollection
            };

            GetAllCustomizedProductCollectionsModelView actualModelView =
                CustomizedProductCollectionModelViewService.fromCollection(collection);

            assertBasicModelView(expectedModelView[0], actualModelView[0]);
            assertBasicModelView(expectedModelView[1], actualModelView[1]);
        }
        public void ensureFromEntityReturnsModelViewIfEntityIsValid()
        {
            CustomizedProductCollection customizedProductCollection =
                createCustomizedProductCollection();

            GetCustomizedProductCollectionModelView expectedModelView =
                new GetCustomizedProductCollectionModelView();

            expectedModelView.name = customizedProductCollection.name;
            expectedModelView.customizedProducts = new List <GetBasicCustomizedProductModelView>();
            expectedModelView.customizedProducts.Add(new GetBasicCustomizedProductModelView());
            expectedModelView.customizedProducts[0].designation =
                customizedProductCollection.collectionProducts[0].customizedProduct.designation;
            expectedModelView.customizedProducts[0].reference =
                customizedProductCollection.collectionProducts[0].customizedProduct.reference;
            expectedModelView.customizedProducts[0].productId =
                customizedProductCollection.collectionProducts[0].customizedProduct.product.Id;

            GetCustomizedProductCollectionModelView actualModelView =
                CustomizedProductCollectionModelViewService.fromEntity(customizedProductCollection);

            Assert.Equal(expectedModelView.name, actualModelView.name);
            Assert.Equal(expectedModelView.customizedProducts[0].designation,
                         actualModelView.customizedProducts[0].designation);
            Assert.Equal(expectedModelView.customizedProducts[0].reference,
                         actualModelView.customizedProducts[0].reference);
            Assert.Equal(expectedModelView.customizedProducts[0].productId,
                         actualModelView.customizedProducts[0].productId);
        }
コード例 #6
0
        public void ensureNameCantBeChangedToEmptyString()
        {
            CustomizedProductCollection instance =
                new CustomizedProductCollection("Shroom");

            Assert.Throws <ArgumentException>(() => instance.changeName(""));
        }
コード例 #7
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);
        }
コード例 #8
0
        public void ensureNameCantBeChangedToNull()
        {
            CustomizedProductCollection instance =
                new CustomizedProductCollection("Peach");

            Assert.Throws <ArgumentException>(() => instance.changeName(null));
        }
コード例 #9
0
        public void ensureCatalogueCollectionCanBeCreatedIfCustomizedProductCollectionIsNotNull()
        {
            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("Closets Spring 2019");

            CatalogueCollection catalogueCollection = new CatalogueCollection(customizedProductCollection);

            Assert.NotNull(catalogueCollection);
        }
コード例 #10
0
        public void ensureCatalogueCollectionCantBeCreatedWithNullCustomizedProducts()
        {
            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("Closets Spring 2019");

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

            Assert.Throws <ArgumentException>(createCatalogueCollection);
        }
コード例 #11
0
        public void ensureDisabledCustomizedProductCollectionCantBeDisabled()
        {
            CustomizedProductCollection collection = new CustomizedProductCollection("Mario");

            collection.deactivate();

            Assert.False(collection.deactivate());
        }
コード例 #12
0
        public void ensureHasCustomizedProductReturnsFalseIfCustomizedProductWasNotAdded()
        {
            CustomizedProductCollection collection = new CustomizedProductCollection("Collection");

            CustomizedProduct customizedProduct = buildFinishedCustomizedProductInstance();

            Assert.False(collection.hasCustomizedProduct(customizedProduct));
        }
コード例 #13
0
        public void ensureInstancesHaveDifferentHashCode()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("Some other collection");
            CatalogueCollection         otherCatalogueCollection    = new CatalogueCollection(customizedProductCollection);

            Assert.NotEqual(catalogueCollection.GetHashCode(), otherCatalogueCollection.GetHashCode());
        }
コード例 #14
0
        public void ensureCatalogueCollectionWithDifferentCustomizedProductCollectionIsNotEqual()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("Some other collection");
            CatalogueCollection         otherCatalogueCollection    = new CatalogueCollection(customizedProductCollection);

            Assert.False(catalogueCollection.Equals(otherCatalogueCollection));
        }
コード例 #15
0
        public void ensureAddingPendingCustomizedProductThrowsException()
        {
            Product product = buildValidProduct();

            CustomizedProductCollection instance = new CustomizedProductCollection("Mario");

            Assert.Throws <ArgumentException>(() => instance.addCustomizedProduct(
                                                  buildUnfinishedCustomizedProductInstance()
                                                  ));
        }
コード例 #16
0
        public void ensureAddCustomizedProductWorksForValidProduct()
        {
            CustomizedProduct           customizedProduct = buildFinishedCustomizedProductInstance();
            CustomizedProductCollection instance          = new CustomizedProductCollection("Mario");

            instance.addCustomizedProduct(customizedProduct);

            Assert.NotEmpty(instance.collectionProducts);
            Assert.Equal(customizedProduct, instance.collectionProducts[0].customizedProduct);
        }
コード例 #17
0
        public void ensureAddCustomizedProductFailsIfItAlreadyExists()
        {
            CustomizedProduct        customizedProduct = buildFinishedCustomizedProductInstance();
            List <CustomizedProduct> list = new List <CustomizedProduct>();

            list.Add(customizedProduct);

            CustomizedProductCollection instance = new CustomizedProductCollection("Mario", list);

            Assert.Throws <ArgumentException>(() => instance.addCustomizedProduct(customizedProduct));
        }
コード例 #18
0
        public void ensureNameCanBeChangedToValidNewName()
        {
            var oldName = "Luigi";
            var newName = "Mario";
            CustomizedProductCollection instance =
                new CustomizedProductCollection(oldName);

            instance.changeName(newName);

            Assert.NotEqual(oldName, instance.name);
        }
コード例 #19
0
        /// <summary>
        /// Fetches a customized product collection by its entity identifier
        /// </summary>
        /// <param name="modelView">CustomizedProductCollectionDTO with the customized product collection information</param>
        /// <returns>CustomizedProductCollectionDTO with the fetched customized product collection information</returns>
        public GetCustomizedProductCollectionModelView findCollectionByEID(GetCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollection collection = PersistenceContext.repositories().createCustomizedProductCollectionRepository().find(modelView.name);

            if (collection == null)
            {
                throw new ResourceNotFoundException(string.Format(UNABLE_TO_FIND_COLLECTION_BY_NAME, modelView.name));
            }

            return(CustomizedProductCollectionModelViewService.fromEntity(collection));
        }
コード例 #20
0
 /// <summary>
 /// Checks if a customized product collection was found
 /// </summary>
 /// <param name="customizedProductCollection">Customized Product Collection to be checked</param>
 /// <param name="customizedProductCollectionId">PID of the requested customized product collection</param>
 private static void checkIfCustomizedProductCollectionWasFound(CustomizedProductCollection customizedProductCollection, long customizedProductCollectionId)
 {
     if (customizedProductCollection == null)
     {
         throw new ResourceNotFoundException(
                   string.Format(
                       UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_COLLECTION,
                       customizedProductCollectionId)
                   );
     }
 }
コード例 #21
0
 /// <summary>
 /// Checks if a customized product collection was updated successfully
 /// </summary>
 /// <param name="updatedCustomizedProductCollection">Updated Customized Product Collection to be checked</param>
 /// <param name="customizedProductCollectionId">PID of the updated customized product collection</param>
 private static void checkIfUpdatedCustomizedProductCollectionWasSaved(CustomizedProductCollection updatedCustomizedProductCollection, long customizedProductCollectionId)
 {
     if (updatedCustomizedProductCollection == null)
     {
         throw new ArgumentException(
                   string.Format(
                       UNABLE_TO_UPDATE_CUSTOMIZED_PRODUCT_COLLECTION,
                       customizedProductCollectionId)
                   );
     }
 }
        private CustomizedProductCollection createCustomizedProductCollection()
        {
            CustomizedProductCollection customizedProductCollection =
                new CustomizedProductCollection("hello");

            CustomizedProduct customizedProduct =
                buildCustomizedProductInstance();

            customizedProductCollection.addCustomizedProduct(customizedProduct);

            return(customizedProductCollection);
        }
コード例 #23
0
        /// <summary>
        /// Deactivates a customized product collection
        /// </summary>
        /// <param name="modelView"> model view with the necessary information to deactivate a customized product collection</param>
        public static void deactivate(DeleteCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollectionRepository customizedProductCollectionRepository =
                PersistenceContext.repositories()
                .createCustomizedProductCollectionRepository();

            CustomizedProductCollection customizedProductCollection =
                customizedProductCollectionRepository.find(modelView.customizedProductCollectionId);

            checkIfCustomizedProductCollectionWasFound(customizedProductCollection, modelView.customizedProductCollectionId);

            customizedProductCollectionRepository.remove(customizedProductCollection);
        }
コード例 #24
0
        public void ensureRemovedCustomizedProductWorksForExistingProduct()
        {
            CustomizedProduct        cp   = buildFinishedCustomizedProductInstance();
            List <CustomizedProduct> list = new List <CustomizedProduct>();

            list.Add(cp);

            CustomizedProductCollection instance = new CustomizedProductCollection("Mario", list);

            instance.removeCustomizedProduct(cp);

            Assert.Empty(instance.collectionProducts);
        }
        public static GetBasicCustomizedProductCollectionModelView fromEntityAsBasic(CustomizedProductCollection customizedProductCollection)
        {
            if (customizedProductCollection == null)
            {
                throw new ArgumentNullException(INVALID_CUSTOMIZED_PRODUCT_COLLECTION);
            }

            GetBasicCustomizedProductCollectionModelView basicModelView = new GetBasicCustomizedProductCollectionModelView();

            basicModelView.id   = customizedProductCollection.Id;
            basicModelView.name = customizedProductCollection.name;
            basicModelView.hasCustomizedProducts = customizedProductCollection.collectionProducts.Count != 0;

            return(basicModelView);
        }
        public void ensureFromEntityAsBasicReturnsBasicModelViewIfEntityIsValid()
        {
            CustomizedProductCollection customizedProductCollection =
                createCustomizedProductCollection();

            GetBasicCustomizedProductCollectionModelView expectedModelView =
                new GetBasicCustomizedProductCollectionModelView();

            expectedModelView.name = customizedProductCollection.name;
            expectedModelView.hasCustomizedProducts = customizedProductCollection.collectionProducts.Count != 0;

            GetBasicCustomizedProductCollectionModelView actualModelView =
                CustomizedProductCollectionModelViewService.fromEntityAsBasic(customizedProductCollection);

            assertBasicModelView(expectedModelView, actualModelView);
        }
コード例 #27
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));
        }
        /// <summary>
        /// Creates an instance of CatalogueCollection with the data in the given AddCatalogueCollectionModelView.
        /// </summary>
        /// <param name="addCatalogueCollectionModelView">AddCatalogueCollectionModelView with the CatalogueCollection's data.</param>
        /// <returns>An instance of CatalogueCollection.</returns>
        /// <exception cref="System.ArgumentException">
        /// Thrown when no CustomizedProductCollection or CustomizedProduct could be found with the provided identifiers.
        /// </exception>
        public static CatalogueCollection create(AddCatalogueCollectionModelView addCatalogueCollectionModelView)
        {
            CustomizedProductCollectionRepository collectionRepository = PersistenceContext.repositories().createCustomizedProductCollectionRepository();

            CustomizedProductCollection customizedProductCollection = collectionRepository.find(addCatalogueCollectionModelView.customizedProductCollectionId);

            if (customizedProductCollection == null)
            {
                throw new ArgumentException(string.Format(CUSTOMIZED_PRODUCT_COLLECTION_NOT_FOUND, addCatalogueCollectionModelView.customizedProductCollectionId));
            }

            CatalogueCollection catalogueCollection = null;

            //check if any customized product was defined
            if (addCatalogueCollectionModelView.customizedProductIds.Any())
            {
                IEnumerable <long> customizedProductIds = addCatalogueCollectionModelView.customizedProductIds.Select(cp => cp.customizedProductId).ToList();

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

                foreach (long customizedProductId in customizedProductIds)
                {
                    CustomizedProduct customizedProduct = customizedProductCollection.collectionProducts
                                                          .Where(cp => cp.customizedProductId == customizedProductId)
                                                          .Select(cp => cp.customizedProduct).SingleOrDefault();

                    if (customizedProduct == null)
                    {
                        throw new ArgumentException(string.Format(
                                                        CUSTOMIZED_PRODUCT_NOT_FOUND_IN_COLLECTION, customizedProductId, addCatalogueCollectionModelView.customizedProductCollectionId)
                                                    );
                    }

                    customizedProducts.Add(customizedProduct);
                }

                catalogueCollection = new CatalogueCollection(customizedProductCollection, customizedProducts);
            }
            else
            {
                catalogueCollection = new CatalogueCollection(customizedProductCollection);
            }

            return(catalogueCollection);
        }
コード例 #29
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);
        }
コード例 #30
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);
        }