Ejemplo n.º 1
0
        public async Task Execution_deletes_order_and_associated_order_items_state_based_async()
        {
            var order = new Order()
            {
                OrderDate = DateTime.Now
            };
            var orderRepo = new OrderRepository(Mock.Of <ICustomerDataProxy>(), Mock.Of <IOrderItemDataProxy>());

            orderRepo.Clear();
            order = orderRepo.Insert(order);
            var orderItemRepo = new OrderItemRepository();

            orderItemRepo.Clear();
            await orderItemRepo.InsertAsync(new OrderItem { OrderID = order.ID, OrderStatusID = OrderStatusConstants.PENDING_STATUS });

            await orderItemRepo.InsertAsync(new OrderItem { OrderID = order.ID, OrderStatusID = OrderStatusConstants.SUBMITTED_STATUS });

            await orderItemRepo.InsertAsync(new OrderItem { OrderID = order.ID, OrderStatusID = OrderStatusConstants.BACK_ORDERED_STATE });

            await orderItemRepo.InsertAsync(new OrderItem { OrderID = 2, OrderStatusID = OrderStatusConstants.PENDING_STATUS });

            var orderItemService = new OrderItemService(orderItemRepo, Mock.Of <IProductDataProxy>(), Mock.Of <IInventoryItemDataProxy>(), new TransactionContextStub());

            var command = new DeleteOrderCommand(order.ID, orderRepo, orderItemService, new TransactionContextStub());
            await command.ExecuteAsync();

            orderRepo.GetAll().ShouldBeEmpty();
            orderItemRepo.GetAll().Count().ShouldBe(1);
        }
Ejemplo n.º 2
0
        public GraphQLQueries(OrderRepository orderRepository,
                              OrderItemRepository orderItemRepository)
        {

            #region Order

            Field<ListGraphType<OrderType>>(
               "orders",
               resolve: context => orderRepository.GetAll());

            Field<OrderType>(
                "order",
                arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>>
                { Name = "id" }),
                resolve: context =>
                {
                    var id = context.GetArgument<int>("id");
                    return orderRepository.GetOne(id);

                });


            #endregion


            #region OrderItems

            Field<ListGraphType<OrderItemType>>(
                "orderItems",
                resolve: context => orderItemRepository.GetAll());

            Field<OrderItemType>(
                "orderItemsForOrder",
                arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>>
                { Name = "id" }),
                resolve: context =>
                {
                    var id = context.GetArgument<int>("id");
                    return orderItemRepository.GetForOrder(id);

                });



            #endregion

        }
Ejemplo n.º 3
0
 public IEnumerable <OrderItem> GetAll()
 {
     return(_repository.GetAll());
 }
Ejemplo n.º 4
0
        public NorthwindQuery(CustomerRepository customerRepository,
                              OrderRepository orderRepository,
                              SupplierRepository supplierRepository,
                              ProductRepository productRepository,
                              OrderItemRepository orderItemRepository)
        {
            Field <ListGraphType <CustomerType> >(
                "customers",
                resolve: context => customerRepository.GetAll()
                );

            Field <ListGraphType <OrderType> >(
                "orders",
                resolve: context => orderRepository.GetAll()
                );

            Field <ListGraphType <SupplierType> >(
                "suppliers",
                resolve: context => supplierRepository.GetAll()
                );

            Field <ListGraphType <ProductType> >(
                "products",
                resolve: context => productRepository.GetAll()
                );

            Field <ListGraphType <OrderItemType> >(
                "orderItems",
                resolve: context => orderItemRepository.GetAll()
                );

            Field <CustomerType>(
                "customer",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <int>("id");
                return(customerRepository.GetOne(id));
            }
                );

            Field <SupplierType>(
                "supplier",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <int>("id");
                return(supplierRepository.GetOne(id));
            }
                );

            Field <OrderType>(
                "order",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <int>("id");
                return(orderRepository.GetOne(id));
            }
                );

            Field <ListGraphType <SupplierType> >(
                "suppliersByCountry",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name = "country"
            }),
                resolve: context =>
            {
                var country = context.GetArgument <string>("country");
                return(supplierRepository.GetForCountry(country));
            }
                );
        }