Esempio n. 1
0
        public void UpdateRecurringPayment_CreationTimeSame()
        {
            // Arrange
            DateTime                startDate  = DateTime.Now.AddDays(-1);
            DateTime                endDate    = DateTime.Now;
            const int               amount     = 123;
            const PaymentType       type       = PaymentType.Income;
            const PaymentRecurrence recurrence = PaymentRecurrence.Daily;
            var          account = new Account("foo");
            const string note    = "asdf";

            var recurringPayment = new RecurringPayment(startDate,
                                                        65,
                                                        type,
                                                        PaymentRecurrence.Monthly,
                                                        new Account("1111"),
                                                        "foo");

            DateTime creationTime = recurringPayment.CreationTime;

            // Act
            recurringPayment.UpdateRecurringPayment(amount, recurrence, account, note, endDate);

            // Assert
            recurringPayment.CreationTime.ShouldEqual(creationTime);
        }
Esempio n. 2
0
        public void CheckIfRepeatable_UnclearedPayment_ReturnFalse(
            PaymentRecurrence recurrence, int amountOfDaysUntilRepeat)
        {
            var account = new AccountEntity {
                Id = 2
            };

            var recurringPayment = new RecurringPaymentEntity
            {
                Id               = 4,
                Recurrence       = PaymentRecurrence.Weekly,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(new Payment
            {
                Data =
                {
                    Date             = DateTime.Today.AddDays(amountOfDaysUntilRepeat),
                    RecurringPayment = recurringPayment
                }
            })
            .ShouldBeFalse();
        }
        public void GetRecurringFromPayment_Endless(PaymentRecurrence recurrence, PaymentType type)
        {
            var startDate = new DateTime(2015, 03, 12);
            var enddate = Convert.ToDateTime("7.8.2016");

            var payment = new PaymentViewModel
            {
                ChargedAccount = new AccountViewModel {Id = 3},
                TargetAccount = new AccountViewModel {Id = 8},
                Category = new CategoryViewModel {Id = 16},
                Date = startDate,
                Amount = 2135,
                IsCleared = false,
                Type = type,
                IsRecurring = true
            };

            var recurring = RecurringPaymentHelper.GetRecurringFromPayment(payment, true,
                recurrence, enddate);

            recurring.ChargedAccount.Id.ShouldBe(3);
            recurring.TargetAccount.Id.ShouldBe(8);
            recurring.StartDate.ShouldBe(startDate);
            recurring.EndDate.ShouldBe(enddate);
            recurring.IsEndless.ShouldBe(true);
            recurring.Amount.ShouldBe(payment.Amount);
            recurring.Category.Id.ShouldBe(payment.Category.Id);
            recurring.Type.ShouldBe(type);
            recurring.Recurrence.ShouldBe(recurrence);
            recurring.Note.ShouldBe(payment.Note);
        }
Esempio n. 4
0
        public void GetPaymentFromRecurring_CorrectMappedPayment(PaymentRecurrence recurrence)
        {
            var account = new AccountEntity {
                Id = 2
            };

            var recurringPayment = new RecurringPayment
            {
                Data =
                {
                    Id               =                 4,
                    Recurrence       = recurrence,
                    StartDate        = new DateTime(2015, 08, DateTime.Today.Day),
                    ChargedAccountId =                 2,
                    ChargedAccount   = account,
                    Amount           = 105
                }
            };

            var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment);

            result.Data.ChargedAccount.ShouldBe(account);
            result.Data.ChargedAccountId.ShouldBe(account.Id);
            result.Data.Amount.ShouldBe(105);
            result.Data.Date.ShouldBe(DateTime.Today);
        }
