Ejemplo n.º 1
0
        public static async Task ListAsync_WithFilter_ReturnsExpectedResult(
            [Frozen] Mock <IOrderItemService> service,
            [Frozen] CallOffId callOffId,
            List <OrderItem> orderItems,
            Order order,
            OrderItemsController controller)
        {
            foreach (var orderItem in orderItems)
            {
                order.AddOrUpdateOrderItem(orderItem);
            }

            const CatalogueItemType catalogueItemType = CatalogueItemType.AdditionalService;

            service.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            service.Setup(o => o.GetOrderItems(callOffId, catalogueItemType)).ReturnsAsync(
                orderItems.Where(i => i.CatalogueItem.CatalogueItemType == catalogueItemType).Select(i => i).ToList());

            var expectedResult = orderItems
                                 .Where(i => i.CatalogueItem.CatalogueItemType == catalogueItemType)
                                 .Select(i => new GetOrderItemModel(i));

            var response = await controller.ListAsync(callOffId, catalogueItemType);

            response.Value.Should().BeEquivalentTo(expectedResult);
        }
Ejemplo n.º 2
0
        public static async Task ListAsync_InvalidCatalogueItemType_ReturnsNotFound(
            [Frozen] Mock <IOrderItemService> service,
            CallOffId callOffId,
            OrderItemsController controller)
        {
            service.Setup(o => o.GetOrderItems(callOffId, It.IsAny <CatalogueItemType>())).ReturnsAsync((List <OrderItem>)null);
            var response = await controller.ListAsync(callOffId, CatalogueItemType.AdditionalService);

            response.Result.Should().BeOfType <NotFoundResult>();
        }
Ejemplo n.º 3
0
        public static async Task ListAsync_CatalogueItemTypeIsInvalid_ReturnsEmptyList(
            [Frozen] Mock <IOrderItemService> service,
            [Frozen] CallOffId callOffId,
            List <OrderItem> orderItems,
            Order order,
            OrderItemsController controller)
        {
            foreach (var orderItem in orderItems)
            {
                order.AddOrUpdateOrderItem(orderItem);
            }

            service.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            service.Setup(o => o.GetOrderItems(callOffId, null)).ReturnsAsync(new List <OrderItem>());

            var response = await controller.ListAsync(callOffId, (CatalogueItemType)100);

            response.Value.Should().BeEmpty();
        }
Ejemplo n.º 4
0
        public static async Task ListAsync_WithoutFilter_ReturnsExpectedResult(
            [Frozen] Mock <IOrderItemService> service,
            [Frozen] CallOffId callOffId,
            List <OrderItem> orderItems,
            Order order,
            OrderItemsController controller)
        {
            foreach (var orderItem in orderItems)
            {
                order.AddOrUpdateOrderItem(orderItem);
            }

            service.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            service.Setup(o => o.GetOrderItems(callOffId, null)).ReturnsAsync(orderItems);

            var expectedResult = orderItems.Select(i => new GetOrderItemModel(i));

            var response = await controller.ListAsync(callOffId, null);

            response.Value.Should().BeEquivalentTo(expectedResult);
        }