public void CreateReoccuringPayment_ValidReoccuringPayment_AddsReoccuringPayment()
        {
            ReoccuringPayment newReoccuringPayment = new ReoccuringPayment()
            {
                Id        = Guid.NewGuid(),
                Amount    = new decimal(123.123),
                StartDate = DateTime.Now.AddDays(-17).ToString("yyyy-MM-dd"),
                Tags      = new List <Tag>()
                {
                    reoccuringPayment1.Tags.First(),
                              reoccuringPayment2.Tags.First(t => t.Type.Equals(TagType.Secondary))
                },
                Title = "ReoccuringPayment B"
            };

            foreach (var tag in newReoccuringPayment.Tags)
            {
                tag.ReoccuringPayments.Add(newReoccuringPayment);
            }

            var service = new PaymentService(context, contextAccessorMock.Object);

            var result             = service.CreateReoccuringPayment(newReoccuringPayment);
            var ReoccuringPayments = service.GetAllReoccuringPayments().ToList();

            Assert.IsTrue(ReoccuringPayments.Any(p => p.Id.Equals(newReoccuringPayment.Id)));
            Assert.AreEqual(newReoccuringPayment.Tags.Count, ReoccuringPayments.Single(p => p.Id.Equals(newReoccuringPayment.Id)).Tags.Count);
        }
        public ReoccuringPayment CreateReoccuringPayment(ReoccuringPayment payment)
        {
            payment.Tags = GetTrackedTagsList(payment.Tags);

            _context.ReoccuringPayments.Add(payment);
            _context.SaveChanges();

            return(payment);
        }
예제 #3
0
        public static ReoccuringPayment RemoveCycle(this ReoccuringPayment payment)
        {
            if (payment.Tags != null)
            {
                foreach (var t in payment.Tags)
                {
                    ClearPaymentsInTag(t);
                }
            }

            return(payment);
        }
        public ActionResult <ReoccuringPayment> CreateOrUpdateReoccuringPayment(ReoccuringPayment payment)
        {
            if (payment.Id.Equals(Guid.Empty))
            {
                return(Ok(paymentService.CreateReoccuringPayment(payment).RemoveCycle()));
            }
            else
            {
                if (paymentService.GetReoccuringPaymentById(payment.Id) == null)
                {
                    return(NotFound());
                }

                return(Ok(paymentService.UpdateReoccuringPayment(payment).RemoveCycle()));
            }
        }
        public ReoccuringPayment UpdateReoccuringPayment(ReoccuringPayment payment)
        {
            ReoccuringPayment paymentById = GetReoccuringPaymentById(payment.Id, true);

            if (paymentById == null)
            {
                return(null);
            }

            paymentById.Amount         = payment.Amount;
            paymentById.Title          = payment.Title;
            paymentById.StartDate      = payment.StartDate;
            paymentById.EndDate        = payment.EndDate;
            paymentById.ReoccuringType = payment.ReoccuringType;
            paymentById.Tags           = GetTrackedTagsList(payment.Tags);

            _context.SaveChanges();

            return(paymentById);
        }