Esempio n. 5
0
        public RecurringPayment(DateTime startDate,
                                double amount,
                                PaymentType type,
                                PaymentRecurrence recurrence,
                                Account chargedAccount,
                                string note           = "",
                                DateTime?endDate      = null,
                                Account targetAccount = null,
                                Category category     = null)
        {
            if (!IsEndless && endDate != null && endDate < DateTime.Today)
            {
                throw new MoneyFoxInvalidEndDateException();
            }

            ChargedAccount = chargedAccount ?? throw new ArgumentNullException(nameof(chargedAccount));
            StartDate      = startDate;
            Amount         = amount;
            Type           = type;
            Recurrence     = recurrence;
            Note           = note;
            Category       = category;
            TargetAccount  = targetAccount;
            IsEndless      = endDate == null;
        }
        public void Ctor_Params_ValuesAssigned()
        {
            // Arrange
            var                     startDate  = DateTime.Now;
            const int               amount     = 123;
            const PaymentType       type       = PaymentType.Expense;
            const PaymentRecurrence recurrence = PaymentRecurrence.Daily;
            var                     account    = new Account("foo");
            const string            note       = "asdf";

            // Act
            var recurringPayment = new RecurringPayment(startDate,
                                                        amount,
                                                        type,
                                                        recurrence,
                                                        account,
                                                        note);

            // Assert
            recurringPayment.StartDate.ShouldEqual(startDate);
            recurringPayment.IsEndless.ShouldBeTrue();
            recurringPayment.Amount.ShouldEqual(amount);
            recurringPayment.Type.ShouldEqual(type);
            recurringPayment.Recurrence.ShouldEqual(recurrence);
            recurringPayment.ChargedAccount.ShouldEqual(account);
            recurringPayment.Note.ShouldEqual(note);
        }
        public static string GetStringForPaymentRecurrence(PaymentRecurrence passedEnum)
        {
            switch (passedEnum)
            {
            case PaymentRecurrence.Daily:
                return(Strings.DailyLabel);

            case PaymentRecurrence.DailyWithoutWeekend:
                return(Strings.DailyWithoutWeekendLabel);

            case PaymentRecurrence.Weekly:
                return(Strings.WeeklyLabel);

            case PaymentRecurrence.Biweekly:
                return(Strings.BiweeklyLabel);

            case PaymentRecurrence.Monthly:
                return(Strings.MonthlyLabel);

            case PaymentRecurrence.Bimonthly:
                return(Strings.BimonthlyLabel);

            case PaymentRecurrence.Quarterly:
                return(Strings.QuarterlyLabel);

            case PaymentRecurrence.Biannually:
                return(Strings.BiannuallyLabel);

            case PaymentRecurrence.Yearly:
                return(Strings.YearlyLabel);

            default:
                return(string.Empty);
            }
        }
Esempio n. 8
0
        public RecurringPayment(DateTime startDate,
                                decimal amount,
                                PaymentType type,
                                PaymentRecurrence recurrence,
                                Account chargedAccount,
                                string note                    = "",
                                DateTime?endDate               = null,
                                Account?targetAccount          = null,
                                Category?category              = null,
                                DateTime?lastRecurrenceCreated = null)
        {
            if (!IsEndless && endDate != null && endDate < DateTime.Today)
            {
                throw new InvalidEndDateException();
            }

            ChargedAccount = chargedAccount ?? throw new ArgumentNullException(nameof(chargedAccount));
            StartDate      = startDate;
            EndDate        = endDate;
            Amount         = amount;
            Type           = type;
            Recurrence     = recurrence;
            Note           = note;
            Category       = category;
            TargetAccount  = targetAccount;
            IsEndless      = endDate == null;

            RelatedPayments = new List <Payment>();

            LastRecurrenceCreated = lastRecurrenceCreated ?? DateTime.Now;
            ModificationDate      = DateTime.Now;
            CreationTime          = DateTime.Now;
        }
        public void SaveCommand_Recurrence_RecurrenceSetCorrectly(PaymentRecurrence recurrence)
        {
            // Arrange
            var testPayment = new Payment();

            var settingsManagerMock = new Mock <ISettingsManager>();

            settingsManagerMock.SetupAllProperties();

            var paymentServiceMock = new Mock <IPaymentService>();

            paymentServiceMock.Setup(x => x.SavePayment(It.IsAny <Payment>()))
            .Callback((Payment payment) => testPayment = payment)
            .Returns(Task.CompletedTask);

            var viewmodel = new ModifyPaymentViewModel(paymentServiceMock.Object,
                                                       new Mock <IAccountService>().Object,
                                                       new Mock <IDialogService>().Object,
                                                       settingsManagerMock.Object,
                                                       new Mock <IMvxMessenger>().Object,
                                                       new Mock <IBackupManager>().Object);

            viewmodel.Init(PaymentType.Income);
            viewmodel.SelectedPayment.ChargedAccount = new AccountViewModel(new Account());
            viewmodel.SelectedPayment.IsRecurring    = true;
            viewmodel.Recurrence = recurrence;

            // Act
            viewmodel.SaveCommand.Execute();

            // Assert
            testPayment.Data.RecurringPayment.ShouldNotBeNull();
            testPayment.Data.RecurringPayment.Recurrence.ShouldBe(recurrence);
        }
