コード例 #1
0
        [InlineData(1)] // 15, 20
        public void PutOrderTest(int id)
        {
            // Arrange
            var currentOrder = _service.GetOrderByID(id);

            Assert.False(currentOrder.Delivered);

            var newOrderedProducts = new List <BasketElemDTO>();

            foreach (var x in currentOrder.OrderedProducts)
            {
                newOrderedProducts.Add(new BasketElemDTO
                {
                    amount  = x.amount,
                    Id      = x.ID,
                    product = new ProductDTO
                    {
                        Id        = x.product.ID,
                        Amount    = x.product.Amount,
                        Available = x.product.Available,
                        Category  = new CategoryDTO {
                            Id = x.product.CategoryId, Name = _service.GetCategoryByID(x.product.CategoryId).Name
                        },
                        Description  = x.product.Description,
                        Image        = x.product.Image,
                        Manufacturer = x.product.Manufacturer,
                        ModelID      = x.product.ModelID,
                        Price        = x.product.Price
                    }
                });
            }

            var newOrder = new OrderDTO
            {
                ID              = currentOrder.ID,
                UserName        = currentOrder.UserName,
                Address         = currentOrder.Address,
                PhoneNumber     = currentOrder.PhoneNumber,
                Delivered       = currentOrder.Delivered,
                Email           = currentOrder.Email,
                OrderedProducts = newOrderedProducts
            };

            newOrder.Delivered = true;

            // Act
            //_service.UpdateProduct(currentProduct);
            var result = _controller.PutOrder(id, newOrder);

            // Assert
            var objectResult      = Assert.IsAssignableFrom <OkResult>(result);
            var newCurrentProduct = _service.GetOrderByID(id);

            Assert.True(currentOrder.Delivered);
        }
コード例 #2
0
        public IActionResult GetOrder(int id)
        {
            try
            {
                var o = _service.GetOrderByID(id);

                return(Ok(new OrderDTO
                {
                    ID = o.ID,
                    UserName = o.UserName,
                    Email = o.Email,
                    Address = o.Address,
                    PhoneNumber = o.PhoneNumber,
                    Delivered = o.Delivered,
                    OrderedProducts = new List <BasketElemDTO>(o.OrderedProducts.Select(x => new BasketElemDTO
                    {
                        amount = x.amount,
                        Id = x.ID,
                        product = new ProductDTO
                        {
                            Id = x.product.ID,
                            Amount = x.product.Amount,
                            Available = x.product.Available,
                            Category = new CategoryDTO {
                                Id = x.product.CategoryId, Name = _service.GetCategoryByID(x.product.CategoryId).Name
                            },
                            Description = x.product.Description,
                            Image = x.product.Image,
                            Manufacturer = x.product.Manufacturer,
                            ModelID = x.product.ModelID,
                            Price = x.product.Price
                        }
                    }))
                }));
            }
            catch (InvalidOperationException)
            {
                // Single() nem adott eredményt
                return(NotFound());
            }
            catch
            {
                // Internal Server Error
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }