Пример #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);
        }
Пример #2
0
        /// <summary>
        /// Removes an instance of CatalogueCollectionProduct from a CommercialCatalogue's CatalogueCollection.
        /// </summary>
        /// <param name="deleteCatalogueCollectionProductModelView">DeleteCatalogueCollectionProductModelView with the CustomizedProduct's, CustomizedProductCollection's and CommercialCatalogue's identifiers.</param>
        ///<exception cref="ResourceNotFoundException">Thrown when no CommercialCatalogue, CatalogueCollection or CatalogueCollectionProduct could be found.</exception>
        public void deleteCatalogueCollectionProduct(DeleteCatalogueCollectionProductModelView deleteCatalogueCollectionProductModelView)
        {
            CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository();

            CommercialCatalogue commercialCatalogue = catalogueRepository.find(deleteCatalogueCollectionProductModelView.commercialCatalogueId);

            if (commercialCatalogue == null)
            {
                throw new ResourceNotFoundException(string.Format(CATALOGUE_NOT_FOUND_BY_ID, deleteCatalogueCollectionProductModelView.commercialCatalogueId));
            }

            CatalogueCollection catalogueCollection = commercialCatalogue.catalogueCollectionList
                                                      .Where(cc => cc.customizedProductCollection.Id == deleteCatalogueCollectionProductModelView.customizedProductCollectionId).SingleOrDefault();

            if (catalogueCollection == null)
            {
                throw new ResourceNotFoundException(string.Format(
                                                        CATALOGUE_COLLECTION_NOT_FOUND_BY_ID, deleteCatalogueCollectionProductModelView.customizedProductCollectionId, deleteCatalogueCollectionProductModelView.commercialCatalogueId
                                                        ));
            }

            CustomizedProduct customizedProduct = catalogueCollection.catalogueCollectionProducts
                                                  .Where(ccp => ccp.customizedProductId == deleteCatalogueCollectionProductModelView.customizedProductId)
                                                  .Select(ccp => ccp.customizedProduct).SingleOrDefault();

            if (customizedProduct == null)
            {
                throw new ResourceNotFoundException(string.Format(
                                                        CUSTOMIZED_PRODUCT_NOT_FOUND_BY_ID, deleteCatalogueCollectionProductModelView.customizedProductCollectionId, deleteCatalogueCollectionProductModelView.customizedProductId
                                                        ));
            }

            catalogueCollection.removeCustomizedProduct(customizedProduct);
            catalogueRepository.update(commercialCatalogue);
        }
Пример #3
0
        public void ensureInstancesHaveSameHashCode()
        {
            CatalogueCollection catalogueCollection  = buildCatalogueCollection();
            CatalogueCollection catalogueCollection2 = buildCatalogueCollection();

            Assert.Equal(catalogueCollection.GetHashCode(), catalogueCollection2.GetHashCode());
        }
