public async Task GetByIdAsync_NotFound_ReturnsNull() { // arrange var id = new Guid(); PaymentRepositoryMock .Setup(m => m.GetByIdAsync(id)) .ReturnsAsync((Payment)null); // act var actual = await SUT.GetByIdAsync(id); // assert actual.Should().BeNull(); }
public async Task GetByIdAsync_HappyPath_ReturnsGetPayment() { // arrange var id = new Guid(); var payment = Fixture.Create <Payment>(); var expected = new GetPayment(payment); PaymentRepositoryMock .Setup(m => m.GetByIdAsync(id)) .ReturnsAsync(payment); // act var actual = await SUT.GetByIdAsync(id); // assert actual.Should().BeEquivalentTo(expected); }
public async Task CreateAsync_HappyPath_AddsToCommandQueue() { // arrange var createPayment = Fixture.Create <CreatePayment>(); var payment = Fixture.Create <Payment>(); PaymentRepositoryMock .Setup(m => m.CreateAsync(createPayment)) .ReturnsAsync(payment); // act await SUT.CreateAsync(createPayment); // assert CommandQueueMock .Setup(m => m.QueueCommand(It.Is <SubmitPaymentCommand>(c => c.PaymentId == payment.Id))); }
public async Task ProcessPaymentAsync_HappyPath_SetsOrderStatus() { // arrange var command = Fixture.Create <SubmitPaymentCommand>(); var payment = Fixture.Create <Payment>(); PaymentRepositoryMock .Setup(m => m.GetByIdAsync(command.PaymentId)) .ReturnsAsync(payment); BankServiceClientMock .Setup(m => m.CreateOrderAsync(command)) .ReturnsAsync(new BankPaymentResponse { IsSuccessful = true, Id = Guid.NewGuid() }); // act await SUT.ProcessPaymentAsync(command); // assert PaymentRepositoryMock .Verify(m => m.UpdateAsync(It.Is <Payment>(p => p.Id == payment.Id && p.PaymentStatus == PaymentStatus.Success))); }
public async Task ProcessPaymentAsync_HappyPath_ReportsToTelemetry() { // arrange var command = Fixture.Create <SubmitPaymentCommand>(); var payment = Fixture.Create <Payment>(); var bankPaymentResponse = new BankPaymentResponse { IsSuccessful = true, Id = Guid.NewGuid() }; PaymentRepositoryMock .Setup(m => m.GetByIdAsync(command.PaymentId)) .ReturnsAsync(payment); BankServiceClientMock .Setup(m => m.CreateOrderAsync(command)) .ReturnsAsync(bankPaymentResponse); // act await SUT.ProcessPaymentAsync(command); // assert TelemetrySubmitterMock .Verify(m => m.SubmitAsync(It.IsAny <ServiceOperation>())); }
public async Task ProcessPaymentAsync_OnBankError_ReportsToTelemetry() { // arrange var command = Fixture.Create <SubmitPaymentCommand>(); var payment = Fixture.Create <Payment>(); var bankPaymentResponse = new BankPaymentResponse { IsSuccessful = true, Id = Guid.NewGuid() }; PaymentRepositoryMock .Setup(m => m.GetByIdAsync(command.PaymentId)) .ReturnsAsync(payment); BankServiceClientMock .Setup(m => m.CreateOrderAsync(command)) .ThrowsAsync(new InvalidOperationException()); // act await SUT.ProcessPaymentAsync(command); // assert TelemetrySubmitterMock .Verify(m => m.SubmitAsync(It.Is <ServiceOperation>(o => o.IsFaulted == 1))); }