コード例 #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
        private CustomizedProductCollection buildCustomizedProductCollection()
        {
            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);

            return(customizedProductCollection);
        }
コード例 #3
0
        public void ensureHasCustomizedProductReturnsTrueIfCustomizedProductWasAdded()
        {
            CustomizedProductCollection collection = new CustomizedProductCollection("Collection");

            CustomizedProduct customizedProduct = buildFinishedCustomizedProductInstance();

            collection.addCustomizedProduct(customizedProduct);

            Assert.True(collection.hasCustomizedProduct(customizedProduct));
        }
コード例 #4
0
        public void ensureAddingPendingCustomizedProductThrowsException()
        {
            Product product = buildValidProduct();

            CustomizedProductCollection instance = new CustomizedProductCollection("Mario");

            Assert.Throws <ArgumentException>(() => instance.addCustomizedProduct(
                                                  buildUnfinishedCustomizedProductInstance()
                                                  ));
        }
コード例 #5
0
        public void ensureAddCustomizedProductWorksForValidProduct()
        {
            CustomizedProduct           customizedProduct = buildFinishedCustomizedProductInstance();
            CustomizedProductCollection instance          = new CustomizedProductCollection("Mario");

            instance.addCustomizedProduct(customizedProduct);

            Assert.NotEmpty(instance.collectionProducts);
            Assert.Equal(customizedProduct, instance.collectionProducts[0].customizedProduct);
        }
コード例 #6
0
        public void ensureAddCustomizedProductFailsIfItAlreadyExists()
        {
            CustomizedProduct        customizedProduct = buildFinishedCustomizedProductInstance();
            List <CustomizedProduct> list = new List <CustomizedProduct>();

            list.Add(customizedProduct);

            CustomizedProductCollection instance = new CustomizedProductCollection("Mario", list);

            Assert.Throws <ArgumentException>(() => instance.addCustomizedProduct(customizedProduct));
        }
コード例 #7
0
        public void ensureCreatingCatalogueCollectionWithCustomizedProductCollectionAddsAllCustomizedProducts()
        {
            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);

            CatalogueCollection catalogueCollection = new CatalogueCollection(customizedProductCollection);

            Assert.True(catalogueCollection.hasCustomizedProduct(customizedProduct1));
            Assert.True(catalogueCollection.hasCustomizedProduct(customizedProduct2));
        }
        private CustomizedProductCollection createCustomizedProductCollection()
        {
            CustomizedProductCollection customizedProductCollection =
                new CustomizedProductCollection("hello");

            CustomizedProduct customizedProduct =
                buildCustomizedProductInstance();

            customizedProductCollection.addCustomizedProduct(customizedProduct);

            return(customizedProductCollection);
        }
コード例 #9
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));
        }
コード例 #10
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);
        }
コード例 #11
0
        public void ensureCatalogueCollectionCantBeCreatedWithDuplicateCustomizedProductsInCustomizedProductEnumerable()
        {
            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");

            List <CustomizedProduct> customizedProducts = new List <CustomizedProduct>()
            {
                customizedProduct1, customizedProduct2, customizedProduct1
            };

            Action createCatalogueCollection = () => new CatalogueCollection(customizedProductCollection, customizedProducts);

            Assert.Throws <ArgumentException>(createCatalogueCollection);
        }
コード例 #12
0
        /// <summary>
        /// Updates a customized product collection by adding a new customized product to it
        /// </summary>
        /// <param name="modelView">model view with the necessary update information</param>
        /// <returns>Updated customized product collection or throws an exception if an error occurs</returns>
        public static CustomizedProductCollection update(AddCustomizedProductToCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollectionRepository customizedProductCollectionRepository =
                PersistenceContext.repositories()
                .createCustomizedProductCollectionRepository();

            CustomizedProductCollection customizedProductCollection =
                customizedProductCollectionRepository.find(modelView.customizedProductCollectionId);

            checkIfCustomizedProductCollectionWasFound(
                customizedProductCollection, modelView.customizedProductCollectionId
                );

            CustomizedProduct customizedProduct =
                PersistenceContext.repositories()
                .createCustomizedProductRepository()
                .find(modelView.customizedProductId);

            if (customizedProduct == null)
            {
                throw new ArgumentException(
                          string.Format(
                              UNABLE_TO_FIND_CUSTOMIZED_PRODUCT,
                              modelView.customizedProductId)
                          );
            }

            customizedProductCollection.addCustomizedProduct(customizedProduct);

            CustomizedProductCollection updatedCustomizedProductCollection =
                customizedProductCollectionRepository.update(customizedProductCollection);

            checkIfUpdatedCustomizedProductCollectionWasSaved(
                updatedCustomizedProductCollection, modelView.customizedProductCollectionId
                );

            return(updatedCustomizedProductCollection);
        }
コード例 #13
0
        public void ensureAddCustomizedProductFailsIfItIsNull()
        {
            CustomizedProductCollection instance = new CustomizedProductCollection("Mario");

            Assert.Throws <ArgumentException>(() => instance.addCustomizedProduct(null));
        }