public async Task Then_Handler_Returns_True_If_Allowed_To_Submit()
        {
            ApplyRepository.Setup(r => r.CanSubmitApplication(It.IsAny <Guid>())).ReturnsAsync(true);

            var request = new SubmitApplicationRequest
            {
                ApplicationId       = Guid.NewGuid(),
                SubmittingContactId = Guid.NewGuid(),
                ApplyData           = new ApplyData
                {
                    ApplyDetails = new ApplyDetails(),
                    Sequences    = new List <ApplySequence>
                    {
                        new ApplySequence
                        {
                            SequenceNo = 1,
                            Sections   = new List <ApplySection>
                            {
                                new ApplySection
                                {
                                    SectionNo = 1
                                }
                            }
                        }
                    }
                }
            };

            var result = await Handler.Handle(request, new CancellationToken());

            Assert.IsTrue(result);
            ApplyRepository.Verify(r => r.SubmitApplication(It.IsAny <Guid>(), It.IsAny <ApplyData>(), It.IsAny <FinancialData>(), It.IsAny <Guid>()), Times.Once);
        }
Пример #2
0
        public HomeController(IConfiguration configuration)
        {
            Configuration = configuration;

            //DATA ACCESS LAYER
            applyRepository = new ApplyRepository(configuration);
        }
        public override void Arrange()
        {
            base.Arrange();

            // the QnAData is replaced for these tests
            ApplyRepository.Setup(r => r.GetSection(ApplicationId, 1, 1, UserId)).ReturnsAsync(new ApplicationSection()
            {
                Status  = ApplicationSectionStatus.Evaluated,
                QnAData = new QnAData()
                {
                    Pages = new List <Page>
                    {
                        new Page
                        {
                            PageId    = "1",
                            Questions = new List <Question>
                            {
                                new Question()
                                {
                                    QuestionId = "Q1",
                                    Input      = new Input {
                                        Type = "Text"
                                    }
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>()
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "2"
                                }
                            },
                            Feedback = new List <Feedback>()
                            {
                                new Feedback {
                                    IsNew = true, IsCompleted = true
                                }
                            }
                        },
                        new Page
                        {
                            PageId   = "2",
                            Feedback = new List <Feedback>()
                            {
                                new Feedback {
                                    IsNew = true, IsCompleted = true
                                }
                            }
                        }
                    }
                }
            });

            AnswerQ1.Value = "QuestionAnswer";

            Validator.Setup(v => v.Validate(It.Is <string>(p => p == QuestionIdQ1), It.Is <Answer>(p => p.QuestionId == AnswerQ1.QuestionId))).Returns(
                new List <KeyValuePair <string, string> >());
        }
        public void Then_prevent_submission_if_another_user_has_already_submitted()
        {
            var request = new SubmitApplicationRequest {
                ApplicationId = differentAppGuid, SubmittingContactId = differentAppGuid
            };

            Handler.Handle(request, new CancellationToken()).Wait();

            ApplyRepository.Verify(r => r.SubmitApplication(It.IsAny <Guid>(), It.IsAny <ApplyData>(), It.IsAny <FinancialData>(), It.IsAny <Guid>()), Times.Never);
        }
Пример #5
0
        public void Then_section_is_not_saved_with_those_answers()
        {
            Handler.Handle(new UpdatePageAnswersRequest(ApplicationId, UserId, 1, 1, "5",
                                                        new List <Answer>()
            {
                /* no answers are provided */
            },
                                                        true), new CancellationToken()).Wait();

            ApplyRepository.Verify(r => r.SaveSection(It.IsAny <ApplicationSection>(), UserId), Times.Never);
        }
