コード例 #1
0
        public void ProduceOfferReturnsCorrectResultWhenSpecificationIsSatisfied()
        {
            // Arrange
            var application = new MortgageApplication();

            var sut = new ConditionalMortgageApplicationProcessor
            {
                Specification  = new Mock <IMortgageApplicationSpecification>().Object,
                TruthProcessor = new Mock <IMortgageApplicationProcessor>().Object
            };

            Mock.Get(sut.Specification)
            .Setup(s => s.IsSatisfiedBy(application))
            .Returns(true);

            var expected = new []
            {
                new Mock <IRendering>().Object,
                new Mock <IRendering>().Object,
                new Mock <IRendering>().Object,
            };

            Mock.Get(sut.TruthProcessor)
            .Setup(p => p.ProduceOffer(application))
            .Returns(expected);

            // Act
            var actual = sut.ProduceOffer(application);

            // Assert
            Assert.Equal(expected, actual);
        }
コード例 #2
0
 public MortgageApplicationResult ProcessApplication(MortgageApplication application)
 {
     return(_first.ProcessApplication(application) == MortgageApplicationResult.Approved &&
            _second.ProcessApplication(application) == MortgageApplicationResult.Approved
         ? MortgageApplicationResult.Approved
         : MortgageApplicationResult.Declined);
 }
コード例 #3
0
        public void ProduceOfferReturnsCorrectResult(
            LoanType loanType,
            int term,
            PaymentFrequency frequency)
        {
            var sut         = new DesiredLoanMortgageApplicationProcessor();
            var application = new MortgageApplication
            {
                DesiredLoanType  = loanType,
                DesiredTerm      = term,
                DesiredFrequency = frequency
            };

            var actual = sut.ProduceOffer(application);

            var expected = new IRendering[]
            {
                new Heading2Rendering("Desired loan"),
                new BoldRendering("Loan type:"),
                new TextRendering(" " + loanType),
                new LineBreakRendering(),
                new BoldRendering("Term:"),
                new TextRendering(" " + term + " years."),
                new LineBreakRendering(),
                new BoldRendering("Frequency:"),
                new TextRendering(" " + frequency),
                new LineBreakRendering()
            };

            Assert.Equal(expected, actual);
        }
        public void ProduceOfferReturnsCorrectResult(
            int rate,
            string term)
        {
            var application = new MortgageApplication();
            var offer       = new InterestOnlyOffer
            {
                Rate = rate,
                Term = DateTimeOffset.Parse(term)
            };
            var sut = new InterestOnlyOfferMortgageApplicationProcessor
            {
                OfferService = new Mock <IOfferService>().Object
            };

            Mock.Get(sut.OfferService)
            .Setup(o => o.GetInterestOnlyOffer(application))
            .Returns(offer);

            var actual = sut.ProduceOffer(application);

            var expected = new IRendering[]
            {
                new Heading2Rendering("Interest only offer"),
                new BoldRendering("Interest rate:"),
                new TextRendering(" " + offer.Rate / 10m + " %"),
                new LineBreakRendering(),
                new BoldRendering("Term:"),
                new TextRendering(" " + offer.Term.ToString("D")),
                new LineBreakRendering()
            };

            Assert.Equal(expected, actual);
        }
コード例 #5
0
        public void IsSatisfiedByReturnsCorrectResult(
            bool b1,
            bool b2,
            bool b3,
            bool expected)
        {
            // Arrange
            var application = new MortgageApplication();

            var spec1 = new Mock <IMortgageApplicationSpecification>();
            var spec2 = new Mock <IMortgageApplicationSpecification>();
            var spec3 = new Mock <IMortgageApplicationSpecification>();

            spec1.Setup(s => s.IsSatisfiedBy(application)).Returns(b1);
            spec2.Setup(s => s.IsSatisfiedBy(application)).Returns(b2);
            spec3.Setup(s => s.IsSatisfiedBy(application)).Returns(b3);

            var sut = new AndMortgageApplicationSpecification
            {
                Specifications = new[] { spec1.Object, spec2.Object, spec3.Object }
            };

            // Act
            var actual = sut.IsSatisfiedBy(application);

            // Assert
            Assert.Equal(expected, actual);
        }
コード例 #6
0
        public void ProduceOfferReturnsCorrectResult(
            string street,
            string postalCode,
            string country,
            int price,
            int size)
        {
            var sut         = new PropertyMortgageApplicationProcessor();
            var application = new MortgageApplication
            {
                Property = new Property
                {
                    Address = new Address
                    {
                        Street     = street,
                        PostalCode = postalCode,
                        Country    = country
                    },
                    Price = price,
                    Size  = size
                }
            };

            var actual = sut.ProduceOffer(application);

            var expected =
                new PropertyProcessor
            {
                PriceText = "Asking price"
            }
            .ProduceRenderings(application.Property);

            Assert.Equal(expected, actual);
        }
コード例 #7
0
 public IEnumerable <IRendering> ProduceOffer(MortgageApplication application)
 {
     return(new PropertyProcessor
     {
         PriceText = "Asking price"
     }
            .ProduceRenderings(application.Property));
 }
