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);
        }
        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");
        }
        public void SolutionIsAnalyzedCorrectly(TestSolution testSolution)
        {
            var analysisRun = TestSolutionAnalyzer.Run(testSolution);

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