Пример #6
0
        public void Then_RequestedFeedbackAnswered_IsFalse()
        {
            Handler.Handle(new UpdatePageAnswersRequest(ApplicationId, UserId, 1, 1, "1",
                                                        new List <Answer>()
            {
                AnswerQ1
            },
                                                        true), new CancellationToken()).Wait();


            ApplyRepository.Verify(r => r.SaveSection(It.Is <ApplicationSection>(section => !section.QnAData.RequestedFeedbackAnswered.Value), UserId));
        }
        public async Task Then_Handler_Returns_False_If_Not_Allowed_To_Submit()
        {
            ApplyRepository.Setup(r => r.CanSubmitApplication(It.IsAny <Guid>())).ReturnsAsync(false);

            var request = new SubmitApplicationRequest {
                ApplicationId = Guid.NewGuid(), SubmittingContactId = Guid.NewGuid()
            };

            var result = await Handler.Handle(request, new CancellationToken());

            Assert.IsFalse(result);
            ApplyRepository.Verify(r => r.SubmitApplication(It.IsAny <Guid>(), It.IsAny <ApplyData>(), It.IsAny <FinancialData>(), It.IsAny <Guid>()), Times.Never);
        }
        public void Then_allow_submission_if_user_is_the_one_whom_already_submitted()
        {
            var request = new SubmitApplicationRequest
            {
                ApplicationId = sameAppGuid, SubmittingContactId = sameAppGuid,
                ApplyData     = new ApplyData
                {
                    ApplyDetails = new ApplyDetails(),
                    Sequences    = new List <ApplySequence>()
                }
            };

            Handler.Handle(request, new CancellationToken()).Wait();

            ApplyRepository.Verify(r => r.SubmitApplication(It.IsAny <Guid>(), It.IsAny <ApplyData>(), It.IsAny <FinancialData>(), It.IsAny <Guid>()), Times.Once);
        }
Пример #9
0
        /// <summary>
        /// 会员积分转让申请
        /// </summary>
        /// <returns></returns>
        public static Result <decimal> ScoreSellApply(int userId, decimal score)
        {
            #region 数据验证
            var result = new Result <decimal>();
            if (userId <= 0)
            {
                result.Message = "用户信息无效";
                return(result);
            }

            var memberInfo = MemberRepository.Get(userId);
            if (memberInfo == null)
            {
                result.Message = "会员信息无效";
                return(result);
            }
            memberInfo.TotalWithdrawScore += score;
            if (score <= 0 || memberInfo.TotalWithdrawScore > memberInfo.TotalScore)
            {
                result.Message = "转让的积分数量无效";
                return(result);
            }
            #endregion

            var dbResult = MemberRepository.Update(memberInfo);
            if (dbResult)
            {
                result.Code = ResultCode.Success;
                result.Data = memberInfo.TotalWithdrawScore;
                //添加用户积分申请记录
                ApplyRepository.Add(new MemberApplyModel()
                {
                    UserId     = userId,
                    ApType     = ApplyType.ScoreSell,
                    ApValue    = score,
                    Status     = ApplyStatus.Applying,
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                });
            }
            else
            {
                result.Code    = ResultCode.Error;
                result.Message = "数据库操作异常";
            }
            return(result);
        }