コード例 #8
0
        public IEnumerable <IRendering> ProduceOffer(MortgageApplication application)
        {
            yield return(new BoldRendering("Self payment:"));

            yield return(new TextRendering(" " + application.SelfPayment));

            yield return(new LineBreakRendering());
        }
コード例 #9
0
        public IEnumerable <IRendering> ProduceOffer(MortgageApplication application)
        {
            yield return(new Heading1Rendering("Loan offer"));

            yield return(new TextRendering("It gives us great pleasure to extend to you the following loan offer, lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."));

            yield return(new LineBreakRendering());
        }
コード例 #10
0
        public IEnumerable <IRendering> ProduceOffer(MortgageApplication application)
        {
            if (this.Specification.IsSatisfiedBy(application))
            {
                return(this.TruthProcessor.ProduceOffer(application));
            }

            return(Enumerable.Empty <IRendering>());
        }
コード例 #11
0
        public void IsSatisfiedByAplicationWithNoAdditionalApplicantsReturnsFalse()
        {
            var application = new MortgageApplication();
            var sut         = new AnyAdditionalApplicantsSpecification();

            var actual = sut.IsSatisfiedBy(application);

            Assert.False(actual);
        }
コード例 #12
0
        public IEnumerable <IRendering> ProduceOffer(
            MortgageApplication application)
        {
            yield return(new TextRendering(
                             this.LocationProvider.GetCurrentLocationName() +
                             ", " +
                             this.TimeProvider.GetCurrentTime().ToString("D")));

            yield return(new LineBreakRendering());
        }
コード例 #13
0
        public IEnumerable <IRendering> ProduceOffer(MortgageApplication application)
        {
            yield return(new BoldRendering("Primary applicant:"));

            var p = new ApplicantProcessor();

            foreach (var r in p.ProduceRenderings(application.PrimaryApplicant))
            {
                yield return(r);
            }
        }
コード例 #14
0
ファイル: HomeController.cs プロジェクト: jrades/Net_Project
        public IActionResult Details(Guid id)
        {
            MortgageApplication application = Repository.Get(id);

            if (application == null)
            {
                return(RedirectToAction("Index"));
            }

            return(View(application));
        }
        public void IsSatisfiedByReturnsFalseIfCurrentPropertyIsNull()
        {
            var application = new MortgageApplication
            {
                CurrentPropertyWillBeSoldToFinanceNewProperty = false
            };
            var sut = new CurrentPropertySoldAsFinancingMortgageApplicationSpecification();

            var actual = sut.IsSatisfiedBy(application);

            Assert.False(actual);
        }
        public void IsSatisfiedByReturnsTrueIfCurrentPropertyHasValue()
        {
            var application = new MortgageApplication
            {
                CurrentPropertyWillBeSoldToFinanceNewProperty = true
            };
            var sut = new CurrentPropertySoldAsFinancingMortgageApplicationSpecification();

            var actual = sut.IsSatisfiedBy(application);

            Assert.True(actual);
        }
コード例 #17
0
        public void IsSatisfiedByApplicationWithAdditionalApplicantsReturnsTrue()
        {
            var application = new MortgageApplication();

            application.AdditionalApplicants.Add(new Applicant());
            application.AdditionalApplicants.Add(new Applicant());
            var sut = new AnyAdditionalApplicantsSpecification();

            var actual = sut.IsSatisfiedBy(application);

            Assert.True(actual);
        }
コード例 #18
0
        public void IsSatisfiedByReturnsTrueIfCurrentPropertyHasValue()
        {
            var application = new MortgageApplication
            {
                CurrentProperty = new Property()
            };
            var sut = new CurrentPropertyExistsSpecification();

            var actual = sut.IsSatisfiedBy(application);

            Assert.True(actual);
        }
