コード例 #1
0
        public void SolutionShouldBeCorrectlyAnalyzed(TestSolution testSolution)
        {
            var analysisRun = TestSolutionAnalyzer.Run(testSolution);

            Assert.Equal(analysisRun.Expected.Status, analysisRun.Actual.Status);
            Assert.Equal(analysisRun.Expected.Comments, analysisRun.Actual.Comments);
        }
コード例 #2
0
        public void ReferToMentorWhenNoAnalyzerHasBeenImplementedForExercise()
        {
            var analysisRun = TestSolutionAnalyzer.Run("missing", "Missing", string.Empty);

            Assert.True(analysisRun.ReferToMentor);
            Assert.Empty(analysisRun.Comments);
        }
コード例 #3
0
        public void DisapproveWithCommentWhenCodeHasSyntaxErrors()
        {
            const string code = @"
                public static class Gigasecond
                {
                    public static DateTime Add
                }";

            var analysisRun = TestSolutionAnalyzer.Run("errors", "Errors", code);

            Assert.True(analysisRun.DisapproveWithComment);
            Assert.Single(analysisRun.Comments, "Has errors");
        }
コード例 #4
0
        public void DisapproveWithCommentWhenUsingPlusOperator()
        {
            const string code = @"
                using System;
                
                public static class Gigasecond
                {
                    public static DateTime Add(DateTime birthDate) => birthDate + TimeSpan.FromSeconds(1000000000);
                }";

            var analysisRun = TestSolutionAnalyzer.Run(Slug, Name, code);

            Assert.True(analysisRun.DisapproveWithComment);
            Assert.Single(analysisRun.Comments, "Use AddSeconds");
        }
コード例 #5
0
        public void ApproveWithCommentWhenUsingAddSecondsWithDigitsWithoutSeparator()
        {
            const string code = @"
                using System;
                
                public static class Gigasecond
                {
                    public static DateTime Add(DateTime birthDate) => birthDate.AddSeconds(1000000);
                }";

            var analysisRun = TestSolutionAnalyzer.Run(Slug, Name, code);

            Assert.True(analysisRun.ApproveWithComment);
            Assert.Single(analysisRun.Comments, "Use 1e9 or 1_000_000 instead of 1000000");
        }
コード例 #6
0
        public void ApproveWithCommentWhenUsingAddSecondsWithMathPow()
        {
            const string code = @"
                using System;
                
                public static class Gigasecond
                {
                    public static DateTime Add(DateTime birthDate) => birthDate.AddSeconds(Math.Pow(10, 9));
                }";

            var analysisRun = TestSolutionAnalyzer.Run(Slug, Name, code);

            Assert.True(analysisRun.ApproveWithComment);
            Assert.Single(analysisRun.Comments, "Use 1e9 instead of Math.Pow(10, 9)");
        }
コード例 #7
0
        public void ApproveAsOptimalWhenUsingAddSecondsWithScientificNotation()
        {
            const string code = @"
                using System;
                
                public static class Gigasecond
                {
                    public static DateTime Add(DateTime birthDate) => birthDate.AddSeconds(1e9);
                }";

            var analysisRun = TestSolutionAnalyzer.Run(Slug, Name, code);

            Assert.True(analysisRun.ApproveAsOptimal);
            Assert.Empty(analysisRun.Comments);
        }
コード例 #8
0
        public void ApproveWithCommentWhenUsingAddSecondsWithScientificNotationInBlockBody()
        {
            const string code = @"
                using System;
                
                public static class Gigasecond
                {
                    public static DateTime Add(DateTime birthDate)
                    {
                        return birthDate.AddSeconds(1e9);
                    }
                }";

            var analysisRun = TestSolutionAnalyzer.Run(Slug, Name, code);

            Assert.True(analysisRun.ApproveWithComment);
            Assert.Single(analysisRun.Comments, "You could write the method an an expression-bodied member");
        }
コード例 #9
0
        public void SolutionIsAnalyzedCorrectly(TestSolution testSolution)
        {
            var analysisRun = TestSolutionAnalyzer.Run(testSolution);

            Assert.Equal(analysisRun.Expected.Analysis.NormalizeJson(), analysisRun.Actual.Analysis.NormalizeJson());
        }