public void ReturnComparisonForFirstProduct_WithPartialKnownExpectedValues()
        {
            var products = new List <LoanProduct>
            {
                new LoanProduct(1, "a", 1),
                new LoanProduct(2, "b", 2),
                new LoanProduct(3, "c", 3)
            };

            var sut = new ProductComparer(new LoanAmount("USD", 200_000m), products);

            List <MonthlyRepaymentComparison> comparisons = sut.CompareMonthlyRepayments(new LoanTerm(30));

            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            Assert.That(comparisons,
                        Has.Exactly(1).Property("ProductName").EqualTo("a")
                        .And.Property("InterestRate").EqualTo(1)
                        .And.Property("MonthlyRepayment").GreaterThan(0));

            Assert.That(comparisons, Has.Exactly(1)
                        .Matches <MonthlyRepaymentComparison>(
                            item => item.ProductName == "a" &&
                            item.InterestRate == 1 &&
                            item.MonthlyRepayment > 0));
        }
        public void RespectValueInequality()
        {
            var a = new MonthlyRepaymentComparison("a", 42.42m, 22.22m);
            var b = new MonthlyRepaymentComparison("a", 42.42m, 23.22m);

            Assert.That(a, Is.Not.EqualTo(b));
        }
Example #3
0
        public void ReturnComparisonForFirstProduct()
        {
            List <MonthlyRepaymentComparison> comparisons = sut.CompareMonthlyRepayments(new LoanTerm(30));
            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            Assert.That(comparisons, Does.Contain(expectedProduct));
        }
Example #4
0
        public void ComparisonsContainsExpectedProduct()
        {
            List <MonthlyRepaymentComparison> comparisons = _comparer.CompareMonthlyRepayments(new LoanTerm(30));

            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            Assert.That(comparisons, Does.Contain(expectedProduct));
        }
Example #5
0
        public void ReturnComparisonForFirstProduct()
        {
            List <MonthlyRepaymentComparison> comparisons = sut.CompareMonthlyRepayments(new LoanTerm(30));

            // You need to know the exact value to run this test.
            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            Assert.That(comparisons, Does.Contain(expectedProduct));
        }
Example #6
0
        public void ReturnComparisonForFirstProduct()
        {
            List <MonthlyRepaymentComparison> comparisons = sut.CompareMonthlyRepayments(new LoanTerm(30));

            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            // Check that the list of comparisons contains the expected loan product (Will need to know the expected monthly repayment)
            Assert.That(comparisons, Does.Contain(expectedProduct));
        }
Example #7
0
        public void ReturnComparisonForFirstProduct()
        {
            List <MonthlyRepaymentComparison> comparisons =
                sut.CompareMonthlyRepayments(new LoanTerm(30));

            //Need to know the expected monthly repayment (third parameter)
            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            Assert.That(comparisons, Does.Contain(expectedProduct));
        }
Example #8
0
        public void ReturnComparisonForFirstProduct_withNotKnowingAllValues()
        {
            List <MonthlyRepaymentComparison> comparisons = sut.CompareMonthlyRepayments(new LoanTerm(30));
            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            Assert.That(comparisons, Has.Exactly(1)
                        .Property("ProductName")
                        .EqualTo("a")
                        );
        }
        public void ReturnComparisonForFirstProduct()
        {
            List <MonthlyRepaymentComparison> comparisons =
                sut.CompareMonthlyRepayments(new LoanTerm(30));

            /**
             * Assert that a specific collection exists.
             * We need to know the expected monthly repayment (643.28)
             */
            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            Assert.That(comparisons, Does.Contain(expectedProduct));
        }
Example #10
0
        public void ReturnCorrectnumberOfComparision()
        {
            List <MonthlyRepaymentComparison> comparisons = sut.CompareMonthlyRepayments(new LoanTerm(30));

            Assert.That(comparisons, Has.Exactly(3).Items);

            Assert.That(comparisons, Is.Unique);

            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            //Test if expected product is there.
            Assert.That(comparisons, Does.Contain(expectedProduct));
        }
