public async Task Execute_WhenCommandValid_CallsAquiringBankService() { const int MERCHANT_ID = 4; AddBankPaymentCommand addBankPaymentCommand = null; var aquiringBankService = new Mock <MockAquiringBankService>(); aquiringBankService .Setup(m => m.MakePaymentAsync(It.IsAny <AddBankPaymentCommand>())) .Callback <AddBankPaymentCommand>(c => addBankPaymentCommand = c) .CallBase(); var userSessionService = new Mock <IUserSessionService>(); userSessionService .Setup(m => m.GetCurrentMerchantId()) .Returns(MERCHANT_ID); var handler = new AddPaymentCommandHandler( NullLogger <AddPaymentCommandHandler> .Instance, aquiringBankService.Object, userSessionService.Object, new InMemoryPaymentsRepository(NullLogger <InMemoryPaymentsRepository> .Instance) ); var command = AddPaymentCommandValidatorTests.CreateValidCommand(); await handler.ExecuteAsync(command); Assert.Equal(command.CreditCard, addBankPaymentCommand.CreditCard); Assert.Equal(MERCHANT_ID, addBankPaymentCommand.MerchantId); Assert.True(addBankPaymentCommand.PaymentId > 0); }
public virtual Task <BankPaymentResponse> MakePaymentAsync(AddBankPaymentCommand command) { // threadsafe id increment because the repository is singleton scope var bankPaymentId = Interlocked.Increment(ref _currentId); var response = new BankPaymentResponse() { BankPaymentId = bankPaymentId.ToString(), Result = PaymentStatus.Paid }; return(Task.FromResult(response)); }