public void Map_GivenAFullyPopulatedViewModelObject_ReturnsACorrectlyMappedDomainModelObject()
        {
            // Arrange
            var vm =
                new DebtorViewModel
                    {
                        Id = 14,
                        Name = "XXX",
                        CompanyName = "MoneyHelper",
                        Income = 444.4m,
                        Expenditure = 2323.23m,
                        Debts =
                            new[]
                                {
                                    new DebtViewModel {AmountOwed = 40.0m},
                                    new DebtViewModel {AmountOwed = 50.0m}
                                }
                    };

            // Act
            var dm = new Debtor(vm.Id);
            Mapper.Map<DebtorViewModel, Debtor>(vm, dm);

            // Assert
            Assert.That(dm.Id, Is.EqualTo(vm.Id));
            Assert.That(dm.Name, Is.EqualTo(vm.Name));
            Assert.That(dm.Company, Is.EqualTo(Company.CompanyC));
            Assert.That(dm.Income, Is.EqualTo(vm.Income));
            Assert.That(dm.Expenditure, Is.EqualTo(vm.Expenditure));
            Assert.That(dm.Debts, Has.Count.EqualTo(vm.Debts.Length));
            Assert.That(dm.Debts.Skip(0).First().AmountOwed, Is.EqualTo(40.0m));
            Assert.That(dm.Debts.Skip(1).First().AmountOwed, Is.EqualTo(50.0m));
        }
        public void Map_GivenAFullyPopulatedDomainModelObject_ReturnsACorrectlyMappedViewModelObject()
        {
            // Arrange
            var dm =
                new Debtor(2)
                    {
                        Name = "AAA",
                        Company = Company.CompanyB,
                        Income = 333.3m,
                        Expenditure = 222.2m,
                        Debts =
                            new[]
                                {
                                    new Debt {AmountOwed = 10.0m},
                                    new Debt {AmountOwed = 20.0m},
                                    new Debt {AmountOwed = 30.0m}
                                }
                    };

            // Act
            var vm = Mapper.Map<Debtor, DebtorViewModel>(dm);

            // Assert
            Assert.That(vm.Id, Is.EqualTo(dm.Id));
            Assert.That(vm.Name, Is.EqualTo(dm.Name));
            Assert.That(vm.CompanyName, Is.EqualTo(dm.Company.CompanyToDisplayName()));
            Assert.That(vm.Income, Is.EqualTo(dm.Income));
            Assert.That(vm.Expenditure, Is.EqualTo(dm.Expenditure));
            Assert.That(vm.Debts, Has.Length.EqualTo(dm.Debts.Count()));
            Assert.That(vm.Debts[0].AmountOwed, Is.EqualTo(10.0m));
            Assert.That(vm.Debts[1].AmountOwed, Is.EqualTo(20.0m));
            Assert.That(vm.Debts[2].AmountOwed, Is.EqualTo(30.0m));
        }
        public override decimal CalculateManagementFee(Debtor debtor)
        {
            var monthlyManagementFee = Math.Ceiling(debtor.TotalAmountOwed / ChunkOfAmountOwed) * FeePerChunkOfAmountOwed;

            if (monthlyManagementFee > MaximumFee) {
                monthlyManagementFee = MaximumFee;
            }

            return monthlyManagementFee;
        }
Example #4
0
        public DebtManagementPlan(Debtor debtor, Company company)
        {
            Debtor = debtor;
            Company = company;

            _commissionCalculator = CommissionCalculatorFactory.GetCommissionCalculator(Company);

            MonthlyManagementFee = _commissionCalculator.CalculateManagementFee(Debtor);

            CalculateProRataRepaymentsToCreditors();
        }
Example #5
0
        public ActionResult Create(DebtorEditModel editModelDebtor)
        {
            if (ModelState.IsValid)
            {
                var domainDebtor = new Debtor(editModelDebtor.Id);
                Mapper.Map(editModelDebtor, domainDebtor);
                _debtorRepository.MakePersistent(domainDebtor);
                return RedirectToAction("Index");
            }

            return View("CreateOrEdit", editModelDebtor);
        }
Example #6
0
 private static Debtor CreateDebtor3()
 {
     var debtor =
         new Debtor
             {
                 Name = "Miss T. Un-terre",
                 Income = 500m,
                 Expenditure = 400m,
                 Company = Company.CompanyB,
                 Debts = new[]
                                 {
                                     new Debt {AmountOwed = 100m},
                                     new Debt {AmountOwed = 2400m},
                                     new Debt {AmountOwed = 5000m}
                                 }
             };
     SetIdUsingReflection(debtor, 3);
     return debtor;
 }
Example #7
0
 private static Debtor CreateDebtor1()
 {
     var debtor =
         new Debtor
             {
                 Name = "John Nogan",
                 Income = 980m,
                 Expenditure = 670m,
                 Company = Company.CompanyA,
                 Debts = new[]
                                 {
                                     new Debt {AmountOwed = 3000m},
                                     new Debt {AmountOwed = 12000m},
                                     new Debt {AmountOwed = 100m},
                                     new Debt {AmountOwed = 4000m}
                                 }
             };
     SetIdUsingReflection(debtor, 1);
     return debtor;
 }
Example #8
0
 private static Debtor CreateDebtor2()
 {
     var debtor =
         new Debtor
             {
                 Name = "Paul A’rdé",
                 Income = 1560m,
                 Expenditure = 1399m,
                 Company = Company.CompanyC,
                 Debts = new[]
                                 {
                                     new Debt {AmountOwed = 300m},
                                     new Debt {AmountOwed = 2400m},
                                     new Debt {AmountOwed = 10000m},
                                     new Debt {AmountOwed = 2000m},
                                     new Debt {AmountOwed = 919m}
                                 }
             };
     SetIdUsingReflection(debtor, 2);
     return debtor;
 }
Example #9
0
        public static Debtor Build(int id)
        {
            var debtor =
                new Debtor
                    {
                        Company = Company.CompanyB,
                        Name = "Stub Debtor Name",
                        Expenditure = 1000.0m,
                        Income = 2000.0m,
                        Debts = new[]
                                        {
                                            new Debt {AmountOwed = 100.0m},
                                            new Debt {AmountOwed = 200.0m},
                                            new Debt {AmountOwed = 300.0m}
                                        }
                    };

            BuilderHelpers.SetIdUsingReflection(debtor, id);

            return debtor;
        }
Example #10
0
 private static Debtor CreateDebtor4()
 {
     var debtor =
         new Debtor
             {
                 Name = "David Simmer",
                 Income = 2000m,
                 Expenditure = 1000m,
                 Company = Company.CompanyC,
                 Debts = new[]
                                 {
                                     new Debt {AmountOwed = 100m},
                                     new Debt {AmountOwed = 200m},
                                     new Debt {AmountOwed = 600m},
                                     new Debt {AmountOwed = 2000m},
                                     new Debt {AmountOwed = 7370m}
                                 }
             };
     SetIdUsingReflection(debtor, 4);
     return debtor;
 }
Example #11
0
 public DebtManagementPlan(Debtor debtor)
     : this(debtor, debtor.Company)
 {
 }