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); }
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>(); }
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(); }
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); }