Example #11
0
        public void ReturnComparisonForFirstProduct()
        {
            var product = new Gen.List <LoanProduct>
            {
                new LoanProduct(1, "a", 1),
                new LoanProduct(2, "b", 2),
                new LoanProduct(3, "c", 3),
            };

            var sut = new ProductComparer(new LoanAmount("USD", 200_000m), product);

            Gen.List <MonthlyRepaymentComparison> comparisons = sut.CompareMonthlyRepayments(new LoanTerm(30));

            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            Assert.That(comparisons, Does.Contain(expectedProduct));
        }
        public override ConstraintResult ApplyTo <TActual>(TActual actual)
        {
            MonthlyRepaymentComparison comparison = actual as MonthlyRepaymentComparison;

            if (comparison is null)
            {
                return(new ConstraintResult(this, actual, ConstraintStatus.Error));
            }
            if (comparison.InterestRate == ExpectedInterestRate &&
                comparison.ProductName == ExpectedProductName &&
                comparison.MonthlyRepayment > 0)
            {
                return(new ConstraintResult(this, actual, ConstraintStatus.Success));
            }

            return(new ConstraintResult(this, actual, ConstraintStatus.Failure));
        }
Example #13
0
        public void ReturnComparisonForFirstProduct_WithPartialKnownExpectedValues()
        {
            List <MonthlyRepaymentComparison> comparisons = sut.CompareMonthlyRepayments(new LoanTerm(30));

            var expectedProduct = new MonthlyRepaymentComparison("a", 1, 643.28m);

            Assert.That(comparisons, Has.Exactly(1).Property("ProductName").EqualTo("a")
                        .And
                        .Property("InterestRate").EqualTo(1)
                        .And
                        .Property("MonthlyRepayment").GreaterThan(0));

            Assert.That(comparisons, Has.Exactly(1)
                        .Matches <MonthlyRepaymentComparison>(
                            item => item.ProductName == "a" &&
                            item.InterestRate == 1 &&
                            item.MonthlyRepayment > 0));
        }
Example #14
0
        public override ConstraintResult ApplyTo <TActual>(TActual actual)
        {
            MonthlyRepaymentComparison comparison = actual as MonthlyRepaymentComparison;

            //if "actual" parameter is not of the correct type, in this case a MonthlyRepaymentComparison,
            //then the cast above will fail and comparison will be null below, working as a type check.
            if (comparison is null)
            {
                return(new ConstraintResult(this, actual, ConstraintStatus.Error));
            }

            //Since now we know we are dealing with a MonthlyRepaymentComparison parameter, we can start comparing
            if (comparison.ProductName == ExpectedProductName &&
                comparison.InterestRate == ExpectedInterestRate &&
                comparison.MonthlyRepayment > 0)
            {
                return(new ConstraintResult(this, actual, ConstraintStatus.Success));
            }

            return(new ConstraintResult(this, actual, ConstraintStatus.Failure));
        }
Example #15
0
        // Need to implement the 'ApplyTo' method when inheriting from 'Constraint' class.
        // param: actual value we're testing against
        public override ConstraintResult ApplyTo <TActual>(TActual actual)
        {
            // This code decides ultimately whether the assert will pass or fail

            // Test if actual value is of type MonthlyRepaymentComparison
            MonthlyRepaymentComparison comparison = actual as MonthlyRepaymentComparison;

            if (comparison is null) // if actual value is not a MonthlyRepaymentComparison
            {
                // param1: reference to the constraint, 'this'. param2: actual value testing against. param3: constraint status
                return(new ConstraintResult(this, actual, ConstraintStatus.Error));
            }

            // if actual value is a MonthlyRepaymentComparison object, we can compare its values with a set of expected values
            if (comparison.InterestRate == ExpectedInterestRate && comparison.ProductName == ExpectedProductName && comparison.MonthlyRepayment > 0)
            {
                return(new ConstraintResult(this, actual, ConstraintStatus.Success));
            }

            // if InterestRate or ProductName is different OR MonthlyPayment is not greater than 0
            return(new ConstraintResult(this, actual, ConstraintStatus.Failure));
        }