public async Task WHEN_valid_request_SHOULD_succeed()
        {
            //Arrange
            var findOrderRequest = new FindOrdersRequest();
            var orderQueryResult = new OrderQueryResult
            {
                TotalCount = 1,
                Results    = new List <OrderItem>
                {
                    new OrderItem()
                }
            };
            var orderRepository = _container.CreateInstance <OrderRepository>();

            _container.GetMock <IFindOrdersRequestFactory>()
            .Setup(r => r.Create(It.IsAny <GetCustomerOrdersParam>()))
            .Returns(findOrderRequest);

            _container.GetMock <IOvertureClient>()
            .Setup(r => r.SendAsync(findOrderRequest))
            .ReturnsAsync(orderQueryResult);

            //Act
            var result = await orderRepository.GetCustomerOrdersAsync(BuildGetCustomerOrdersParam()).ConfigureAwait(false);

            //Assert
            result.Should().NotBeNull();
            result.TotalCount.ShouldBeEquivalentTo(1);
            result.Results.Should().NotBeNull();
        }
Beispiel #2
0
        public virtual FindOrdersRequest Create(GetCustomerOrdersParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException("param.CultureInfo");
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException("param.CustomerId");
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException("param.Scope");
            }

            var request = new FindOrdersRequest
            {
                CustomerId  = param.CustomerId,
                CultureName = param.CultureInfo.Name,
                ScopeId     = param.Scope,
                Query       = new Query
                {
                    StartingIndex = (param.Page - 1) * OrderHistoryConfiguration.MaxItemsPerPage,
                    MaximumItems  = OrderHistoryConfiguration.MaxItemsPerPage,
                    Sortings      = new List <QuerySorting>
                    {
                        new QuerySorting
                        {
                            Direction    = SortDirection.Descending,
                            PropertyName = "Created"
                        }
                    }
                },
            };

            request.Query.Filter = new FilterGroup
            {
                Filters = new List <Filter>
                {
                    BuildOrderStatusFilter(param.OrderTense)
                }
            };

            return(request);
        }
        public async Task WHEN_result_is_null_SHOULD_return_null()
        {
            //Arrange
            var findOrderRequest = new FindOrdersRequest();
            var orderRepository  = _container.CreateInstance <OrderRepository>();

            _container.GetMock <IFindOrdersRequestFactory>()
            .Setup(r => r.Create(It.IsAny <GetCustomerOrdersParam>()))
            .Returns(findOrderRequest);

            _container.GetMock <IOvertureClient>()
            .Setup(r => r.SendAsync(findOrderRequest))
            .ReturnsAsync(null);

            //Act
            var result = await orderRepository.GetCustomerOrdersAsync(BuildGetCustomerOrdersParam()).ConfigureAwait(false);

            //Assert
            result.Should().BeNull();
        }
Beispiel #4
0
        private void ValidateRequest(FindOrdersRequest request, GetCustomerOrdersParam param,
                                     int expectedStartingIndex, bool expectedNot)
        {
            request.Should().NotBeNull();
            request.CustomerId.ShouldBeEquivalentTo(param.CustomerId);
            request.CultureName.ShouldBeEquivalentTo(param.CultureInfo.Name);
            request.ScopeId.ShouldBeEquivalentTo(param.Scope);
            request.Query.Should().NotBeNull();

            var query = request.Query;

            query.StartingIndex.ShouldBeEquivalentTo(expectedStartingIndex);
            query.MaximumItems.ShouldBeEquivalentTo(OrderHistoryConfiguration.MaxItemsPerPage);
            query.Filter.Should().NotBeNull();
            query.Filter.Filters.Should().NotBeNull();
            var filter = query.Filter.Filters.FirstOrDefault();

            filter.Should().NotBeNull();
            filter.Member.ShouldBeEquivalentTo("OrderStatus");
            filter.Operator.ShouldBeEquivalentTo(Operator.In);
            filter.Not.ShouldBeEquivalentTo(expectedNot);
        }
Beispiel #5
0
        public FindOrdersResult FindOrders(FindOrdersRequest request)
        {
            var core = new FindOrdersCore(request, _orderRepository);

            return(core.DoExecute());
        }