Ejemplo n.º 1
0
        public static TaskScoreQuery Create(int taskId, string userId)
        {
            Fail.If(taskId <= 0);
            Fail.IfNullOrEmpty(userId);

            return(new TaskScoreQuery(taskId, userId));
        }
Ejemplo n.º 2
0
        public static CreateContestCommand Create(string name, ClaimsPrincipal user)
        {
            Fail.IfNullOrEmpty(name);
            Fail.IfNull(user);

            return(new CreateContestCommand(name, user));
        }
Ejemplo n.º 3
0
        public static CompilationQuery Create(string sourceCode, string input, ProgrammingLanguage language)
        {
            Fail.IfNullOrEmpty(sourceCode);
            Fail.IfNull(input);
            Fail.IfNull(language);

            return(new CompilationQuery(sourceCode, input, language));
        }
Ejemplo n.º 4
0
        public static CreateSolutionCommand Create(string sourceCode, string languageCode, int taskId, string username)
        {
            Fail.IfNullOrEmpty(sourceCode);
            Fail.IfNullOrEmpty(languageCode);
            Fail.IfNull(taskId);
            Fail.IfNull(username);

            return(new CreateSolutionCommand(sourceCode, languageCode, taskId, username));
        }
Ejemplo n.º 5
0
        public static int GetScore(decimal percentagePassed, ScorePolicy scorePolicy)
        {
            Fail.IfNull(scorePolicy);
            Fail.IfNullOrEmpty(scorePolicy.ScoreRules);

            var rules = scorePolicy.ScoreRules
                        .OrderBy(sr => sr.Threshold)
                        .ToList();

            var score = 0;

            foreach (var rule in rules)
            {
                if (percentagePassed < rule.Threshold)
                {
                    break;
                }
                score = rule.Score;
            }
            return(score);
        }
Ejemplo n.º 6
0
        public void IfNullOrEmpty_GivenSampleCollection_NoExceptionThrown()
        {
            Action act = () => Fail.IfNullOrEmpty(new int[] { 1, 2, 3, 4 });

            act.Should().NotThrow();
        }
Ejemplo n.º 7
0
        public void IfNullOrEmpty_GivenEmptyCollection_ThrowDesignByContractException()
        {
            Action act = () => Fail.IfNullOrEmpty(Array.Empty <int>());

            act.Should().Throw <DesignByContractException>();
        }
Ejemplo n.º 8
0
        public void IfNullOrEmpty_GivenNullCollection_ThrowDesignByContractException()
        {
            Action act = () => Fail.IfNullOrEmpty <int[]>(null);

            act.Should().Throw <DesignByContractException>();
        }
Ejemplo n.º 9
0
 public static CreateScorePolicyCommand Create(string name, string description, List <ScoreRuleDto> scoreRules)
 {
     Fail.IfNullOrEmpty(name);
     Fail.IfNullOrEmpty(scoreRules);
     return(new CreateScorePolicyCommand(name, description, scoreRules));
 }