public void NewOrderShouldBeAddedTogetherOrderItemsSuccess() { //Arrange var handler = Fixture.GetOrderHandler(); var command = GeneratedObjectsTests.GenerateAddItemCommand(1); var order = GeneratedObjectsTests.GenerateOrder(); var product = GeneratedObjectsTests.GenerateProduct(1M); Fixture.OrderAdoRepositoryMock.Setup(r => r.GetLastCreatedOrderByUserId(command.UserId)).Returns((Order)null); Fixture.OrderComposerMock.Setup(r => r.Create(command.UserId)).Returns(order); Fixture.ProductRepositoryMock.Setup(r => r.GetById(command.ProductId)).Returns(product); //Act var result = handler.Handle(command); //Assert Fixture.OrderAdoRepositoryMock.Verify(r => r.GetLastCreatedOrderByUserId(command.UserId), Times.Once); Fixture.OrderComposerMock.Verify(r => r.Create(command.UserId), Times.Once); Fixture.ProductRepositoryMock.Verify(r => r.GetById(command.ProductId), Times.Once); Fixture.OrderAdoRepositoryMock.Verify(r => r.Save(order), Times.Once); Fixture.OrderItemAdoRepositoryMock.Verify(r => r.Save(It.IsAny <OrderItem>()), Times.Once); result.Should().BeOfType <ReturnedItemCommandResult>(); }
public Order GetValidOrderWithOrderItems() { var order = GeneratedObjectsTests.GenerateOrder(); var product = GeneratedObjectsTests.GenerateProduct(1M); order.AddItem(product, 1); return(order); }
public void ShouldAddItemInvalid() { var order = GeneratedObjectsTests.GenerateOrder(); var product = GeneratedObjectsTests.GenerateProduct(1M); order.AddItem(product, 1000); var result = order.Valid; result.Should().BeFalse(); order.Notifications.FirstOrDefault()?.Message.Should().Be("The total weight is greater than 3kg allowed."); }
public void ShouldAddItemValid() { var order = GeneratedObjectsTests.GenerateOrder(); var product = GeneratedObjectsTests.GenerateProduct(2M); order.AddItem(product, 1); var result = order.Valid; result.Should().BeTrue(); order.Notifications.Should().HaveCount(0); }
public void OrderShouldBeFailedProductIsOverweight() { //Arrange var handler = Fixture.GetOrderHandler(); var command = GeneratedObjectsTests.GenerateAddItemCommand(1); var order = Fixture.GetValidOrderWithOrderItems(); var product = GeneratedObjectsTests.GenerateProduct(10M); Fixture.OrderAdoRepositoryMock.Setup(r => r.GetLastCreatedOrderByUserId(command.UserId)).Returns(order); Fixture.ProductRepositoryMock.Setup(r => r.GetById(command.ProductId)).Returns(product); //Act var result = handler.Handle(command); //Assert Fixture.OrderAdoRepositoryMock.Verify(r => r.GetLastCreatedOrderByUserId(command.UserId), Times.Once); Fixture.ProductRepositoryMock.Verify(r => r.GetById(command.ProductId), Times.Once); result.Should().BeNull(); handler.Notifications.Should().HaveCount(1); handler.Notifications.First().Message.Should().Be("The total weight is greater than 3kg allowed."); }