Пример #10
0
        public void Then_validation_fail_if_application_is_not_still_in_draft()
        {
            AnswerQ1.Value     = "Yes";
            AnswerQ1Dot1.Value = "SomeAnswer";

            ApplyRepository.Setup(r => r.GetSection(ApplicationId, 1, 1, UserId)).ReturnsAsync(new ApplicationSection()
            {
                Status  = ApplicationSectionStatus.Evaluated,
                QnAData = QnAData
            });

            Validator.Setup(v => v.Validate(It.Is <string>(p => p == QuestionIdQ1), It.Is <Answer>(p => p.QuestionId == AnswerQ1.QuestionId)))
            .Returns
                ((string questionId, Answer answer) => !string.IsNullOrEmpty(answer.Value)
                    ? new List <KeyValuePair <string, string> >()
                    : new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>(questionId, $"{questionId} is required")
            });

            Validator.Setup(v => v.Validate(It.Is <string>(p => p == QuestionIdQ1Dot1), It.Is <Answer>(p => p.QuestionId == AnswerQ1Dot1.QuestionId)))
            .Returns
                ((string questionId, Answer answer) => !string.IsNullOrEmpty(answer.Value)
                    ? new List <KeyValuePair <string, string> >()
                    : new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>(questionId, $"{questionId} is required")
            });

            var result = Handler.Handle(new UpdatePageAnswersRequest(ApplicationId, UserId, 1, 1, "1",
                                                                     new List <Answer>()
            {
                AnswerQ1,
                AnswerQ1Dot1
            }, true), new CancellationToken()).Result;

            result.ValidationPassed.Should().BeFalse();
            result.ValidationErrors.Select(v => v.Key).Distinct().Should().ContainSingle(AnswerQ1.QuestionId);

            // Make sure it has verified the entirety of Question 1
            ValidatorFactory.Verify(v => v.Build(It.Is <Question>(question => question.QuestionId == AnswerQ1.QuestionId)));
            Validator.Verify(v => v.Validate(QuestionIdQ1, AnswerQ1));

            ValidatorFactory.Verify(v => v.Build(It.Is <Question>(question => question.QuestionId == AnswerQ1Dot1.QuestionId)));
            Validator.Verify(v => v.Validate(QuestionIdQ1Dot1, AnswerQ1Dot1));
        }
        public void Then_section_is_saved_with_the_existing_answers()
        {
            Handler.Handle(new UpdatePageAnswersRequest(ApplicationId, UserId, 1, 1, "3",
                                                        new List <Answer>()
            {
                AnswerQ4,
                AnswerQ5
            },
                                                        false), new CancellationToken()).Wait();

            ApplyRepository.Verify(r => r.SaveSection(It.Is <ApplicationSection>(
                                                          section =>
                                                          section.QnAData.Pages.First(p => p.PageId == "3").PageOfAnswers[0].Answers[0].QuestionId == _existingAnswerQ4.QuestionId &&
                                                          section.QnAData.Pages.First(p => p.PageId == "3").PageOfAnswers[0].Answers[0].Value == _existingAnswerQ4.Value), UserId), Times.Once());

            ApplyRepository.Verify(r => r.SaveSection(It.Is <ApplicationSection>(
                                                          section =>
                                                          section.QnAData.Pages.First(p => p.PageId == "3").PageOfAnswers[0].Answers[1].QuestionId == _existingAnswerQ5.QuestionId &&
                                                          section.QnAData.Pages.First(p => p.PageId == "3").PageOfAnswers[0].Answers[1].Value == _existingAnswerQ5.Value), UserId), Times.Once());
        }
        public void Then_section_is_saved_with_those_answers()
        {
            Handler.Handle(new UpdatePageAnswersRequest(ApplicationId, UserId, 1, 1, "1",
                                                        new List <Answer>()
            {
                AnswerQ1,
                AnswerQ1Dot1
            },
                                                        true), new CancellationToken()).Wait();

            ApplyRepository.Verify(r => r.SaveSection(It.Is <ApplicationSection>(
                                                          section =>
                                                          section.QnAData.Pages.First(p => p.PageId == "1").PageOfAnswers[0].Answers[0].QuestionId == AnswerQ1.QuestionId &&
                                                          (string)section.QnAData.Pages.First(p => p.PageId == "1").PageOfAnswers[0].Answers[0].Value == AnswerQ1.Value), UserId));

            ApplyRepository.Verify(r => r.SaveSection(It.Is <ApplicationSection>(
                                                          section =>
                                                          section.QnAData.Pages.First(p => p.PageId == "1").PageOfAnswers[0].Answers[1].QuestionId == AnswerQ1Dot1.QuestionId &&
                                                          section.QnAData.Pages.First(p => p.PageId == "1").PageOfAnswers[0].Answers[1].Value == AnswerQ1Dot1.Value), UserId));
        }
Пример #13
0
        public async Task When_Versions_Has_One_Version_And_StandardReference_Set_Then_WithdrawalType_Should_Be_Version()
        {
            // Arrange

            ApplyRepository.Setup(m => m.GetWithdrawalApplications(It.IsAny <string>(), "New", "SubmittedDate", 0, 10, 1))
            .ReturnsAsync(new ApplicationsResult()
            {
                TotalCount    = 1,
                PageOfResults = new List <Domain.Entities.ApplicationListItem>()
                {
                    new Domain.Entities.ApplicationListItem()
                    {
                        StandardApplicationType = StandardApplicationTypes.VersionWithdrawal,
                        StandardReference       = "ST0205",
                        Versions = "[\"1.0\"]"
                    }
                }
            });

            // Act

            var paginatedList = await Handler.Handle(
                new WithdrawalApplicationsRequest(
                    new Guid().ToString(), // organisation id
                    "New",                 // reviewstatus
                    "SubmittedDate",       // sortcolumn
                    0,                     // sort ascending
                    10,                    // page size
                    1,                     // page index
                    6                      // page set size
                    ),
                new CancellationToken());

            // Assert

            paginatedList.Should().NotBeNull();
            paginatedList.Items.Should().HaveCount(1);
            paginatedList.Items[0].WithdrawalType.Should().Be(WithdrawalTypes.Version);
        }
