public function testSavePaymentInformationAndPlaceOrder()
 {
     $cartId = 100;
     $orderId = 200;
     $email = '*****@*****.**';
     $paymentMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\PaymentInterface');
     $billingAddressMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\AddressInterface');
     $billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf();
     $this->billingAddressManagementMock->expects($this->once())->method('assign')->with($cartId, $billingAddressMock);
     $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
     $this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId);
     $this->assertEquals($orderId, $this->model->savePaymentInformationAndPlaceOrder($cartId, $email, $paymentMock, $billingAddressMock));
 }
 /**
  * @expectedExceptionMessage Cannot place order
  * @expectedException \Magento\Framework\Exception\CouldNotSaveException
  */
 public function testSavePaymentInformationAndPlaceOrderException()
 {
     $cartId = 100;
     $email = '*****@*****.**';
     $paymentMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\PaymentInterface');
     $billingAddressMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\AddressInterface');
     $billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf();
     $this->billingAddressManagementMock->expects($this->once())->method('assign')->with($cartId, $billingAddressMock);
     $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
     $exception = new CouldNotSaveException(__('DB exception'));
     $this->cartManagementMock->expects($this->once())->method('placeOrder')->willThrowException($exception);
     $this->model->savePaymentInformationAndPlaceOrder($cartId, $email, $paymentMock, $billingAddressMock);
 }