Beispiel #1
0
        public void GetOptions()
        {
            Guid ProductId = Guid.NewGuid();
            Guid OptionId1 = Guid.NewGuid();
            var  OptionId2 = Guid.NewGuid();

            var product = new ProductEntity()
            {
                Id            = ProductId,
                Name          = "Product With Options",
                Description   = "Product with options Description",
                Price         = 999.99M,
                DeliveryPrice = 9.8M
            };
            var productOption1 = new ProductOptionsEntity()
            {
                ProductId   = ProductId,
                Id          = OptionId1,
                Name        = "Option 1",
                Description = "Option 1 Description"
            };
            var productOption2 = new ProductOptionsEntity()
            {
                ProductId   = ProductId,
                Id          = OptionId2,
                Name        = "Option 2",
                Description = "Option 2 Description"
            };

            _productsService.CreateProduct(product);
            _productsOptionService.CreateOption(ProductId, productOption1);
            _productsOptionService.CreateOption(ProductId, productOption2);

            var productOptions = _productsOptionService.GetOptions(ProductId);

            Assert.True(2 == productOptions.Count, "Two options created successfully");

            var productOption = _productsOptionService.GetOption(ProductId, OptionId1);

            Assert.True("Option 1" == productOption.Name, "Successfully retrieved option 1");
        }
Beispiel #2
0
        public HttpResponseMessage GetOptions(Guid productId)
        {
            log.Info(String.Format("Get Product Options Method called for Product Id : {0}", productId));

            var prodOptions = _productOptionService.GetOptions(productId);

            if (prodOptions != null)
            {
                var productOptionsEntity = prodOptions as List <ProductOptionsEntity> ?? prodOptions;

                if (productOptionsEntity.Count > 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, productOptionsEntity));
                }
            }
            return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Products not found"));
        }