コード例 #19
0
        public void IsSatisfiedByReturnsFalseIfCurrentPropertyIsNull()
        {
            var application = new MortgageApplication
            {
                CurrentProperty = null
            };
            var sut = new CurrentPropertyExistsSpecification();

            var actual = sut.IsSatisfiedBy(application);

            Assert.False(actual);
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: jjokela/DesignPatterns
        static void Main(string[] args)
        {
            MortgageApplication facade   = new MortgageApplication();
            Customer            customer = new Customer {
                Name = "Risto Reipas"
            };
            var amount = 10000;

            var isEligible = facade.IsEligible(customer, amount);

            Console.WriteLine("{0} applies for amount: {1}. Approved: {2}", customer.Name, amount, isEligible);

            Console.ReadLine();
        }
        public void ProduceOfferReturnsCorrectResult()
        {
            var sut = new FinancingHeadlineMortgageApplicationProcessor();

            var dummyApplication = new MortgageApplication();
            var actual           = sut.ProduceOffer(dummyApplication);

            var expected = new[]
            {
                new Heading2Rendering("Financing")
            };

            Assert.Equal(expected, actual);
        }
コード例 #22
0
        public IEnumerable <IRendering> ProduceOffer(MortgageApplication application)
        {
            yield return(new TextRendering("Current property will be sold to finance new property."));

            yield return(new LineBreakRendering());

            var p = new PropertyProcessor
            {
                PriceText = "Estimated sales price"
            };

            foreach (var r in p.ProduceRenderings(application.CurrentProperty))
            {
                yield return(r);
            }
        }
コード例 #23
0
ファイル: Tests.cs プロジェクト: truepele/MortgageChallenge
        public void FixedMortgageForFivePercentDownpaymentAndOverMillionDollarsValueApproved()
        {
            // Arrange
            var mortgage = BuildDefaultProcessor(5, 2000000);
            var app      = new MortgageApplication
            {
                DownpaymentPercentage = 5,
                MortgageType          = MortgageType.Fixed,
                PropertyValue         = 1100000.00
            };
            // Act
            var actualResult = mortgage.ProcessApplication(app);

            // Assert
            Assert.Equal(MortgageApplicationResult.Approved, actualResult);
        }
コード例 #24
0
        public void ProduceOfferReturnsCorrectResult()
        {
            var sut = new RealtyUpsellMortgageApplicationProcessor();

            var dummyApplication = new MortgageApplication();
            var actual           = sut.ProduceOffer(dummyApplication);

            var expected = new IRendering[]
            {
                new Heading1Rendering("Real estate services"),
                new TextRendering("Do you need help selling your current property? Then  lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
                new LineBreakRendering()
            };

            Assert.Equal(expected, actual);
        }
        public IEnumerable <IRendering> ProduceOffer(MortgageApplication application)
        {
            yield return(new BoldRendering("Additional applicants:"));

            yield return(new LineBreakRendering());

            var p = new ApplicantProcessor();

            foreach (var a in application.AdditionalApplicants)
            {
                yield return(new BulletRendering(""));

                foreach (var r in p.ProduceRenderings(a))
                {
                    yield return(r);
                }
            }
        }
コード例 #26
0
        public void IsSatisfiedByReturnsCorrectResult(
            LoanType matchingLoanType,
            LoanType desiredLoanType,
            bool expected)
        {
            var sut = new DesiredLoanTypeMortgageApplicationSpecification
            {
                MatchingLoanType = matchingLoanType
            };
            var application = new MortgageApplication
            {
                DesiredLoanType = desiredLoanType
            };

            var actual = sut.IsSatisfiedBy(application);

            Assert.Equal(expected, actual);
        }
コード例 #27
0
        public IEnumerable <IRendering> ProduceOffer(MortgageApplication application)
        {
            var offer = this.OfferService.GetAdjustableRateAnnuityOffer(application);

            yield return(new Heading2Rendering("Adjustable rate offer"));

            yield return(new BoldRendering("Initial interest rate:"));

            yield return(new TextRendering(" " + offer.InitialRate / 10m + " %"));

            yield return(new LineBreakRendering());

            yield return(new BoldRendering("Term:"));

            yield return(new TextRendering(" " + offer.Term.ToString("D")));

            yield return(new LineBreakRendering());
        }
コード例 #28
0
        public IEnumerable <IRendering> ProduceOffer(MortgageApplication application)
        {
            var offer = this.OfferService.GetInterestOnlyOffer(application);

            yield return(new Heading2Rendering("Interest only offer"));

            yield return(new BoldRendering("Interest rate:"));

            yield return(new TextRendering(" " + offer.Rate / 10m + " %"));

            yield return(new LineBreakRendering());

            yield return(new BoldRendering("Term:"));

            yield return(new TextRendering(" " + offer.Term.ToString("D")));

            yield return(new LineBreakRendering());
        }
コード例 #29
0
ファイル: HomeController.cs プロジェクト: jrades/Net_Project
        public IActionResult Submit(MortgageApplication application)
        {
            if (application.ApplicationId == Guid.Empty)
            {
                application.ApplicationId = Guid.NewGuid();
            }
            bool success = Repository.Add(application);

            if (success)
            {
                Messages.Add(new ResponseMessage(ResponseMessageType.Success, $"Successfully submitted mortage application. Your application id is {application.ApplicationId}"));
            }
            else
            {
                Messages.Add(new ResponseMessage(ResponseMessageType.Error, $"Failed to submit mortage application."));
                return(View("New", application));
            }
            return(RedirectToAction("Index"));
        }
コード例 #30
0
        public void ProduceOfferReturnsCorrectResult(int selfPayment)
        {
            var sut         = new SelfPaymentMortgageApplicationProcessor();
            var application = new MortgageApplication
            {
                SelfPayment = selfPayment
            };

            var actual = sut.ProduceOffer(application);

            var expected = new IRendering[]
            {
                new BoldRendering("Self payment:"),
                new TextRendering(" " + application.SelfPayment),
                new LineBreakRendering()
            };

            Assert.Equal(expected, actual);
        }
コード例 #31
0
  public static void Main(string[] args)
  {
    // Create Facade
    MortgageApplication mortgage = 
                   new MortgageApplication( 125000 );

    // Call subsystem through Facade
    mortgage.IsEligible( 
                new Customer( "Gabrielle McKinsey" ) );

  }