コード例 #1
0
        public void Test_SellCondo_SellsTheHomeAndTheMortgage()
        {
            var purchasePrice = 2000.00M;

            // Buy condo
            var balanceSheet = Subject
                               .SetInitialCash(purchasePrice)
                               .AddCondoWithFixedRateMortgageAtDownPaymentPercentage("first", purchasePrice, 0.25M);

            var condo       = Subject.GetHomes().First();
            var purchasedAt = condo.PurchasedAt;

            // Sell the condo
            var soldAt        = purchasedAt.AddYears(5);
            var homeInflation = new CompoundYearlyInflation(0.05M);
            var soldPrice     = homeInflation.GetValueAt(purchasePrice, purchasedAt, soldAt);

            Subject.SellHome(condo, soldAt, soldPrice);

            Assert.That(Subject.GetHomes(), Is.Empty);
            var activity = Subject
                           .Build();

            var actualHistories = activity.GetHistories()
                                  .ToList();

            Assert.That(actualHistories, Has.Exactly(2).Items);

            var inflationAdjustment = Inflations.ConsumerPriceIndex;

            Assert.That(
                actualHistories[0].TransactionalPrice,
                Is.EqualTo(new decimal[] {
                -2000.00M,
                inflationAdjustment.GetValueAt(
                    -1000.00M,
                    HomePurchaseStrategy.InflationStartsAt,
                    purchasedAt
                    ),
                inflationAdjustment.GetValueAt(
                    -8500.00M,
                    HomePurchaseStrategy.InflationStartsAt,
                    purchasedAt
                    ),
                inflationAdjustment.GetValueAt(
                    -800.00M,
                    HomePurchaseStrategy.InflationStartsAt,
                    purchasedAt
                    )
            }.Sum())
                );
            Assert.That(actualHistories[0].Type, Is.EqualTo(Types.Purchase));
            Assert.That(actualHistories[0].At, Is.EqualTo(InitiatedAt.GetNext()));
            Assert.That(actualHistories[0].Product, Is.TypeOf <Home>());

            Assert.That(actualHistories[1].TransactionalPrice, Is.EqualTo(10.41M));
            Assert.That(actualHistories[1].Type, Is.EqualTo(Types.Sale));
            Assert.That(actualHistories[1].At, Is.EqualTo(soldAt));
            Assert.That(actualHistories[1].Product, Is.TypeOf <Home>());
        }
コード例 #2
0
ファイル: CashFinder.cs プロジェクト: ofer987/Financier
        public DateTime HasAvailableCashAt(decimal expenseAtInitiation, IInflation expenseInflation)
        {
            var      atFiftyYears = InitiatedAt.AddYears(50);
            DateTime at = InitiatedAt;
            decimal  available, required;

            do
            {
                if (at > atFiftyYears)
                {
                    throw new InvalidOperationException($"Unable to find enough money to pay for {expenseAtInitiation} by ${atFiftyYears.ToString("yyyy-MM-dd")}");
                }

                at        = at.GetNext();
                available = CashFlow.GetCash(expenseInflation, InitiatedAt, at);
                required  = CostAt(expenseAtInitiation, expenseInflation, at);
            } while (available < required);

            return(at);
        }
コード例 #3
0
        public override int GetHashCode()
        {
            int hashCode = 388412647;

            if (Context != null)
            {
                hashCode += Context.GetHashCode();
            }

            if (Id != null)
            {
                hashCode += Id.GetHashCode();
            }

            if (Status != null)
            {
                hashCode += Status.GetHashCode();
            }

            if (TotalMoney != null)
            {
                hashCode += TotalMoney.GetHashCode();
            }

            if (InitiatedAt != null)
            {
                hashCode += InitiatedAt.GetHashCode();
            }

            if (BankAccountId != null)
            {
                hashCode += BankAccountId.GetHashCode();
            }

            if (Entries != null)
            {
                hashCode += Entries.GetHashCode();
            }

            return(hashCode);
        }
コード例 #4
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is V1Settlement other &&
                   ((Context == null && other.Context == null) || (Context?.Equals(other.Context) == true)) &&
                   ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) &&
                   ((Status == null && other.Status == null) || (Status?.Equals(other.Status) == true)) &&
                   ((TotalMoney == null && other.TotalMoney == null) || (TotalMoney?.Equals(other.TotalMoney) == true)) &&
                   ((InitiatedAt == null && other.InitiatedAt == null) || (InitiatedAt?.Equals(other.InitiatedAt) == true)) &&
                   ((BankAccountId == null && other.BankAccountId == null) || (BankAccountId?.Equals(other.BankAccountId) == true)) &&
                   ((Entries == null && other.Entries == null) || (Entries?.Equals(other.Entries) == true)));
        }