public async Task <IActionResult> Get()
        {
            var command = new GetPaymentsQuery();
            var result  = await _mediatr.Send(command);

            return(result != null ? (IActionResult)Ok(result) : NotFound(new { message = "Data not found" }));
        }
Example #2
0
        public async Task Should_ReturnPayments_By_CombinedFilter()
        {
            var date    = new DateTime(2018, 2, 18);
            var details = "details";

            //One with everything but with category
            DbContentBuilder.Payment().WithDate(date).WithDetails(details).WithCategory(new Category()).Build();
            //One excellent
            DbContentBuilder.Payment().WithDate(date).WithDetails(details).Build();
            //Only date wrong
            DbContentBuilder.Payment().WithDate(date.AddDays(1)).WithDetails(details).Build();
            //Only details wrong
            DbContentBuilder.Payment().WithDate(date).WithDetails(details.Substring(1)).Build();

            DbContentBuilder.Payment().WithCategory(new Category()).Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                WithEmptyCategory   = true,
                DateFrom            = date,
                DateTo              = date,
                WithPhraseInDetails = details
            };

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            Assert.AreEqual(1, payments.Length);
        }
Example #3
0
        public async Task <ActionResult <AccountViewModel> > GetPaymentsAsync([FromHeader(Name = "ACCOUNT_KEY")] Guid accountId)
        {
            var query   = new GetPaymentsQuery(accountId);
            var account = await _mediator.Send(query);

            return(account);
        }
Example #4
0
        public async Task Handle_ReturnsCorrectPaymentsAndListCount()
        {
            var query = new GetPaymentsQuery();

            var handler = new GetPaymentsQuery.GetPaymentsQueryHandler(_context, _mapper);

            var result = await handler.Handle(query, CancellationToken.None);

            result.ShouldBeOfType <PaymentsVm>();
            result.Payments.Count.ShouldBe(0);
        }
Example #5
0
        public async Task Should_ReturnPayments_With_SpecificDetails()
        {
            DbContentBuilder.Payment().WithDetails("Buy beer in dopio").Build();
            DbContentBuilder.Payment().WithDetails("Buy coffee in dopio").Build();
            DbContentBuilder.Payment().WithDetails("Dopio lunch").Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                WithPhraseInDetails = "dopio"
            };

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            Assert.AreEqual(3, payments.Length);
        }
 public async Task <BaseDto <List <Payment_Output> > > Handle(GetPaymentsQuery request, CancellationToken cancellationToken)
 {
     return(new BaseDto <List <Payment_Output> >
     {
         message = "Success Retrieve Payment Datas",
         success = true,
         data = await _context.payments.Select(s => new Payment_Output
         {
             order_id = s.order_id,
             transaction_id = s.transaction_id,
             payment_type = s.payment_type,
             gross_amount = Convert.ToInt32(s.gross_amount),
             transaction_time = s.transaction_time,
             transaction_status = s.transaction_status
         }).ToListAsync()
     });
 }
Example #7
0
        public async Task Should_ReturnPayments_Without_Category()
        {
            DbContentBuilder.Payment().WithCategory(null).Build();
            DbContentBuilder.Payment().WithCategory(null).Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                WithEmptyCategory = true
            };
            var ct = _context.ChangeTracker;

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            var paymentsWithoutCategory = _context.Payments.Where(payment => payment.Category == null).ToArray();

            Assert.AreEqual(paymentsWithoutCategory.Length, payments.Length);
            CollectionAssert.AreEquivalent(paymentsWithoutCategory, payments);
        }
Example #8
0
        public async Task Should_ReturnPayments_For_SpecificDay()
        {
            var date = new DateTime(2018, 2, 18);

            DbContentBuilder.Payment().WithDate(date.AddDays(1)).Build();
            DbContentBuilder.Payment().WithDate(date.AddDays(-1)).Build();
            DbContentBuilder.Payment().WithDate(date).Build();
            DbContentBuilder.Payment().WithDate(date).Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                DateFrom = date,
                DateTo   = date
            };

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            Assert.AreEqual(2, payments.Length);
        }
Example #9
0
        public async Task Should_ReturnPayments_With_SpecificDetailsAlias()
        {
            var d1 = DbContentBuilder.Details().WithDetails("1").WithAlias("Buy beer in dopio").Build();
            var d2 = DbContentBuilder.Details().WithDetails("2").WithAlias("Buy coffee in dopio").Build();
            var d3 = DbContentBuilder.Details().WithDetails("3").WithAlias("Buy coffee in MC").Build();

            DbContentBuilder.Payment().WithDetails(d1).Build();
            DbContentBuilder.Payment().WithDetails(d2).Build();
            DbContentBuilder.Payment().WithDetails(d3).Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                WithPhraseInDetails = "dopio"
            };

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            Assert.AreEqual(2, payments.Length);
        }
Example #10
0
        public async void Handle_ShouldReturnViewModel()
        {
            var accountsRepo = new Mock <IAccountRepository>();
            var account      = new Account(Guid.NewGuid(), 100);

            account.AddPaymentRequest(new DateTime(2020, 3, 1), 40);

            accountsRepo.Setup(a => a.GetAsync(account.Id)).ReturnsAsync(account);

            var handler = new GetPaymentsHandler(accountsRepo.Object);

            var query     = new GetPaymentsQuery(account.Id);
            var viewModel = await handler.Handle(query, new CancellationToken());

            Assert.Equal(account.Balance, viewModel.Balance);
            Assert.Equal(account.PaymentRequests.First().Amount, viewModel.Payments.First().Amount);
            Assert.Equal(account.PaymentRequests.First().Date, viewModel.Payments.First().Date);
            Assert.Equal(account.PaymentRequests.First().Reason, viewModel.Payments.First().Reason);
            Assert.Equal(account.PaymentRequests.First().Status.ToString(), viewModel.Payments.First().Status);
        }
Example #11
0
        public async Task Should_ReturnPayments_Before_SpecificDay()
        {
            var date = new DateTime(2018, 2, 18);

            DbContentBuilder.Payment().WithDate(date.AddDays(1)).Build();
            DbContentBuilder.Payment().WithDate(date.AddDays(-1)).Build();
            DbContentBuilder.Payment().WithDate(date).Build();
            DbContentBuilder.Payment().WithDate(date).Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                DateTo = date,
            };

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            var paymentsBefore = _context.Payments.Where(payment => payment.Date <= date).ToArray();

            Assert.AreEqual(paymentsBefore.Length, payments.Length);
            CollectionAssert.AreEquivalent(paymentsBefore, payments);
        }
Example #12
0
        public async Task <ActionResult> Get()
        {
            var notif = new GetPaymentsQuery();

            return(Ok(await _mediatr.Send(notif)));
        }
Example #13
0
        public async Task <ActionResult <GetPaymentsDto> > Get()
        {
            var result = new GetPaymentsQuery();

            return(Ok(await _mediatr.Send(result)));
        }
Example #14
0
 public async Task <IEnumerable <Payment> > Handle(GetPaymentsQuery request, CancellationToken cancellationToken)
 {
     return(await _repository.GetAllAsync());
 }