Beispiel #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);
        }
Beispiel #2
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));
        }
Beispiel #3
0
        public void ensureChangingToEmptyDesignationThrowsException()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            Action changeDesignation = () => commercialCatalogue.changeDesignation("");

            Assert.Throws <ArgumentException>(changeDesignation);
        }
Beispiel #4
0
        public void ensureRemovingNullCatalogueCollectionThrowsException()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

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

            Assert.Throws <ArgumentException>(removeCollection);
        }
Beispiel #5
0
        public void ensureChangingToNullReferenceThrowsException()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            Action changeReference = () => commercialCatalogue.changeReference(null);

            Assert.Throws <ArgumentException>(changeReference);
        }
Beispiel #6
0
        public void ensureSameAsReturnsFalseIfArgumentIsNotEqualToTheBusinessIdentifier()
        {
            string reference = "other reference";

            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            Assert.False(commercialCatalogue.sameAs(reference));
        }
Beispiel #7
0
        public void ensureInstancesHaveDifferentHashCode()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            CommercialCatalogue otherCommercialCatalogue = new CommercialCatalogue("other reference", "designation");

            Assert.NotEqual(commercialCatalogue.GetHashCode(), otherCommercialCatalogue.GetHashCode());
        }
Beispiel #8
0
        public void ensureIdReturnsCommercialCatalogueBusinessIdentifier()
        {
            string reference = "reference";

            CommercialCatalogue commercialCatalogue = new CommercialCatalogue(reference, "designation");

            Assert.Equal(reference, commercialCatalogue.id());
        }
Beispiel #9
0
        public void ensureSameAsReturnsTrueIfArgumentIsEqualToTheBusinessIdentifier()
        {
            string reference = "reference";

            CommercialCatalogue commercialCatalogue = new CommercialCatalogue(reference, "designation");

            Assert.True(commercialCatalogue.sameAs(reference));
        }
Beispiel #10
0
        public void ensureCommercialCatalogueWithEqualReferenceIsEqual()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            CommercialCatalogue otherCommercialCatalogue = new CommercialCatalogue("reference", "designation");

            Assert.Equal(commercialCatalogue, otherCommercialCatalogue);
        }
Beispiel #11
0
        public void ensureToStringIsEqualIfInstancesAreEqual()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            CommercialCatalogue otherCommercialCatalogue = new CommercialCatalogue("reference", "designation");

            Assert.Equal(commercialCatalogue.ToString(), otherCommercialCatalogue.ToString());
        }
Beispiel #12
0
        public void ensureChangingToValidDesignationDoesNotThrowException()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            Action changeDesignation = () => commercialCatalogue.changeDesignation("a different designation");

            Exception exception = Record.Exception(changeDesignation);

            Assert.Null(exception);
        }
Beispiel #13
0
        public void ensureRemovingNotAddedCatalogueCollectionThrowsException()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            CatalogueCollection catalogueCollection = buildCatalogueCollection("Winter 2018");

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

            Assert.Throws <ArgumentException>(removeCollection);
        }
Beispiel #14
0
        public void ensureChangingReferenceToValidReferenceChangesReference()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            string newReference = "New reference";

            commercialCatalogue.changeReference(newReference);

            Assert.Equal(newReference, commercialCatalogue.reference);
        }
Beispiel #15
0
        public void ensureChangingReferenceToValidReferenceDoesNotThrowException()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            Action changeReference = () => commercialCatalogue.changeReference("New reference");

            Exception exception = Record.Exception(changeReference);

            Assert.Null(exception);
        }
Beispiel #16
0
        public void ensureChangingToValidDesignationChangesDesignation()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            string newDesignation = "a different designation";

            commercialCatalogue.changeDesignation(newDesignation);

            Assert.Equal(newDesignation, commercialCatalogue.designation);
        }
Beispiel #17
0
        public void ensureAddingNullCatalogueCollectionDoesNotAddCollection()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            try
            {
                commercialCatalogue.addCollection(null);
            }
            catch (Exception) { }

            Assert.Empty(commercialCatalogue.catalogueCollectionList);
        }
Beispiel #18
0
        /// <summary>
        /// Retrieves an instance of CommercialCatalogue stored in the repository with a matching identifier.
        /// </summary>
        /// <param name="findCommercialCatalogueModelView">FindCommercialCatalogueModelView with the identifier.</param>
        /// <returns>Instance of GetCommercialCatalogueModelView representing the instance of CommercialCatalogue.</returns>
        /// <exception cref="ResourceNotFoundException">Thrown when no instance of CommercialCatalogue is found with a matching identifier.</exception>
        public GetCommercialCatalogueModelView findCommercialCatalogue(FindCommercialCatalogueModelView findCommercialCatalogueModelView)
        {
            CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository();

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

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

            return(CommercialCatalogueModelViewService.fromEntity(commercialCatalogue));
        }
Beispiel #19
0
        /// <summary>
        /// Deletes an instance of CommercialCatalogue.
        /// </summary>
        /// <param name="deleteCommercialCatalogueModelView">DeleteCommercialCatalogueModelView with CommercialCatalogue's identifier.</param>
        /// <exception cref="ResourceNotFoundException">Thrown when no CommercialCatalogue could be found with the provided identifier.</exception>
        public void deleteCommercialCatalogue(DeleteCommercialCatalogueModelView deleteCommercialCatalogueModelView)
        {
            CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository();

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

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

            catalogueRepository.remove(commercialCatalogue);
        }
Beispiel #20
0
        public void ensureChangingToEmptyReferenceDoesNotChangeReference()
        {
            string reference = "reference";

            CommercialCatalogue commercialCatalogue = new CommercialCatalogue(reference, "designation");

            try
            {
                commercialCatalogue.changeReference("");
            }
            catch (Exception) { }

            Assert.Equal(reference, commercialCatalogue.reference);
        }
