public void TestAddingOptionsToProduct()
        {
            var product = Product.Create(name: "Apple iPhone 12 Pro Max",
                                         description: "The iPhone 12 Pro is 5G capable, has a 6.1 inch Super Retina XDR display, and new possibilities with improved night mode camera lenses",
                                         price: 1650.00m,
                                         deliveryPrice: 10.00m);

            var storageCapacity64GB = ProductOption.Create(product.Id,
                                                           name: "Storage Capacity",
                                                           description: "64 GB");

            var storageCapacity128GB = ProductOption.Create(product.Id,
                                                            name: "Storage Capacity",
                                                            description: "128 GB");

            product.AddProductOption(storageCapacity64GB);
            product.AddProductOption(storageCapacity128GB);

            Assert.NotNull(product.ProductOptions);
            Assert.True(product.ProductOptions.Count() == 2);
            Assert.All(product.ProductOptions, x => IsNewProductOption(x));
            Assert.Contains(product.ProductOptions, item => item
                            .Name
                            .Equals(storageCapacity64GB.Name, StringComparison.InvariantCultureIgnoreCase));
            Assert.Contains(product.ProductOptions, item => item
                            .Name
                            .Equals(storageCapacity128GB.Name, StringComparison.InvariantCultureIgnoreCase));
        }
        public async Task AddAsync(ProductOptionDto productOptionDto)
        {
            var productOption = ProductOption.Create(productOptionDto.ProductId,
                                                     productOptionDto.Name,
                                                     productOptionDto.Description);

            var product = await _productRepository.GetAsync(productOptionDto.ProductId);

            product.AddProductOption(productOption);
            await this._unitOfWork.CommitAsync();
        }
        public void TestProductOptionCreation()
        {
            Guid   productId   = Guid.NewGuid();
            string name        = "Storage Capacity";
            string description = "64 GB";

            var productOption = ProductOption.Create(productId,
                                                     name,
                                                     description);

            Assert.Equal(name, productOption.Name);
            Assert.Equal(description, productOption.Description);
            Assert.True(productOption.IsNew);
        }
Beispiel #4
0
        public ActionResult CreateProductOption(Guid productId, ProductOption option)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var productExists = this.productRepository.ProductExists(productId);

            if (!productExists)
            {
                BadRequest(new ErrorMessageDto(404, $"Cant find product {productId}"));
            }

            option.ProductId = productId;

            option.Create();

            this.productRepository.AddProductOption(option);

            return(Created($"/{productId}/options/{option.Id}", option));
        }
 public StatusCode CreateOption(Guid productId, ProductOption option)
 {
     option.ProductId = productId;
     return(Helpers.ResponseMaker(option.Create()));
 }