public void Accept()
        {
            LoanProduct     product     = new LoanProduct(99, "Loan", 5.25m);
            LoanAmount      amount      = new LoanAmount("USD", 200_000);
            LoanApplication application = new LoanApplication(42,
                                                              product,
                                                              amount,
                                                              "Bruno",
                                                              31,
                                                              "Mullerstr. 3, Germany", 65_000);

            var mockIdentityVerifier = new Mock <IIdentityVerifier>();

            // Setup mock with paremeters and returns.
            //mockIdentityVerifier.Setup(x => x.Validate("Bruno", 31, "Mullerstr. 3, Germany")).Returns(true);

            // Setup mock with out parameter.
            //bool isValidOutValue = true;
            //mockIdentityVerifier.Setup(x => x.Validate("Bruno",
            //                                            31,
            //                                            "Mullerstr. 3, Germany",
            //                                            out isValidOutValue));

            // Setup mock with a ref parameter.
            mockIdentityVerifier.Setup(x => x.Validate("Bruno",
                                                       31,
                                                       "Mullerstr. 3, Germany",
                                                       ref It.Ref <IdentityVerificationStatus> .IsAny))
            .Callback(new ValidateCallback(
                          (string applicantName,
                           int applicantAge,
                           string applicantAddress,
                           ref IdentityVerificationStatus status) =>
                          status = new IdentityVerificationStatus(true)));

            //// Using the class 'It', you can specify a specific condition to match a field.
            //// In the case below, the method will pass the tests independent of the typed values on fields.
            //// That's recommend to be used only when the value of the parameter is non-deterministic
            //mockIdentityVerifier.Setup(x => x.Validate(
            //                             It.IsAny<string>(),
            //                             It.IsAny<int>(),
            //                             It.IsAny<string>()))
            //                             .Returns(true);

            var mockCreditScorer = new Mock <ICreditScorer>();

            var sut = new LoanApplicationProcessor(mockIdentityVerifier.Object, mockCreditScorer.Object);

            sut.Process(application);

            Assert.That(application.GetIsAccepted(), Is.True);
        }
Beispiel #2
0
        public void Accept()
        {
            LoanProduct product     = new LoanProduct(99, "Loan", 5.25m);
            LoanAmount  amount      = new LoanAmount("USD", 200_000);
            var         application = new LoanApplication(42,
                                                          product,
                                                          amount,
                                                          "Sarah",
                                                          25,
                                                          "133 Pluralsight Drive, Draper, Utah",
                                                          65_000);

            var mockIdentityVerifier = new Mock <IIdentityVerifier>();

            //mockIdentityVerifier.Setup(x => x.Validate(It.IsAny<string>(),
            //                                           It.IsAny<int>(),
            //                                           It.IsAny<string>()))
            //                    .Returns(true);
            //mockIdentityVerifier.Setup(x => x.Validate("Sarah",
            //                                           25,
            //                                           "133 Pluralsight Drive, Draper, Utah"))
            //                    .Returns(true);

            //bool isValidOutValue = true;
            //mockIdentityVerifier.Setup(x => x.Validate("Sarah",
            //                                           25,
            //                                           "133 Pluralsight Drive, Draper, Utah",
            //                                           out isValidOutValue));

            mockIdentityVerifier
            .Setup(x => x.Validate("Sarah",
                                   25,
                                   "133 Pluralsight Drive, Draper, Utah",
                                   ref It.Ref <IdentityVerificationStatus> .IsAny))
            .Callback(new ValidateCallback(
                          (string applicantName,
                           int applicantAge,
                           string applicantAddress,
                           ref IdentityVerificationStatus status) =>
                          status = new IdentityVerificationStatus(true)));


            var mockCreditScorer = new Mock <ICreditScorer>();

            var sut = new LoanApplicationProcessor(mockIdentityVerifier.Object,
                                                   mockCreditScorer.Object);

            sut.Process(application);

            Assert.That(application.GetIsAccepted(), Is.True);
        }
 public void Validate(string applicantName, int applicantAge, string applicantAddress,
                      ref IdentityVerificationStatus status)
 {
     throw new NotImplementedException();
 }