Пример #14
0
        /// <summary>
        /// 会员申请提现
        /// </summary>
        /// <returns></returns>
        public static Result <int> WithdrawalApply(int userId, decimal amount)
        {
            #region 数据验证
            var result = new Result <int>();
            if (userId <= 0)
            {
                result.Message = "用户信息无效";
                return(result);
            }
            if (amount <= 0)
            {
                result.Message = "申请提现的金额无效";
                return(result);
            }
            #endregion

            //添加用户提现申请记录
            var iRet = ApplyRepository.Add(new MemberApplyModel()
            {
                UserId     = userId,
                ApType     = ApplyType.Withdrawal,
                ApValue    = amount,
                Status     = ApplyStatus.Applying,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            });
            if (iRet > 0)
            {
                result.Code = ResultCode.Success;
                result.Data = iRet;
            }
            else
            {
                result.Code    = ResultCode.Error;
                result.Message = "提交提现申请失败";
            }
            return(result);
        }
        public async Task Then_standard_applications_are_retrieved()
        {
            await Handler.Handle(new GetApplicationsRequest(new Guid(), ApplicationTypes.Standard), new CancellationToken());

            ApplyRepository.Verify(r => r.GetStandardApplications(It.IsAny <Guid>()), Times.Once);
        }
        public async Task Then_application_created_by_orgainisation_are_returned()
        {
            await Handler.Handle(new GetApplicationsRequest(Guid.NewGuid(), false), new CancellationToken());

            ApplyRepository.Verify(r => r.GetOrganisationApplications(It.IsAny <Guid>()), Times.Once);
        }
Пример #17
0
        public async Task Then_organisation_withdrawal_applications_are_retrieved()
        {
            await Handler.Handle(new GetApplicationsRequest(new Guid(), ApplicationTypes.OrganisationWithdrawal), new CancellationToken());

            ApplyRepository.Verify(r => r.GetOrganisationWithdrawalApplications(It.IsAny <Guid>()), Times.Once);
        }
        public async Task Then_FinancialData_Is_Persisted()
        {
            ApplyRepository.Setup(r => r.CanSubmitApplication(It.IsAny <Guid>())).ReturnsAsync(true);

            var request = new SubmitApplicationRequest
            {
                ApplicationId       = Guid.NewGuid(),
                SubmittingContactId = Guid.NewGuid(),
                ApplyData           = new ApplyData
                {
                    ApplyDetails = new ApplyDetails(),
                    Sequences    = new List <ApplySequence>
                    {
                        new ApplySequence
                        {
                            SequenceNo = 1,
                            Sections   = new List <ApplySection>
                            {
                                new ApplySection
                                {
                                    SectionNo = 1
                                }
                            }
                        }
                    }
                },
                FinancialData = new FinancialData
                {
                    TurnOver                    = 1,
                    Depreciation                = 2,
                    ProfitLoss                  = 3,
                    Dividends                   = 4,
                    IntangibleAssets            = 5,
                    Assets                      = 6,
                    Liabilities                 = 7,
                    ShareholderFunds            = 8,
                    Borrowings                  = 9,
                    AccountingReferenceDate     = new DateTime(2021, 1, 1),
                    AccountingPeriod            = 10,
                    AverageNumberofFTEEmployees = 11
                }
            };

            var result = await Handler.Handle(request, new CancellationToken());

            Assert.IsTrue(result);
            ApplyRepository.Verify(r => r.SubmitApplication(It.IsAny <Guid>(), It.IsAny <ApplyData>(), It.Is <FinancialData>(
                                                                x => x.TurnOver == 1 &&
                                                                x.Depreciation == 2 &&
                                                                x.ProfitLoss == 3 &&
                                                                x.Dividends == 4 &&
                                                                x.IntangibleAssets == 5 &&
                                                                x.Assets == 6 &&
                                                                x.Liabilities == 7 &&
                                                                x.ShareholderFunds == 8 &&
                                                                x.Borrowings == 9 &&
                                                                x.AccountingReferenceDate == new DateTime(2021, 1, 1) &&
                                                                x.AccountingPeriod == 10 &&
                                                                x.AverageNumberofFTEEmployees == 11
                                                                ), It.IsAny <Guid>()), Times.Once);
        }
 public void AdditionalSetup()
 {
     ApplyRepository.Setup(r => r.CanSubmitApplication(It.Is <Guid>(id => id == differentAppGuid))).ReturnsAsync(false);
     ApplyRepository.Setup(r => r.CanSubmitApplication(It.Is <Guid>(id => id == sameAppGuid))).ReturnsAsync(true);
 }