public async Task PostOrderItemReturns400WhenQuantityLessThan1() { OrderItem orderItem = _fixture.Create <OrderItem>(); Guid orderId = Guid.NewGuid(); Guid productId = Guid.NewGuid(); int quantity = 0; _mockOrderItemAccess.Reset(); _mockOrderItemAccess .Setup(a => a.CreateOrderItemAsync(orderId, productId, quantity, It.IsAny <CancellationToken>())) .ReturnsAsync(orderItem); OrderItemsController sut = CreateSystemUnderTest(); var result = await sut.PostAsync(orderId, productId, quantity, It.IsAny <CancellationToken>()); _mockOrderItemAccess.Verify(a => a.CreateOrderItemAsync(orderId, productId, quantity, It.IsAny <CancellationToken>()), Times.Never); Assert.IsType <BadRequestResult>(result); }
public async Task PostOrderItemReturns404WhenOrderNotFound() { OrderItem orderItem = _fixture.Create <OrderItem>(); Guid orderId = Guid.NewGuid(); Guid productId = Guid.NewGuid(); int quantity = _fixture.Create <int>(); _mockOrderItemAccess.Reset(); _mockOrderItemAccess .Setup(a => a.CreateOrderItemAsync(orderId, productId, quantity, It.IsAny <CancellationToken>())) .ThrowsAsync(new OrderNotFoundException(string.Empty)); OrderItemsController sut = CreateSystemUnderTest(); var result = await sut.PostAsync(orderId, productId, quantity, It.IsAny <CancellationToken>()); _mockOrderItemAccess.Verify(a => a.CreateOrderItemAsync(orderId, productId, quantity, It.IsAny <CancellationToken>()), Times.Once); Assert.IsType <NotFoundResult>(result); }
public async Task PostOrderItemReturnsOkayWhenOrderItemCreated() { OrderItem orderItem = _fixture.Create <OrderItem>(); Guid orderId = Guid.NewGuid(); Guid productId = Guid.NewGuid(); int quantity = _fixture.Create <int>(); _mockOrderItemAccess.Reset(); _mockOrderItemAccess .Setup(a => a.CreateOrderItemAsync(orderId, productId, quantity, It.IsAny <CancellationToken>())) .ReturnsAsync(orderItem); OrderItemsController sut = CreateSystemUnderTest(); var result = await sut.PostAsync(orderId, productId, quantity, It.IsAny <CancellationToken>()); _mockOrderItemAccess.Verify(a => a.CreateOrderItemAsync(orderId, productId, quantity, It.IsAny <CancellationToken>()), Times.Once); Assert.IsType <OkObjectResult>(result); Assert.NotNull((OrderItem)((OkObjectResult)result).Value); }