示例#1
0
 public void SetUp()
 {
     Subject = new RentalHome("foobar", PurchasedAt, 300.00M);
 }
示例#2
0
        public OneHomeQuery()
        {
            Field <DecimalGraphType>(
                "buyAndSellCondo",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <DateGraphType> >
            {
                Name = Keys.InitiatedAt
            },
                    new QueryArgument <NonNullGraphType <DecimalGraphType> >
            {
                Name = Keys.DownPayment
            },
                    new QueryArgument <NonNullGraphType <DecimalGraphType> >
            {
                Name = Keys.PurchasePrice
            },
                    new QueryArgument <IntGraphType>
            {
                Name         = Keys.AmortisationPeriodInMonths,
                DefaultValue = 300
            },
                    new QueryArgument <NonNullGraphType <DecimalGraphType> >
            {
                Name = Keys.InterestRate
            }
                    ),
                resolve: context =>
            {
                var purchasedAt   = GetInitiatedAt(context);
                var purchasePrice = GetPurchasePrice(context);
                var downPayment   = GetDownPayment(context);
                var interestRate  = GetInterestRate(context);
                var amortisationPeriodInMonths = GetAmortizationPeriodInMonths(context);
                var soldAt    = purchasedAt.AddMonths(amortisationPeriodInMonths);
                var salePrice = Inflations.CondoPriceIndex.GetValueAt(purchasePrice, purchasedAt, soldAt);

                // START Validation
                // END Validation

                var mortgage = new FixedRateMortgage(purchasePrice - downPayment, interestRate, amortisationPeriodInMonths, purchasedAt);
                var home     = new Home("foobar", purchasedAt, purchasePrice, downPayment, mortgage);
                var activity = new Activity(purchasedAt);


                activity.Buy(home, purchasedAt);
                activity.Sell(home, salePrice, soldAt);
                // var year = context.GetArgument<int>(Keys.Year);
                // var month = context.GetArgument<int>(Keys.Month);
                // var day = context.GetArgument<int>(Keys.Day);
                //
                // var at = new DateTime(year, month, day);

                return(activity.GetNetWorthAt(Inflations.NoopInflation, soldAt.AddDays(1)));
            }
                );
            Field <DecimalGraphType>(
                "rentApartment",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <DateGraphType> >
            {
                Name = Keys.InitiatedAt
            },
                    new QueryArgument <IntGraphType>
            {
                Name         = Keys.AmortisationPeriodInMonths,
                DefaultValue = 300,
                Description  = "Rental Period (in months)"
            },
                    new QueryArgument <NonNullGraphType <DecimalGraphType> >
            {
                Name = Keys.MonthlyRentalRate
            }
                    ),
                resolve: context =>
            {
                var startAt           = GetInitiatedAt(context);
                var rentalPeriod      = GetAmortizationPeriodInMonths(context);
                var rentalMonthlyRate = GetMonthlyRentalRate(context);
                var endAt             = startAt.AddMonths(rentalPeriod);

                var rental = new RentalHome("foobar", startAt, rentalMonthlyRate);

                // START Validation
                // END Validation

                var activity = new Activity(startAt);


                activity.Buy(rental, startAt);
                activity.Sell(rental, 0.00M, endAt);

                return(activity.GetNetWorthAt(Inflations.NoopInflation, endAt.AddDays(1)));
            }
                );
        }