public async Task Handler_GivenValidCondition_ShouldFindPayments()
        {
            // Save payments
            var payments = new[]
            {
                new Payment(1, "cardholder1", "1111-2222-3333-4444", "12/22", "111", 1000),
                new Payment(1, "cardholder1", "1111-2222-3333-4444", "12/22", "111", 2000),
                new Payment(1, "cardholder1", "1111-2222-3333-4444", "12/22", "111", 3000)
            };

            await context.Payments.AddRangeAsync(payments);

            await context.CommitAsync(CancellationToken.None);

            var query = new GetPaymentsListQuery
            {
                MerchantId = 1,
                CardNumber = "1111-2222-3333-4444"
            };
            var sut    = new GetPaymentsListQuery.Handler(context, mapper);
            var result = await sut.Handle(query, CancellationToken.None);

            result.Should().BeOfType <PaymentsListVm>();
            result.Payments.Count.Should().Be(3);
        }
Esempio n. 2
0
        public async Task Handler_GivenNotExistingId_ShouldThrowException()
        {
            var payment = new Payment(1, "cardholder1", "1111-2222-3333-4444", "12/22", "111", 1000);

            await context.Payments.AddAsync(payment);

            await context.CommitAsync(CancellationToken.None);

            var randomId = new Guid("0f7d4d5e-74d2-49b3-823e-f41dace79557");
            var query    = new GetPaymentDetailQuery
            {
                Id = randomId
            };
            var sut = new GetPaymentDetailQuery.Handler(context, mapper);

            await sut.Invoking(async h => await h.Handle(query, CancellationToken.None))
            .Should().ThrowAsync <EntityNotFoundException>()
            .WithMessage($"Entity \"Payment\" ({randomId}) was not found.");
        }