Beispiel #21
0
        public void ensureChangingToEmptyDesignationDoesNotChangeDesignation()
        {
            string designation = "designation";

            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", designation);

            try
            {
                commercialCatalogue.changeDesignation("");
            }
            catch (Exception) { }

            Assert.Equal(designation, commercialCatalogue.designation);
        }
Beispiel #22
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));
        }
Beispiel #23
0
        /// <summary>
        /// Adds a CommercialCatalogue.
        /// </summary>
        /// <param name="addCommercialCatalogueModelView">AddCommercialCatalogueModelView with the data used for creating the CommercialCatalogue.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">
        /// Thrown when no CustomizedProductCollection or CustomizedProduct could be found with the provided identifiers or when the CommercialCatalogue can't be saved.
        /// </exception>
        public GetCommercialCatalogueModelView addCommercialCatalogue(AddCommercialCatalogueModelView addCommercialCatalogueModelView)
        {
            CommercialCatalogue commercialCatalogue = CreateCommercialCatalogueService.create(addCommercialCatalogueModelView);

            CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository();

            commercialCatalogue = catalogueRepository.save(commercialCatalogue);

            //an error occurred while saving the catalogue
            if (commercialCatalogue == null)
            {
                throw new ArgumentException(UNABLE_TO_SAVE_CATALOGUE);
            }

            return(CommercialCatalogueModelViewService.fromEntity(commercialCatalogue));
        }
Beispiel #24
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);
        }
Beispiel #25
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);
        }
Beispiel #26
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));
        }
        /// <summary>
        /// Builds an instance of GetBasicCommercialCatalogueModelView from an instance of CommercialCatalogue.
        /// </summary>
        /// <param name="commercialCatalogue">Instance of CommercialCatalogue from which the ModelView will be built.</param>
        /// <returns>An instance of GetBasicCommercialCatalogueModelView.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the provided instance of CommercialCatalogue is null.</exception>
        public static GetBasicCommercialCatalogueModelView fromEntityAsBasic(CommercialCatalogue commercialCatalogue)
        {
            if (commercialCatalogue == null)
            {
                throw new ArgumentNullException(ERROR_NULL_CATALOGUE);
            }

            GetBasicCommercialCatalogueModelView basicCommercialCatalogueModelView = new GetBasicCommercialCatalogueModelView();

            basicCommercialCatalogueModelView.commercialCatalogueId = commercialCatalogue.Id;
            basicCommercialCatalogueModelView.reference             = commercialCatalogue.reference;
            basicCommercialCatalogueModelView.designation           = commercialCatalogue.designation;
            basicCommercialCatalogueModelView.hasCollections        = commercialCatalogue.catalogueCollectionList.Any();

            return(basicCommercialCatalogueModelView);
        }
Beispiel #28
0
        public void ensureRemovingNullCatalogueCollectionDoesNotRemoveCatalogueCollection()
        {
            CommercialCatalogue commercialCatalogue = new CommercialCatalogue("reference", "designation");

            CatalogueCollection catalogueCollection = buildCatalogueCollection("Winter 2018");

            commercialCatalogue.addCollection(catalogueCollection);


            try
            {
                commercialCatalogue.removeCollection(null);
            }
            catch (Exception) { }

            Assert.Single(commercialCatalogue.catalogueCollectionList);
        }
Beispiel #29
0
        /// <summary>
        /// Retrieves the CommercialCatalogue's CatalogueCollections.
        /// </summary>
        /// <param name="findCommercialCatalogueModelView">FindCommercialCatalogueModelView with the identifier.</param>
        /// <returns>Instance of GetAllCatalogueCollectionsModelView representing the IEnumerable of CatalogueCollection.</returns>
        /// <exception cref="ResourceNotFoundException">
        /// Thrown when no instance of CommercialCatalogue is found with a matching identifier of when the CommercialCatalogue has no CatalogueCollections.
        /// </exception>
        public GetAllCatalogueCollectionsModelView findCatalogueCollections(FindCommercialCatalogueModelView findCommercialCatalogueModelView)
        {
            CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository();

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

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

            if (!commercialCatalogue.catalogueCollectionList.Any())
            {
                throw new ResourceNotFoundException(CATALOGUE_COLLECTIONS_NOT_FOUND);
            }
            return(CatalogueCollectionModelViewService.fromCollection(commercialCatalogue.catalogueCollectionList));
        }
        /// <summary>
        /// Builds an instance of GetCommercialCatalogueModelView from an instance of CommercialCatalogue.
        /// </summary>
        /// <param name="commercialCatalogue">Instance of CommercialCatalogue from which the ModelView will be built.</param>
        /// <returns>An instance of GetCommercialCatalogueModelView.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the provided instance of CommercialCatalogue is null.</exception>
        public static GetCommercialCatalogueModelView fromEntity(CommercialCatalogue commercialCatalogue)
        {
            if (commercialCatalogue == null)
            {
                throw new ArgumentNullException(ERROR_NULL_CATALOGUE);
            }

            GetCommercialCatalogueModelView commercialCatalogueView = new GetCommercialCatalogueModelView();

            commercialCatalogueView.commercialCatalogueId = commercialCatalogue.Id;
            commercialCatalogueView.reference             = commercialCatalogue.reference;
            commercialCatalogueView.designation           = commercialCatalogue.designation;
            if (commercialCatalogue.catalogueCollectionList.Any())
            {
                commercialCatalogueView.commercialCatalogueCollections = CatalogueCollectionModelViewService.fromCollection(commercialCatalogue.catalogueCollectionList);
            }
            return(commercialCatalogueView);
        }