Пример #4
0
        /// <summary>
        /// Retrieves all the CustomizedProducts added to the CatalogueCollection.
        /// </summary>
        /// <param name="findCatalogueCollectionModelView">FindCatalogueCollectionModelView with the CommercialCatalogue's and CatalogueCollection's identifiers.</param>
        /// <returns>Instance of GetAllCustomizedProductsModelView representing all of the CatalogueCollectionProduct's.</returns>
        /// <exception cref="ResourceNotFoundException">
        /// Thrown when no CommercialCatalogue or CatalogueCollection could be found with the provided identifiers or when the IEnumerable of CatalogueCollectionProduct is empty.
        /// </exception>
        public GetAllCustomizedProductsModelView findCatalogueCollectionProducts(FindCatalogueCollectionModelView findCatalogueCollectionModelView)
        {
            CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository();

            CommercialCatalogue commercialCatalogue = catalogueRepository.find(findCatalogueCollectionModelView.commercialCatalogueId);

            if (commercialCatalogue == null)
            {
                throw new ResourceNotFoundException(string.Format(CATALOGUE_NOT_FOUND_BY_ID, findCatalogueCollectionModelView.commercialCatalogueId));
            }

            CatalogueCollection catalogueCollection = commercialCatalogue.catalogueCollectionList
                                                      .Where(cc => cc.customizedProductCollectionId == findCatalogueCollectionModelView.customizedProductCollectionId).SingleOrDefault();

            if (catalogueCollection == null)
            {
                throw new ResourceNotFoundException(string.Format(
                                                        CATALOGUE_COLLECTION_NOT_FOUND_BY_ID, findCatalogueCollectionModelView.customizedProductCollectionId,
                                                        findCatalogueCollectionModelView.commercialCatalogueId)
                                                    );
            }

            IEnumerable <CustomizedProduct> customizedProducts = catalogueCollection.catalogueCollectionProducts.Select(ccp => ccp.customizedProduct).ToList();

            if (!customizedProducts.Any())
            {
                throw new ResourceNotFoundException(CATALOGUE_COLLECTION_PRODUCTS_NOT_FOUND);
            }

            return(CustomizedProductModelViewService.fromCollection(customizedProducts));
        }
        /// <summary>
        /// Creates a new instance of CommercialCatalogue with the data in the given instance of AddCommercialCatalogueModelView.
        /// </summary>
        /// <param name="addCommercialCatalogueModelView">AddCommercialCatalogueModelView with the CommercialCatalogue's data.</param>
        /// <returns>An instance of CommercialCatalogue.</returns>
        /// <exception cref="System.ArgumentException">
        /// Thrown when no CustomizedProductCollection or CustomizedProduct could be found with the provided identifiers.
        /// </exception>
        public static CommercialCatalogue create(AddCommercialCatalogueModelView addCommercialCatalogueModelView)
        {
            string reference   = addCommercialCatalogueModelView.reference;
            string designation = addCommercialCatalogueModelView.designation;

            //check if catalogue collections were specified
            if (!addCommercialCatalogueModelView.catalogueCollections.Any())
            {
                return(new CommercialCatalogue(reference, designation));
            }
            else
            {
                //create repositories so that customized products and collections can be fetched
                CustomizedProductCollectionRepository customizedProductCollectionRepository = PersistenceContext
                                                                                              .repositories().createCustomizedProductCollectionRepository();

                CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories()
                                                                          .createCustomizedProductRepository();

                List <CatalogueCollection> catalogueCollections = new List <CatalogueCollection>();

                foreach (AddCatalogueCollectionModelView addCatalogueCollectionModelView in addCommercialCatalogueModelView.catalogueCollections)
                {
                    CatalogueCollection catalogueCollection = CreateCatalogueCollectionService.create(addCatalogueCollectionModelView);

                    catalogueCollections.Add(catalogueCollection);
                }

                return(new CommercialCatalogue(reference, designation, catalogueCollections));
            }
        }
Пример #6
0
        public void ensureCatalogueCollectionWithEqualCustomizedProductCollectionIsEqual()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CatalogueCollection otherCatalogueCollection = buildCatalogueCollection();

            Assert.True(catalogueCollection.Equals(otherCatalogueCollection));
        }
Пример #7
0
        public void ensureToStringIsEqualIfInstancesAreEqual()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CatalogueCollection otherCatalogueCollection = buildCatalogueCollection();

            Assert.Equal(catalogueCollection.ToString(), otherCatalogueCollection.ToString());
        }
Пример #8
0
        public void ensureSameAsReturnsFalseIfArgumentIsNotEqualToTheBusinessIdentifier()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            string name = "some other name";

            Assert.False(catalogueCollection.sameAs(name));
        }
Пример #9
0
        public void ensureAddingNullCustomizedProductThrowsException()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            Action addNullCustomizedProduct = () => catalogueCollection.addCustomizedProduct(null);

            Assert.Throws <ArgumentException>(addNullCustomizedProduct);
        }
Пример #10
0
        public void ensureSameAsReturnsTrueIfArgumentIsEqualToTheBusinessIdentifier()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            string name = catalogueCollection.customizedProductCollection.name;

            Assert.True(catalogueCollection.sameAs(name));
        }
