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);
        }
        public void ProduceOfferReturnsCorrectResult(
            string locationName,
            string currentTime)
        {
            // Arrange
            var moqRepo = new MockRepository(MockBehavior.Default);

            var sut = new DateAndLocationMortgageApplicationProcessor
            {
                LocationProvider = moqRepo.Create<ILocationProvider>().Object,
                TimeProvider = moqRepo.Create<ITimeProvider>().Object
            };

            Mock.Get(sut.LocationProvider)
                .Setup(lp => lp.GetCurrentLocationName())
                .Returns(locationName);
            Mock.Get(sut.TimeProvider)
                .Setup(tp => tp.GetCurrentTime())
                .Returns(DateTimeOffset.Parse(currentTime));

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

            // Assert
            var expected = new IRendering[]
            {
                new TextRendering(
                    locationName +
                    ", " +
                    DateTimeOffset.Parse(currentTime).ToString("D")),
                new LineBreakRendering()
            };
            Assert.Equal(expected, actual);
        }
        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);
        }
        public void ProduceOfferReturnsCorrectResult(
            string street,
            string postalCode,
            string country,
            int price,
            int size)
        {
            var sut = new CurrentPropertyMortgageApplicationProcessor();
            var application = new MortgageApplication
            {
                CurrentProperty = new Property
                {
                    Address = new Address
                    {
                        Street = street,
                        PostalCode = postalCode,
                        Country = country
                    },
                    Price = price,
                    Size = size
                }
            };

            var actual = sut.ProduceOffer(application);

            var expected = new IRendering[]
            {
                new TextRendering("Current property will be sold to finance new property."),
                new LineBreakRendering(),
            }
            .Concat(new PropertyProcessor { PriceText = "Estimated sales price" }.ProduceRenderings(application.CurrentProperty));
            Assert.Equal(expected, actual);
        }
        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 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);
        }
        public IEnumerable<IRendering> ProduceOffer(MortgageApplication application)
        {
            if (this.Specification.IsSatisfiedBy(application))
                return this.TruthProcessor.ProduceOffer(application);

            return Enumerable.Empty<IRendering>();
        }
        public void ProduceOfferReturnsCorrectResult(
            int initialRate,
            string term)
        {
            var application = new MortgageApplication();
            var offer = new AdjustableRateAnnuityOffer
            {
                InitialRate = initialRate,
                Term = DateTimeOffset.Parse(term)
            };
            var sut = new AdjustableRateAnnuityOfferMortgageApplicationProcessor
            {
                OfferService = new Mock<IOfferService>().Object
            };
            Mock.Get(sut.OfferService)
                .Setup(o => o.GetAdjustableRateAnnuityOffer(application))
                .Returns(offer);

            var actual = sut.ProduceOffer(application);

            var expected = new IRendering[]
            {
                new Heading2Rendering("Adjustable rate offer"),
                new BoldRendering("Initial interest rate:"),
                new TextRendering(" " + offer.InitialRate / 10m + " %"),
                new LineBreakRendering(),
                new BoldRendering("Term:"),
                new TextRendering(" " + offer.Term.ToString("D")),
                new LineBreakRendering()
            };
            Assert.Equal(expected, actual);
        }
 public IEnumerable<IRendering> ProduceOffer(MortgageApplication application)
 {
     return new PropertyProcessor
     {
         PriceText = "Asking price"
     }
     .ProduceRenderings(application.Property);
 }
        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;
        }
 public IEnumerable<IRendering> ProduceOffer(
     MortgageApplication application)
 {
     yield return new TextRendering(
         this.LocationProvider.GetCurrentLocationName() +
         ", " +
         this.TimeProvider.GetCurrentTime().ToString("D"));
     yield return new LineBreakRendering();
 }
        public void IsSatisfiedByAplicationWithNoAdditionalApplicantsReturnsFalse()
        {
            var application = new MortgageApplication();
            var sut = new AnyAdditionalApplicantsSpecification();

            var actual = sut.IsSatisfiedBy(application);

            Assert.False(actual);
        }
        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);
        }
        public void IsSatisfiedByReturnsFalseIfCurrentPropertyIsNull()
        {
            var application = new MortgageApplication
            {
                CurrentProperty = null
            };
            var sut = new CurrentPropertyExistsSpecification();

            var actual = sut.IsSatisfiedBy(application);

            Assert.False(actual);
        }
        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);
        }
        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;
        }
        public void IsSatisfiedByReturnsTrueIfCurrentPropertyHasValue()
        {
            var application = new MortgageApplication
            {
                CurrentProperty = new Property()
            };
            var sut = new CurrentPropertyExistsSpecification();

            var actual = sut.IsSatisfiedBy(application);

            Assert.True(actual);
        }
        public IEnumerable<IRendering> ProduceOffer(MortgageApplication application)
        {
            yield return new TextRendering(
                "Dear " +
                application.PrimaryApplicant.Contact.Name + ", " +
                application.PrimaryApplicant.Contact.Address.Street + ", " +
                application.PrimaryApplicant.Contact.Address.PostalCode + ", " +
                application.PrimaryApplicant.Contact.Address.Country);
            yield return new LineBreakRendering();

            yield return new TextRendering("It gives us great pleasure to 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();
        }
        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);
        }
        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;
            }
        }
        public IEnumerable<IRendering> ProduceOffer(MortgageApplication application)
        {
            var offer = this.OfferService.GetFixedRateAnnuityOffer(application);

            yield return new Heading2Rendering("Fixed rate 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();
        }
        public void ProduceOfferReturnsCorrectResult()
        {
            var sut = new OfferIntroductionMortgageApplicationProcessor();

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

            var expected = new IRendering[]
            {
                new Heading1Rendering("Loan offer"),
                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."),
                new LineBreakRendering()
            };
            Assert.Equal(expected, actual);
        }
        public IEnumerable<IRendering> ProduceOffer(MortgageApplication application)
        {
            yield return new Heading2Rendering("Desired loan");

            yield return new BoldRendering("Loan type:");
            yield return new TextRendering(" " + application.DesiredLoanType);
            yield return new LineBreakRendering();

            yield return new BoldRendering("Term:");
            yield return new TextRendering(" " + application.DesiredTerm + " years.");
            yield return new LineBreakRendering();

            yield return new BoldRendering("Frequency:");
            yield return new TextRendering(" " + application.DesiredFrequency);
            yield return new LineBreakRendering();
        }
        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);
        }
        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);
        }
        public void ProduceOfferReturnsCorrectResult(
            string name,
            string street,
            string postalCode,
            string country)
        {
            var sut = new GreetingMortgageApplicationProcessor();
            var application = new MortgageApplication
            {
                PrimaryApplicant = new Applicant
                {
                    Contact = new Contact
                    {
                        Name = name,
                        Address = new Address
                        {
                            Street = street,
                            PostalCode = postalCode,
                            Country = country
                        }
                    }
                }
            };

            var actual = sut.ProduceOffer(application);

            var expected = new IRendering[]
            {
                new TextRendering(
                    "Dear " +
                    name + ", " +
                    street + ", " +
                    postalCode + ", " +
                    country),
                new LineBreakRendering(),
                new TextRendering("It gives us great pleasure to 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 void ProduceOfferConcatenatesResultFromAllComposedNodes()
        {
            // Arrange
            var application = new MortgageApplication();

            var moqRepo = new MockRepository(MockBehavior.Default);
            var r1 = moqRepo.Create<IRendering>().Object;
            var r2 = moqRepo.Create<IRendering>().Object;
            var r3 = moqRepo.Create<IRendering>().Object;
            var r4 = moqRepo.Create<IRendering>().Object;
            var r5 = moqRepo.Create<IRendering>().Object;
            var r6 = moqRepo.Create<IRendering>().Object;
            var r7 = moqRepo.Create<IRendering>().Object;
            var r8 = moqRepo.Create<IRendering>().Object;
            var r9 = moqRepo.Create<IRendering>().Object;

            var node1 = moqRepo.Create<IMortgageApplicationProcessor>();
            var node2 = moqRepo.Create<IMortgageApplicationProcessor>();
            var node3 = moqRepo.Create<IMortgageApplicationProcessor>();

            node1.Setup(n => n.ProduceOffer(application))
                .Returns(new[] { r1, r2, r3 });
            node2.Setup(n => n.ProduceOffer(application))
                .Returns(new[] { r4, r5, r6 });
            node3.Setup(n => n.ProduceOffer(application))
                .Returns(new[] { r7, r8, r9 });

            var sut = new CompositeMortgageApplicationProcessor
            {
                Nodes = new[] { node1.Object, node2.Object, node3.Object }
            };

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

            // Assert
            var expected = new[] { r1, r2, r3, r4, r5, r6, r7, r8, r9 };
            Assert.Equal(expected, actual);
        }
        public void ProduceOfferReturnsCorrectResult(
            string name,
            string street,
            string postalCode,
            string country,
            int yearlyIncome,
            string taxAuthority)
        {
            var sut = new PrimaryApplicantMortgageApplicationProcessor();
            var application = new MortgageApplication
            {
                PrimaryApplicant = new Applicant
                {
                    Contact = new Contact
                    {
                        Name = name,
                        Address = new Address
                        {
                            Street = street,
                            PostalCode = postalCode,
                            Country = country
                        }
                    },
                    YearlyIncome = yearlyIncome,
                    TaxationAuthority = taxAuthority
                }
            };

            var actual = sut.ProduceOffer(application);

            var expected = new IRendering[]
            {
                new BoldRendering("Primary applicant:")
            }
            .Concat(new ApplicantProcessor().ProduceRenderings(
                application.PrimaryApplicant));
            Assert.Equal(expected, actual);
        }
        public void ProduceOfferReturnsCorrectResultWithOneAdditionalApplicant(
            string name,
            string street,
            string postalCode,
            string country,
            int yearlyIncome,
            string taxAuthority)
        {
            var applicant = new Applicant
            {
                Contact = new Contact
                {
                    Name = name,
                    Address = new Address
                    {
                        Street = street,
                        PostalCode = postalCode,
                        Country = country
                    }
                },
                YearlyIncome = yearlyIncome,
                TaxationAuthority = taxAuthority
            };
            var application = new MortgageApplication();
            application.AdditionalApplicants.Add(applicant);
            var sut = new AdditionalApplicantsMortgageApplicationProcessor();

            var actual = sut.ProduceOffer(application);

            var expected = new IRendering[]
            {
                new BoldRendering("Additional applicants:"),
                new LineBreakRendering(),
                new BulletRendering("")
            }
            .Concat(new ApplicantProcessor().ProduceRenderings(applicant));
            Assert.Equal(expected, actual);
        }