public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Payment.BillInstance.BillTemplate.User = await _userManager.GetUserAsync(HttpContext.User);

            await _paymentService.AddAsync(Payment);

            return(RedirectToPage("./Index"));
        }
        public void AddPaymentTwoArgumentCorrectly()
        {
            var dbContext = new DbContextOptionsBuilder <ApplicationDbContext>()
                            .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var repository = new EfDeletableEntityRepository <Payment>(new ApplicationDbContext(dbContext.Options));

            repository.SaveChangesAsync().GetAwaiter().GetResult();

            var service = new PaymentService(repository);

            _ = service.AddAsync(1000, "Plategno 125/15.04.2020");
            var list = repository.All().ToList();

            Assert.Single(list);
            Assert.Equal(1000, list[0].AmountPaid);
            Assert.Equal("Plategno 125/15.04.2020", list[0].DocumentNumber);
        }
        public async Task <IActionResult> OnPostAddPayment(int?billInstanceID, int?billPayID)
        {
            if (billPayID == null || billInstanceID == null)
            {
                return(NotFound());
            }

            //Ensure parameters belong to current user
            BillInstance instance = await _billService.GetBillInstanceAsync((int)billInstanceID);

            if (instance == null)
            {
                return(NotFound());
            }

            SimpleBillPay.Models.BillPay billPay = await _billPayService.GetByIdAsync((int)billPayID);

            if (billPay == null)
            {
                return(NotFound());
            }

            //Add new payment with this bill instance and attached to this bill pay
            Payment payment = new Payment();

            payment.BillInstance = instance;

            payment.Amount        = (instance.Amount - instance.Payments.Sum(p => p.Amount));
            payment.PaymentDate   = billPay.BillPayDate;
            payment.DateConfirmed = null;
            payment.BillPay       = billPay;

            await _paymentService.AddAsync(payment);

            //Call get method to rebuild page
            return(Redirect("./Edit?id=" + billPayID.ToString()));
        }
        public async Task AddPaymentAsync()
        {
            //Arrange
            var fakeEventBus = new Mock <IEventBus>();
            var fakeGateWay  = new Mock <IPaymentExternalGateway>();

            PaymentDTO payment = new PaymentDTO();

            payment.BookingOrderId = "1e4199f0-907f-4acc-b886-b12b0323c108";
            payment.Price          = 100;
            payment.CustomerId     = string.Empty;

            var sut = new PaymentService(_repo, fakeGateWay.Object, fakeEventBus.Object);

            //Act
            var result = await sut.AddAsync(payment);

            //Assert
            Guid bookingRef = Guid.Parse(result);

            result.ShouldBeOfType <string>();
            bookingRef.ShouldBeOfType <Guid>();
            result.Count().ShouldBe(36);
        }