Пример #1
0
        public void ensureAddingNullCustomizedProductThrowsException()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

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

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

            CustomizedProduct customizedProduct = buildCustomizedProduct("1234");

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

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

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

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

            CustomizedProduct customizedProduct = buildCustomizedProduct("1234");

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

            Assert.Equal(2, catalogueCollection.catalogueCollectionProducts.Count);
        }
Пример #5
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));
        }
Пример #6
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));
        }
Пример #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);
        }
Пример #8
0
        /// <summary>
        /// Adds a CustomizedProduct to the CatalogueCollection.
        /// </summary>
        /// <param name="addCatalogueCollectionProductModelView">AddCatalogueCollectionProductModelView with the data used </param>
        /// <returns></returns>
        /// <exception cref="ResourceNotFoundException">
        /// Thrown when no instance of CommercialCatalogue or CatalogueCollection could be found with the provided identifiers.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// Thrown when the CustomizedProduct being added does not exist in a given CustomizedProductCollection.
        /// </exception>
        public GetCommercialCatalogueModelView addCatalogueCollectionProduct(AddCatalogueCollectionProductModelView addCatalogueCollectionProductModelView)
        {
            CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository();

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

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

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

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

            //retrieve the instance of CustomizedProduct from the the CustomizedProductCollection linked to the CatalogueCollection
            CustomizedProduct customizedProduct = catalogueCollection.customizedProductCollection.collectionProducts
                                                  .Where(cp => cp.customizedProductId == addCatalogueCollectionProductModelView.customizedProductId)
                                                  .Select(cp => cp.customizedProduct).SingleOrDefault();

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

            catalogueCollection.addCustomizedProduct(customizedProduct);
            commercialCatalogue = catalogueRepository.update(commercialCatalogue);

            return(CommercialCatalogueModelViewService.fromEntity(commercialCatalogue));
        }