public void Handle_GivenInvalidId_ThrowsException() { var query = new GetPaymentQuery { Id = 99 }; var sut = new GetPaymentQueryHandler(_repository, Mapper); Assert.ThrowsAsync <NotFoundException>(() => sut.Handle(query, CancellationToken.None)); }
public async Task Handle_GivenValidId_ReturnsCorrectVm() { var query = new GetPaymentQuery { Id = 1 }; var sut = new GetPaymentQueryHandler(_repository, Mapper); var result = await sut.Handle(query, CancellationToken.None); result.Should().BeOfType <PaymentVm>(); result.Id.Should().Be(1); }
public async Task Return_Error_Result_If_Payment_NotFound() { var paymentId = Guid.NewGuid().ToString(); var mockPaymentRepository = new Mock <IReadOnlyRepository <Payment> >(); var mockLogger = new Mock <ILogger>(); mockPaymentRepository.Setup(x => x.FindBy(It.IsAny <Guid>())) .ReturnsAsync(null as Payment); var mockCyptoService = new Mock <ICryptoService>(); var sut = new GetPaymentQueryHandler(mockPaymentRepository.Object, mockCyptoService.Object, mockLogger.Object); var result = await sut.Handle(new GetPaymentQuery { PaymentId = paymentId }, new System.Threading.CancellationToken()) as ErrorResult; result.Message.Should().Be($"There is no payment with id: {paymentId}"); }
public async Task Get_Payment_Details() { var paymentId = Guid.NewGuid().ToString(); var payment = GivenPayment(paymentId); var mockPaymentRepository = new Mock <IReadOnlyRepository <Payment> >(); var mockLogger = new Mock <ILogger>(); mockPaymentRepository.Setup(x => x.FindBy(It.IsAny <Guid>())) .ReturnsAsync(payment); var mockCyptoService = new Mock <ICryptoService>(); mockCyptoService.Setup(x => x.Decrypt(payment.CardNumber, It.IsAny <string>())) .Returns(cardNumber); var sut = new GetPaymentQueryHandler(mockPaymentRepository.Object, mockCyptoService.Object, mockLogger.Object); var result = await sut.Handle(new GetPaymentQuery { PaymentId = paymentId }, new System.Threading.CancellationToken()) as SuccessResult; result.Amount.Should().Be(payment.Amount); result.PaymentDate.Should().Be(payment.CreatedDate); result.Currency.Should().Be(payment.Currency); result.CardNumber.Should().Be(cardNumber.Mask()); }