Пример #1
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);
        }
Пример #2
0
        public void ensureRemovingNullCustomizedProductThrowsException()
        {
            CatalogueCollection catalogueCollection = buildCatalogueCollection();

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

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

            CustomizedProduct customizedProduct = buildCustomizedProduct("12354112");

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

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

            CustomizedProduct customizedProduct = buildCustomizedProduct("1234");

            catalogueCollection.removeCustomizedProduct(customizedProduct);

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

            CustomizedProduct customizedProduct = buildCustomizedProduct("1234");

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

            Exception exception = Record.Exception(removeCustomizedProduct);

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

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

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

            CustomizedProduct customizedProduct = buildCustomizedProduct("12354112");

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

            Assert.Equal(2, catalogueCollection.catalogueCollectionProducts.Count);
        }