Пример #11
0
        public void ensureRemovingNullCustomizedProductThrowsException()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            Action removeCustomizedProduct = () => catalogueCollection.removeCustomizedProduct(null);

            Assert.Throws <ArgumentException>(removeCustomizedProduct);
        }
Пример #12
0
        public void ensureCatalogueCollectionCanBeCreatedIfCustomizedProductCollectionIsNotNull()
        {
            CustomizedProductCollection customizedProductCollection = new CustomizedProductCollection("Closets Spring 2019");

            CatalogueCollection catalogueCollection = new CatalogueCollection(customizedProductCollection);

            Assert.NotNull(catalogueCollection);
        }
Пример #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 ensureRemovingNotAddedCustomizedProductThrowsException()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProduct customizedProduct = buildCustomizedProduct("12354112");

            Action removeCustomizedProduct = () => catalogueCollection.removeCustomizedProduct(customizedProduct);

            Assert.Throws <ArgumentException>(removeCustomizedProduct);
        }
Пример #16
0
        public void ensureAddingDuplicateCustomizedProductThrowsException()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProduct customizedProduct = buildCustomizedProduct("1234");

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

            Assert.Throws <ArgumentException>(addCustomizedProduct);
        }
Пример #17
0
        public void ensureRemovingNotAddedCatalogueCollectionThrowsException()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            CatalogueCollection catalogueCollection = buildCatalogueCollection("Winter 2018");

            Action removeCollection = () => commercialCatalogue.removeCollection(catalogueCollection);

            Assert.Throws <ArgumentException>(removeCollection);
        }
Пример #18
0
        public void ensureRemovingValidCustomizedProductRemovesCustomizedProduct()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProduct customizedProduct = buildCustomizedProduct("1234");

            catalogueCollection.removeCustomizedProduct(customizedProduct);

            Assert.False(catalogueCollection.hasCustomizedProduct(customizedProduct));
            Assert.Single(catalogueCollection.catalogueCollectionProducts);
        }
Пример #19
0
        public void ensureRemovingValidCustomizedProductDoesNotThrowException()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProduct customizedProduct = buildCustomizedProduct("1234");

            Action removeCustomizedProduct = () => catalogueCollection.removeCustomizedProduct(customizedProduct);

            Exception exception = Record.Exception(removeCustomizedProduct);

            Assert.Null(exception);
        }
Пример #20
0
        public void ensureRemovingNullCustomizedProductDoesNotRemoveCustomizedProduct()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            try
            {
                catalogueCollection.removeCustomizedProduct(null);
            }
            catch (Exception) { }

            Assert.Equal(2, catalogueCollection.catalogueCollectionProducts.Count);
        }
Пример #21
0
        public void ensureRemovingNotAddedCustomizedProductDoesNotRemoveCustomizedProduct()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProduct customizedProduct = buildCustomizedProduct("12354112");

            try
            {
                catalogueCollection.removeCustomizedProduct(customizedProduct);
            }
            catch (Exception) { }

            Assert.Equal(2, catalogueCollection.catalogueCollectionProducts.Count);
        }
Пример #22
0
        public void ensureAddingDuplicateCustomizedProductDoesNotAddCustomizedProduct()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProduct customizedProduct = buildCustomizedProduct("1234");

            try
            {
                catalogueCollection.addCustomizedProduct(customizedProduct);
            }
            catch (Exception) { }

            Assert.Equal(2, catalogueCollection.catalogueCollectionProducts.Count);
        }
Пример #23
0
        public void ensureAddingCustomizedProductNotAddedTocustomizedProductCollectionDoesNotAddCustomizedProduct()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

            CustomizedProduct customizedProduct = buildCustomizedProduct("12345");

            try
            {
                catalogueCollection.addCustomizedProduct(customizedProduct);
            }
            catch (Exception) { }

            Assert.Equal(2, catalogueCollection.catalogueCollectionProducts.Count);
            Assert.False(catalogueCollection.hasCustomizedProduct(customizedProduct));
        }
