예제 #1
0
        public void SampleVerification_ExpectedNewScorePolicyInDatabase()
        {
            var firstscoreRule  = new ScoreRuleDto(1, 1);
            var secondscoreRule = new ScoreRuleDto(2, 2);

            var givenScoreRulesDtos = new List <ScoreRuleDto>();

            givenScoreRulesDtos.Add(firstscoreRule);
            givenScoreRulesDtos.Add(secondscoreRule);

            ICommandHandler <CreateScorePolicyCommand> sut =
                new CreateScorePolicyCommandHandler(Context);

            string givenName        = "ScorePolicy1";
            string givenDescription = "description for ScorePolicy1";

            var command = CreateScorePolicyCommand.Create(givenName, givenDescription, givenScoreRulesDtos);

            sut.HandleAsync(command).Wait();
            var scorePolicy = Context.ScorePolicies.Single(p => p.Name == givenName);

            scorePolicy.Name.Should().Be(givenName);
            scorePolicy.Description.Should().Be(givenDescription);
            scorePolicy.ScoreRules.Should().HaveCount(2)
            .And.Contain(rule =>
                         rule.Threshold == firstscoreRule.Threshold && rule.Score == firstscoreRule.Score)
            .And.Contain(rule =>
                         rule.Threshold == secondscoreRule.Threshold && rule.Score == secondscoreRule.Score);
        }
예제 #2
0
        public async Task <IActionResult> OnPostCreateAsync()
        {
            var scoreRules = GetScoreRulesFromForm().ToList();

            if (scoreRules.IsNullOrEmpty())
            {
                RuleCountFail = true;
                return(Page());
            }

            var command = CreateScorePolicyCommand.Create(
                FormPolicy.Name,
                FormPolicy.Description,
                scoreRules);
            await _createScorePolicyCommandHandler.HandleAsync(command);

            return(RedirectToPage());
        }