Esempio n. 10
0
        [InlineData(PaymentRecurrence.Quarterly, 355, true)]  // with year change
        public void CheckIfRepeatable_ValidatedRecurrence(PaymentRecurrence recurrence, int amountOfDaysPassed,
                                                          bool expectedResult)
        {
            var account = new AccountEntity {
                Id = 2
            };

            var recurringPayment = new RecurringPaymentEntity
            {
                Id               = 4,
                Recurrence       = recurrence,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(
                new Payment
            {
                Data =
                {
                    Date             = DateTime.Today.AddDays(-amountOfDaysPassed),
                    IsCleared        = true,
                    RecurringPayment = recurringPayment
                }
            })
            .ShouldBe(expectedResult);
        }
        public void UpdateRecurringPayment_ValuesAssigned()
        {
            // Arrange
            var                     startDate  = DateTime.Now.AddDays(-1);
            var                     endDate    = DateTime.Now;
            const int               amount     = 123;
            const PaymentType       type       = PaymentType.Income;
            const PaymentRecurrence recurrence = PaymentRecurrence.Daily;
            var                     account    = new Account("foo");
            const string            note       = "asdf";

            var recurringPayment = new RecurringPayment(startDate,
                                                        65,
                                                        type,
                                                        PaymentRecurrence.Monthly,
                                                        new Account("1111"),
                                                        "foo");

            // Act
            recurringPayment.UpdateRecurringPayment(amount, recurrence, account, note, endDate);

            // Assert
            recurringPayment.StartDate.ShouldEqual(startDate);
            recurringPayment.EndDate.ShouldEqual(endDate);
            recurringPayment.Amount.ShouldEqual(amount);
            recurringPayment.Type.ShouldEqual(type);
            recurringPayment.Recurrence.ShouldEqual(recurrence);
            recurringPayment.ChargedAccount.ShouldEqual(account);
            recurringPayment.Note.ShouldEqual(note);
        }
        public void CheckIfRepeatable_UnclearedPayment_ReturnFalse(PaymentRecurrence recurrence, int amountOfDaysUntilRepeat)
        {
            var account = new Account("foo");

            var payment = new Payment(DateTime.Today.AddDays(amountOfDaysUntilRepeat), 105, PaymentType.Expense, account);

            payment.AddRecurringPayment(recurrence, DateTime.Today);

            RecurringPaymentHelper.CheckIfRepeatable(payment)
            .ShouldBeFalse();
        }
        [InlineData(PaymentRecurrence.Quarterly, 355, true)]  // with year change
        public void CheckIfRepeatable_ValidatedRecurrence(PaymentRecurrence recurrence, int amountOfDaysPassed, bool expectedResult)
        {
            var account = new Account("foo");

            var payment = new Payment(DateTime.Today.AddDays(-amountOfDaysPassed), 105, PaymentType.Expense, account);

            payment.AddRecurringPayment(recurrence, DateTime.Today);

            RecurringPaymentHelper.CheckIfRepeatable(payment)
            .ShouldEqual(expectedResult);
        }
        public void EnumToRecurrenceInt_CorrectlyParsed(PaymentRecurrence type, int enumInt)
        {
            var cb = new ContainerBuilder();
            cb.RegisterModule<DataAccessModule>();
            cb.Build();

            var paymentViewModel = new RecurringPaymentViewModel
            {
                Id = 9,
                Recurrence = type
            };

            var mappedPayment = Mapper.Map<RecurringPayment>(paymentViewModel);
            mappedPayment.Recurrence.ShouldBe(enumInt);
        }
        public void RecurrenceIntToEnum_CorrectlyParsed(int enumInt, PaymentRecurrence type)
        {
            var cb = new ContainerBuilder();
            cb.RegisterModule<DataAccessModule>();
            cb.Build();

            var payment = new RecurringPayment()
            {
                Id = 9,
                Recurrence = enumInt
            };

            var mappedPayment = Mapper.Map<RecurringPaymentViewModel>(payment);
            mappedPayment.Recurrence.ShouldBe(type);
        }
Esempio n. 16
0
 public static string GetStringForPaymentRecurrence(PaymentRecurrence passedEnum)
 {
     return(passedEnum switch
     {
         PaymentRecurrence.Daily => Strings.DailyLabel,
         PaymentRecurrence.DailyWithoutWeekend => Strings.DailyWithoutWeekendLabel,
         PaymentRecurrence.Weekly => Strings.WeeklyLabel,
         PaymentRecurrence.Biweekly => Strings.BiweeklyLabel,
         PaymentRecurrence.Monthly => Strings.MonthlyLabel,
         PaymentRecurrence.Bimonthly => Strings.BimonthlyLabel,
         PaymentRecurrence.Quarterly => Strings.QuarterlyLabel,
         PaymentRecurrence.Biannually => Strings.BiannuallyLabel,
         PaymentRecurrence.Yearly => Strings.YearlyLabel,
         _ => string.Empty,
     });
        public void RecurrenceIntToEnum_CorrectlyParsed(int enumInt, PaymentRecurrence type)
        {
            var cb = new ContainerBuilder();

            cb.RegisterModule <DataAccessModule>();
            cb.Build();

            var payment = new RecurringPayment()
            {
                Id         = 9,
                Recurrence = enumInt
            };

            var mappedPayment = Mapper.Map <RecurringPaymentViewModel>(payment);

            mappedPayment.Recurrence.ShouldBe(type);
        }
        public void EnumToRecurrenceInt_CorrectlyParsed(PaymentRecurrence type, int enumInt)
        {
            var cb = new ContainerBuilder();

            cb.RegisterModule <DataAccessModule>();
            cb.Build();

            var paymentViewModel = new RecurringPaymentViewModel
            {
                Id         = 9,
                Recurrence = type
            };

            var mappedPayment = Mapper.Map <RecurringPayment>(paymentViewModel);

            mappedPayment.Recurrence.ShouldBe(enumInt);
        }
Esempio n. 19
0
 /// <summary>
 ///     Creates an recurring PaymentViewModel based on the Financial PaymentViewModel.
 /// </summary>
 /// <param name="paymentViewModel">The financial PaymentViewModel the reuccuring shall be based on.</param>
 /// <param name="isEndless">If the recurrence is infinite or not.</param>
 /// <param name="recurrence">How often the PaymentViewModel shall be repeated.</param>
 /// <param name="enddate">Enddate for the recurring PaymentViewModel if it's not endless.</param>
 /// <returns>The new created recurring PaymentViewModel</returns>
 public static RecurringPaymentViewModel GetRecurringFromPaymentViewModel(PaymentViewModel paymentViewModel,
                                                                          bool isEndless,
                                                                          PaymentRecurrence recurrence,
                                                                          DateTime enddate = new DateTime())
 {
     return(new RecurringPaymentViewModel
     {
         ChargedAccount = paymentViewModel.ChargedAccount,
         TargetAccount = paymentViewModel.TargetAccount,
         StartDate = paymentViewModel.Date,
         EndDate = enddate,
         IsEndless = isEndless,
         Amount = paymentViewModel.Amount,
         Category = paymentViewModel.Category,
         Type = paymentViewModel.Type,
         Recurrence = recurrence,
         Note = paymentViewModel.Note
     });
 }
 /// <summary>
 ///     Creates an recurring PaymentViewModel based on the Financial PaymentViewModel.
 /// </summary>
 /// <param name="paymentViewModel">The financial PaymentViewModel the reuccuring shall be based on.</param>
 /// <param name="isEndless">If the recurrence is infinite or not.</param>
 /// <param name="recurrence">How often the PaymentViewModel shall be repeated.</param>
 /// <param name="enddate">Enddate for the recurring PaymentViewModel if it's not endless.</param>
 /// <returns>The new created recurring PaymentViewModel</returns>
 public static RecurringPaymentViewModel GetRecurringFromPaymentViewModel(PaymentViewModel paymentViewModel,
     bool isEndless,
     PaymentRecurrence recurrence,
     DateTime enddate = new DateTime())
 {
     return new RecurringPaymentViewModel
     {
         ChargedAccount = paymentViewModel.ChargedAccount,
         TargetAccount = paymentViewModel.TargetAccount,
         StartDate = paymentViewModel.Date,
         EndDate = enddate,
         IsEndless = isEndless,
         Amount = paymentViewModel.Amount,
         Category = paymentViewModel.Category,
         Type = paymentViewModel.Type,
         Recurrence = recurrence,
         Note = paymentViewModel.Note
     };
 }
        public void GetRecurringFromPayment_Endless(PaymentRecurrence recurrence, PaymentType type)
        {
            // Arrange
            var startDate = new DateTime(2015, 03, 12);
            var enddate   = Convert.ToDateTime("7.8.2016");

            var payment = new Payment
            {
                Data =
                {
                    ChargedAccount = new AccountEntity  {
                        Id         =  3
                    },
                    TargetAccount  = new AccountEntity  {
                        Id         =       8
                    },
                    Category       = new CategoryEntity {
                        Id         =    16
                    },
                    Date        = startDate,
                    Amount      =    2135,
                    IsCleared   = false,
                    Type        = type,
                    IsRecurring = true
                }
            };

            // Act
            var recurring = RecurringPaymentHelper.GetRecurringFromPayment(payment, true,
                                                                           recurrence, enddate);

            recurring.Data.ChargedAccount.Id.ShouldBe(3);
            recurring.Data.TargetAccount.Id.ShouldBe(8);
            recurring.Data.StartDate.ShouldBe(startDate);
            recurring.Data.EndDate.ShouldBeNull();
            recurring.Data.IsEndless.ShouldBe(true);
            recurring.Data.Amount.ShouldBe(payment.Data.Amount);
            recurring.Data.Category.Id.ShouldBe(payment.Data.Category.Id);
            recurring.Data.Type.ShouldBe(type);
            recurring.Data.Recurrence.ShouldBe(recurrence);
            recurring.Data.Note.ShouldBe(payment.Data.Note);
        }
 /// <summary>
 ///     Creates an recurring PaymentViewModel based on the Financial PaymentViewModel.
 /// </summary>
 /// <param name="payment">The financial PaymentViewModel the reuccuring shall be based on.</param>
 /// <param name="isEndless">If the recurrence is infinite or not.</param>
 /// <param name="recurrence">How often the PaymentViewModel shall be repeated.</param>
 /// <param name="enddate">Enddate for the recurring PaymentViewModel if it's not endless.</param>
 /// <returns>The new created recurring PaymentViewModel</returns>
 public static RecurringPayment GetRecurringFromPayment(Payment payment,
                                                        bool isEndless,
                                                        PaymentRecurrence recurrence,
                                                        DateTime enddate = new DateTime())
 => new RecurringPayment
 {
     Data =
     {
         ChargedAccount = payment.Data.ChargedAccount,
         TargetAccount  = payment.Data.TargetAccount,
         StartDate      = payment.Data.Date,
         EndDate        = !isEndless ? (DateTime?)enddate : null,
         IsEndless      = isEndless,
         Amount         = payment.Data.Amount,
         Category       = payment.Data.Category,
         Type           = payment.Data.Type,
         Recurrence     = recurrence,
         Note           = payment.Data.Note
     }
 };
Esempio n. 23
0
 /// <summary>
 ///     Creates an recurring PaymentViewModel based on the Financial PaymentViewModel.
 /// </summary>
 /// <param name="payment">The financial PaymentViewModel the reuccuring shall be based on.</param>
 /// <param name="isEndless">If the recurrence is infinite or not.</param>
 /// <param name="recurrence">How often the PaymentViewModel shall be repeated.</param>
 /// <param name="enddate">Enddate for the recurring PaymentViewModel if it's not endless.</param>
 /// <returns>The new created recurring PaymentViewModel</returns>
 public static RecurringPaymentViewModel GetRecurringFromPayment(PaymentViewModel payment,
                                                                 bool isEndless,
                                                                 PaymentRecurrence recurrence,
                                                                 DateTime enddate = new DateTime())
 => new RecurringPaymentViewModel
 {
     Id               = payment.RecurringPaymentId,
     ChargedAccount   = payment.ChargedAccount,
     ChargedAccountId = payment.ChargedAccount.Id,
     TargetAccount    = payment.TargetAccount,
     TargetAccountId  = payment.TargetAccount?.Id ?? 0,
     StartDate        = payment.Date,
     EndDate          = enddate,
     IsEndless        = isEndless,
     Amount           = payment.Amount,
     CategoryId       = payment.CategoryId,
     Category         = payment.Category,
     Type             = payment.Type,
     Recurrence       = recurrence,
     Note             = payment.Note
 };
 /// <summary>
 ///     Creates an recurring PaymentViewModel based on the Financial PaymentViewModel.
 /// </summary>
 /// <param name="payment">The financial PaymentViewModel the reuccuring shall be based on.</param>
 /// <param name="isEndless">If the recurrence is infinite or not.</param>
 /// <param name="recurrence">How often the PaymentViewModel shall be repeated.</param>
 /// <param name="enddate">Enddate for the recurring PaymentViewModel if it's not endless.</param>
 /// <returns>The new created recurring PaymentViewModel</returns>
 public static RecurringPaymentViewModel GetRecurringFromPayment(PaymentViewModel payment,
         bool isEndless,
         PaymentRecurrence recurrence,
         DateTime enddate = new DateTime())
     => new RecurringPaymentViewModel
     {
         Id = payment.RecurringPaymentId,
         ChargedAccount = payment.ChargedAccount,
         ChargedAccountId = payment.ChargedAccount.Id,
         TargetAccount = payment.TargetAccount,
         TargetAccountId = payment.TargetAccount?.Id ?? 0,
         StartDate = payment.Date,
         EndDate = enddate,
         IsEndless = isEndless,
         Amount = payment.Amount,
         CategoryId = payment.CategoryId,
         Category = payment.Category,
         Type = payment.Type,
         Recurrence = recurrence,
         Note = payment.Note
     };
        public void GetPaymentFromRecurring_RecurringPayment_CorrectMappedFinancialTrans(
            PaymentRecurrence recurrence)
        {
            var account = new Account {Id = 2};

            var recurringPayment = new RecurringPayment
            {
                Id = 4,
                Recurrence = (int) recurrence,
                StartDate = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount = account,
                Amount = 105
            };

            var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment);

            result.ChargedAccount.ShouldBe(account);
            result.ChargedAccountId.ShouldBe(account.Id);
            result.Amount.ShouldBe(105);
            result.Date.ShouldBe(DateTime.Today);
        }
Esempio n. 26
0
        public async void SaveCommand_Recurrence_RecurrenceSetCorrectly(PaymentRecurrence recurrence)
        {
            // Arrange
            base.Setup();
            var testPayment = new Payment();

            var settingsManagerMock = new Mock <ISettingsManager>();

            settingsManagerMock.SetupAllProperties();

            var paymentServiceMock = new Mock <IPaymentService>();

            paymentServiceMock.Setup(x => x.SavePayments(It.IsAny <Payment[]>()))
            .Callback((Payment[] payment) => testPayment = payment.First())
            .Returns(Task.CompletedTask);

            var viewmodel = new ModifyPaymentViewModel(paymentServiceMock.Object,
                                                       new Mock <IAccountService>().Object,
                                                       new Mock <IDialogService>().Object,
                                                       settingsManagerMock.Object,
                                                       new Mock <IMvxMessenger>().Object,
                                                       new Mock <IBackupManager>().Object,
                                                       new Mock <IMvxLogProvider>().Object,
                                                       new Mock <IMvxNavigationService>().Object);

            viewmodel.Prepare(new ModifyPaymentParameter(PaymentType.Income));
            await viewmodel.Initialize();

            viewmodel.SelectedPayment.ChargedAccount = new AccountViewModel(new Account());
            viewmodel.SelectedPayment.IsRecurring    = true;
            viewmodel.Recurrence = recurrence;

            // Act
            viewmodel.SaveCommand.Execute();

            // Assert
            testPayment.Data.RecurringPayment.ShouldNotBeNull();
            testPayment.Data.RecurringPayment.Recurrence.ShouldEqual(recurrence);
        }
Esempio n. 27
0
        public void CheckIfRepeatable_ValidatedRecurrence(PaymentRecurrence recurrence, int amountOfDaysPassed)
        {
            var account = new AccountViewModel {
                Id = 2
            };

            var recurringPayment = new RecurringPaymentViewModel
            {
                Id               = 4,
                Recurrence       = recurrence,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(recurringPayment,
                                                     new PaymentViewModel {
                Date = DateTime.Today.AddDays(-amountOfDaysPassed), IsCleared = true
            })
            .ShouldBeTrue();
        }
Esempio n. 28
0
        public void UpdateRecurringPayment(decimal amount,
                                           PaymentRecurrence recurrence,
                                           Account chargedAccount,
                                           string note           = "",
                                           DateTime?endDate      = null,
                                           Account targetAccount = null,
                                           Category category     = null)
        {
            if (!IsEndless && endDate != null && endDate < DateTime.Today)
            {
                throw new InvalidEndDateException();
            }

            ChargedAccount   = chargedAccount ?? throw new ArgumentNullException(nameof(chargedAccount));
            EndDate          = endDate;
            Amount           = amount;
            Recurrence       = recurrence;
            Note             = note;
            Category         = category;
            TargetAccount    = targetAccount;
            IsEndless        = endDate == null;
            ModificationDate = DateTime.Now;
        }
Esempio n. 29
0
        public void GetRecurringFromPayment_Endless(PaymentRecurrence recurrence, PaymentType type)
        {
            var startDate = new DateTime(2015, 03, 12);
            var enddate   = Convert.ToDateTime("7.8.2016");

            var payment = new PaymentViewModel
            {
                ChargedAccount = new AccountViewModel {
                    Id = 3
                },
                TargetAccount = new AccountViewModel {
                    Id = 8
                },
                Category = new CategoryViewModel {
                    Id = 16
                },
                Date        = startDate,
                Amount      = 2135,
                IsCleared   = false,
                Type        = type,
                IsRecurring = true
            };

            var recurring = RecurringPaymentHelper.GetRecurringFromPayment(payment, true,
                                                                           recurrence, enddate);

            recurring.ChargedAccount.Id.ShouldBe(3);
            recurring.TargetAccount.Id.ShouldBe(8);
            recurring.StartDate.ShouldBe(startDate);
            recurring.EndDate.ShouldBe(enddate);
            recurring.IsEndless.ShouldBe(true);
            recurring.Amount.ShouldBe(payment.Amount);
            recurring.Category.Id.ShouldBe(payment.Category.Id);
            recurring.Type.ShouldBe(type);
            recurring.Recurrence.ShouldBe(recurrence);
            recurring.Note.ShouldBe(payment.Note);
        }
Esempio n. 30
0
        public void GetPaymentFromRecurring_RecurringPayment_CorrectMappedFinancialTrans(
            PaymentRecurrence recurrence)
        {
            var account = new Account {
                Id = 2
            };

            var recurringPayment = new RecurringPayment
            {
                Id               = 4,
                Recurrence       = (int)recurrence,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment);

            result.ChargedAccount.ShouldBe(account);
            result.ChargedAccountId.ShouldBe(account.Id);
            result.Amount.ShouldBe(105);
            result.Date.ShouldBe(DateTime.Today);
        }
        public void SaveCommand_Recurrence_RecurrenceSetCorrectly(PaymentRecurrence recurrence)
        {
            //setup
            var testPayment = new PaymentViewModel();

            var paymentRepoSetup = new Mock <IPaymentRepository>();
            var accountRepoMock  = new Mock <IAccountRepository>();

            var settingsManagerMock = new Mock <ISettingsManager>();

            settingsManagerMock.SetupAllProperties();

            var paymentManagerMock = new Mock <IPaymentManager>();

            paymentManagerMock.Setup(x => x.SavePayment(It.IsAny <PaymentViewModel>())).Callback((PaymentViewModel payment) => testPayment = payment);

            var viewmodel = new ModifyPaymentViewModel(paymentRepoSetup.Object,
                                                       accountRepoMock.Object,
                                                       new Mock <IDialogService>().Object,
                                                       paymentManagerMock.Object,
                                                       settingsManagerMock.Object,
                                                       new Mock <IMvxMessenger>().Object,
                                                       new Mock <IBackupManager>().Object);

            viewmodel.Init(PaymentType.Income);
            viewmodel.SelectedPayment.ChargedAccount = new AccountViewModel();
            viewmodel.SelectedPayment.IsRecurring    = true;
            viewmodel.Recurrence = recurrence;

            // execute
            viewmodel.SaveCommand.Execute();

            //Assert
            testPayment.RecurringPayment.ShouldNotBeNull();
            testPayment.RecurringPayment.Recurrence.ShouldBe(recurrence);
        }
Esempio n. 32
0
        public void SetLastRecurrenceCreatedDateUpdated()
        {
            // Arrange
            DateTime                startDate  = DateTime.Now;
            const int               amount     = 123;
            const PaymentType       type       = PaymentType.Expense;
            const PaymentRecurrence recurrence = PaymentRecurrence.Daily;
            var          account = new Account("foo");
            const string note    = "asdf";

            var recurringPayment = new RecurringPayment(startDate,
                                                        amount,
                                                        type,
                                                        recurrence,
                                                        account,
                                                        note);

            // Act
            recurringPayment.SetLastRecurrenceCreatedDate();

            // Assert
            recurringPayment.LastRecurrenceCreated.ShouldBeInRange(DateTime.Now.AddSeconds(-1), DateTime.Now);
            recurringPayment.ModificationDate.ShouldBeInRange(DateTime.Now.AddSeconds(-1), DateTime.Now);
        }
        public void CheckIfRepeatable_UnclearedPayment_ReturnFalse(PaymentRecurrence recurrence, int amountOfDaysUntilRepeat)
        {
            var account = new AccountViewModel {Id = 2};

            var recurringPayment = new RecurringPaymentViewModel
            {
                Id = 4,
                Recurrence = PaymentRecurrence.Weekly,
                StartDate = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount = account,
                Amount = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(recurringPayment,
                new PaymentViewModel {Date = DateTime.Today.AddDays(amountOfDaysUntilRepeat)}).ShouldBeFalse();
        }
 public void Convert_CorrectValue(PaymentRecurrence type, string result)
 {
     new RecurrenceTypeConverter().Convert(type, null, null, null).ShouldBe(result);
 }
Esempio n. 35
0
 public void Convert_CorrectValue(PaymentRecurrence type, string result)
 {
     RecurrenceTypeConverterLogic.GetStringForPaymentRecurrence(type).ShouldEqual(result);
 }
        public void SaveCommand_Recurrence_RecurrenceSetCorrectly(PaymentRecurrence recurrence)
        {
            //setup
            var testPayment = new PaymentViewModel();

            var paymentRepoSetup = new Mock<IPaymentRepository>();
            var accountRepoMock = new Mock<IAccountRepository>();

            var settingsManagerMock = new Mock<ISettingsManager>();
            settingsManagerMock.SetupAllProperties();

            var paymentManagerMock = new Mock<IPaymentManager>();
            paymentManagerMock.Setup(x => x.SavePayment(It.IsAny<PaymentViewModel>())).Callback((PaymentViewModel payment) => testPayment = payment);

            var viewmodel = new ModifyPaymentViewModel(paymentRepoSetup.Object,
                accountRepoMock.Object,
                new Mock<IDialogService>().Object,
                paymentManagerMock.Object,
                settingsManagerMock.Object,
                new Mock<IMvxMessenger>().Object,
                new Mock<IBackupManager>().Object);

            viewmodel.Init(PaymentType.Income);
            viewmodel.SelectedPayment.ChargedAccount = new AccountViewModel();
            viewmodel.SelectedPayment.IsRecurring = true;
            viewmodel.Recurrence = recurrence;

            // execute
            viewmodel.SaveCommand.Execute();

            //Assert
            testPayment.RecurringPayment.ShouldNotBeNull();
            testPayment.RecurringPayment.Recurrence.ShouldBe(recurrence);
        }
 public void Convert_CorrectValue(PaymentRecurrence type, string result)
 {
     new RecurrenceTypeConverter().Convert(type, null, null, null).ShouldBe(result);
 }
        public void GetPaymentFromRecurring_CorrectMappedPayment(PaymentRecurrence recurrence)
        {
            var account = new AccountViewModel {Id = 2};

            var recurringPayment = new RecurringPaymentViewModel
            {
                Id = 4,
                Recurrence = recurrence,
                StartDate = new DateTime(2015, 08, DateTime.Today.Day),
                ChargedAccountId = 2,
                ChargedAccount = account,
                Amount = 105
            };

            var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment);

            result.ChargedAccount.ShouldBe(account);
            result.ChargedAccountId.ShouldBe(account.Id);
            result.Amount.ShouldBe(105);
            result.Date.ShouldBe(DateTime.Today);
        }
Esempio n. 39
0
 public void AddRecurringPayment(PaymentRecurrence recurrence, DateTime?endDate = null)
 {
     RecurringPayment = new RecurringPayment(Date, Amount, Type, recurrence, ChargedAccount, Note, endDate, TargetAccount, Category);
     IsRecurring      = true;
 }
        public void CheckIfRepeatable_ValidatedRecurrence(PaymentRecurrence recurrence, int amountOfDaysPassed)
        {
            var account = new AccountViewModel {Id = 2};

            var recurringPayment = new RecurringPaymentViewModel
            {
                Id = 4,
                Recurrence = recurrence,
                StartDate = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount = account,
                Amount = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(recurringPayment,
                new PaymentViewModel {Date = DateTime.Today.AddDays(-amountOfDaysPassed), IsCleared = true})
                .ShouldBeTrue();
        }