public async Task Order_has_been_placed_for_customer() { var currency = Currency.CanadianDollar; var productPrice = 12.5; var productQuantity = 10; var customerEmail = "*****@*****.**"; var productMoney = Money.Of(Convert.ToDecimal(productPrice), currency.Code); _currencyConverter.Convert(currency, Money.Of(Convert.ToDecimal(productPrice * productQuantity), currency.Code)) .Returns(productMoney); var customerUniquenessChecker = Substitute.For <ICustomerUniquenessChecker>(); customerUniquenessChecker.IsUserUnique(customerEmail).Returns(true); var customerId = new CustomerId(Guid.NewGuid()); var customer = Customer.CreateNew(customerEmail, "Customer X", customerUniquenessChecker); _customers.GetById(Arg.Any <CustomerId>()).Returns(customer); var product = Product.CreateNew("Product X", productMoney); _products.GetById(Arg.Any <ProductId>()).Returns(product); var productData = new QuoteItemProductData(product.Id, product.Price, productQuantity); var quote = Quote.CreateNew(customerId); quote.AddItem(productData); List <Product> products = new List <Product>() { product }; _quotes.GetById(quote.Id).Returns(quote); _products.GetByIds(Arg.Any <List <ProductId> >()).Returns(products); var placeOrderCommandHandler = new PlaceOrderCommandHandler(_unitOfWork, _currencyConverter); var placeOrderCommand = new PlaceOrderCommand(quote.Id.Value, customerId.Value, currency.Code); var orderResult = await placeOrderCommandHandler.Handle(placeOrderCommand, CancellationToken.None); await _unitOfWork.Received(1).CommitAsync(Arg.Any <CancellationToken>()); orderResult.Should().NotBe(Guid.Empty); }
public async Task Quote_has_been_created_for_costumer() { var currency = Currency.USDollar; var productPrice = 12.5; var productQuantity = 10; var customerEmail = "*****@*****.**"; var customerUniquenessChecker = Substitute.For <ICustomerUniquenessChecker>(); customerUniquenessChecker.IsUserUnique(customerEmail).Returns(true); var productMoney = Money.Of(Convert.ToDecimal(productPrice), currency.Code); var customer = await Customer .CreateNew(customerEmail, "Customer X", customerUniquenessChecker); _customers .GetById(Arg.Any <CustomerId>()).Returns(customer); var product = Product.CreateNew("Product X", productMoney); _products.GetById(Arg.Any <ProductId>()).Returns(product); var handler = new CreateQuoteCommandHandler(_unitOfWork); var command = new CreateQuoteCommand(customer.Id.Value, new ProductDto(product.Id.Value, productQuantity)); var result = await handler.Handle(command, CancellationToken.None); await _quotes.Received(1) .Add(Arg.Is((Quote c) => c.Id.Value == result.Id), Arg.Any <CancellationToken>()); await _customers.Received(1) .GetById(customer.Id, Arg.Any <CancellationToken>()); await _unitOfWork.Received(1) .CommitAsync(Arg.Any <CancellationToken>()); result.Should().NotBe(Guid.Empty); }