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);
        }
Beispiel #2
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));
        }
Beispiel #3
0
        /// <summary>
        /// Fetches a customized product collection by its name
        /// </summary>
        /// <param name="name">name of the customized product collection</param>
        /// <returns>ActionResult with the requested customized product collection or an error message</returns>
        private ActionResult findByName(string name)
        {
            try
            {
                GetCustomizedProductCollectionModelView modelView = new GetCustomizedProductCollectionModelView();
                modelView.name = name;
                GetCustomizedProductCollectionModelView customizedProductCollectionModelView = new core.application.CustomizedProductCollectionController().findCollectionByEID(modelView);

                return(Ok(customizedProductCollectionModelView));
            }
            catch (ResourceNotFoundException resourceNotFoundException)
            {
                return(NotFound(new SimpleJSONMessageService(resourceNotFoundException.Message)));
            }
            catch (Exception)
            {
                return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR)));
            }
        }