Пример #24
0
        public void ensureAddingValidCatalogueCollectionAddsCollection()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            CatalogueCollection catalogueCollection = buildCatalogueCollection("Winter 2018");

            commercialCatalogue.addCollection(catalogueCollection);

            CatalogueCollection otherCatalogueCollection = buildCatalogueCollection("Spring 2019");

            commercialCatalogue.addCollection(otherCatalogueCollection);

            Assert.Equal(2, commercialCatalogue.catalogueCollectionList.Count);
            Assert.True(commercialCatalogue.hasCollection(otherCatalogueCollection));
        }
        /// <summary>
        /// Converts an instance of CatalogueCollection into an instance of GetBasicCatalogueCollectionModelView.
        /// </summary>
        /// <param name="catalogueCollection">Instance of CatalogueCollection being converted.</param>
        /// <returns>An instance of GetBasicCatalogueCollectionModelView representing the CatalogueCollection.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the provided instance of CatalogueCollection is null.</exception>
        public static GetBasicCatalogueCollectionModelView fromEntityAsBasic(CatalogueCollection catalogueCollection)
        {
            if (catalogueCollection == null)
            {
                throw new ArgumentNullException(ERROR_NULL_CATALOGUE_COLLECTION);
            }

            GetBasicCatalogueCollectionModelView basicCatalogueCollectionModelView = new GetBasicCatalogueCollectionModelView();

            basicCatalogueCollectionModelView.id   = catalogueCollection.customizedProductCollectionId;
            basicCatalogueCollectionModelView.name = catalogueCollection.customizedProductCollection.name;
            basicCatalogueCollectionModelView.hasCustomizedProducts = catalogueCollection.catalogueCollectionProducts.Any();

            return(basicCatalogueCollectionModelView);
        }
Пример #26
0
        public void ensureAddingDuplicateCatalogueCollectionThrowsException()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            string collectionName = "Winter 2018";

            CatalogueCollection catalogueCollection = buildCatalogueCollection(collectionName);

            commercialCatalogue.addCollection(catalogueCollection);

            CatalogueCollection otherCatalogueCollection = buildCatalogueCollection(collectionName);

            Action addCatalogueCollection = () => commercialCatalogue.addCollection(otherCatalogueCollection);

            Assert.Throws <ArgumentException>(addCatalogueCollection);
        }
Пример #27
0
        public void ensureRemovingAddedCatalogueCollectionRemovesCollection()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            CatalogueCollection catalogueCollection = buildCatalogueCollection("Winter 2018");

            commercialCatalogue.addCollection(catalogueCollection);

            CatalogueCollection otherCatalogueCollection = buildCatalogueCollection("Spring 2019");

            commercialCatalogue.addCollection(otherCatalogueCollection);

            commercialCatalogue.removeCollection(otherCatalogueCollection);

            Assert.False(commercialCatalogue.hasCollection(otherCatalogueCollection));
        }
Пример #28
0
        public void ensureAddingValidCatalogueCollectionDoesNotThrowException()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            CatalogueCollection catalogueCollection = buildCatalogueCollection("Winter 2018");

            commercialCatalogue.addCollection(catalogueCollection);

            CatalogueCollection otherCatalogueCollection = buildCatalogueCollection("Spring 2019");

            Action addCatalogueCollection = () => commercialCatalogue.addCollection(otherCatalogueCollection);

            Exception exception = Record.Exception(addCatalogueCollection);

            Assert.Null(exception);
        }
Пример #29
0
        public void ensureCommercialCatalogueCanBeCreatedWithValidCatalogueCollectionEnumerable()
        {
            CatalogueCollection catalogueCollection  = buildCatalogueCollection("Christmas 2018");
            CatalogueCollection catalogueCollection1 = buildCatalogueCollection("Happy New 2019");

            IEnumerable <CatalogueCollection> catalogueCollections = new List <CatalogueCollection>()
            {
                catalogueCollection, catalogueCollection1
            };

            Action createCommercialCatalogue = () => new CommercialCatalogue("reference", "designation", catalogueCollections);

            Exception exception = Record.Exception(createCommercialCatalogue);

            Assert.Null(exception);
        }
Пример #30
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));
        }