public void CheckMethodWorksCorrectlyWithSomeCheckerCode()
        {
            var checker = new CSharpCodeChecker();
            checker.SetParameter(@"
                using OJS.Workers.Common;
                public class MyChecker : IChecker
                {
                    public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput, bool isTrialTest)
                    {
                        return new CheckerResult
                                    {
                                        IsCorrect = true,
                                        ResultType = CheckerResultType.Ok,
                                        CheckerDetails = ""It was me"",
                                    };
                    }
                    public void SetParameter(string parameter)
                    {
                    }
                }");

            var checkerResult = checker.Check(string.Empty, string.Empty, string.Empty, false);

            Assert.IsNotNull(checkerResult);
            Assert.IsTrue(checkerResult.IsCorrect);
            Assert.AreEqual("It was me", checkerResult.CheckerDetails);
        }
        public void CheckMethodReceivesCorrectParameters()
        {
            var checker = new CSharpCodeChecker();

            checker.SetParameter(@"
                using OJS.Workers.Common;
                public class MyChecker : IChecker
                {
                    public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput, bool isTrialTest)
                    {
                        bool isCorrect = true;

                        if (inputData != ""One"") isCorrect = false;
                        if (receivedOutput != ""Two"") isCorrect = false;
                        if (expectedOutput != ""Three"") isCorrect = false;

                        return new CheckerResult
                                    {
                                        IsCorrect = isCorrect,
                                        ResultType = CheckerResultType.Ok,
                                        CheckerDetails = """",
                                    };
                    }
                    public void SetParameter(string parameter)
                    {
                    }
                }");

            var checkerResult = checker.Check("One", "Two", "Three", false);

            Assert.IsNotNull(checkerResult);
            Assert.IsTrue(checkerResult.IsCorrect);
        }
        public void CheckMethodReceivesCorrectParameters()
        {
            var checker = new CSharpCodeChecker();
            checker.SetParameter(@"
                using OJS.Workers.Common;
                public class MyChecker : IChecker
                {
                    public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput, bool isTrialTest)
                    {
                        bool isCorrect = true;

                        if (inputData != ""One"") isCorrect = false;
                        if (receivedOutput != ""Two"") isCorrect = false;
                        if (expectedOutput != ""Three"") isCorrect = false;

                        return new CheckerResult
                                    {
                                        IsCorrect = isCorrect,
                                        ResultType = CheckerResultType.Ok,
                                        CheckerDetails = """",
                                    };
                    }
                    public void SetParameter(string parameter)
                    {
                    }
                }");

            var checkerResult = checker.Check("One", "Two", "Three", false);

            Assert.IsNotNull(checkerResult);
            Assert.IsTrue(checkerResult.IsCorrect);
        }
        public void CheckMethodWorksCorrectlyWithSomeCheckerCode()
        {
            var checker = new CSharpCodeChecker();

            checker.SetParameter(@"
                using OJS.Workers.Common;
                public class MyChecker : IChecker
                {
                    public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput, bool isTrialTest)
                    {
                        return new CheckerResult
                                    {
                                        IsCorrect = true,
                                        ResultType = CheckerResultType.Ok,
                                        CheckerDetails = ""It was me"",
                                    };
                    }
                    public void SetParameter(string parameter)
                    {
                    }
                }");

            var checkerResult = checker.Check(string.Empty, string.Empty, string.Empty, false);

            Assert.IsNotNull(checkerResult);
            Assert.IsTrue(checkerResult.IsCorrect);
            Assert.AreEqual("It was me", checkerResult.CheckerDetails);
        }
Пример #5
0
        public void SetParameterThrowsExceptionWhenGivenInvalidCode()
        {
            // Arrange
            var checker = new CSharpCodeChecker();

            // Act and Assert
            Assert.Throws <Exception>(() => checker.SetParameter(@"."));
        }
        public void ProcessSubmission_CalculatesScoreCorrectly()
        {
            const double expectedScore = 50;

            PostedSubmission submission = new PostedSubmission()
            {
                ProblemName = "add",
                Language    = "CSharp",
                Code        = @"int add(int param1, int param2) {
                return param1 + param2;
                }",
                TestCases   = new List <TestCase>()
                {
                    new TestCase()
                    {
                        ExpectedOutput = "3",
                        Parameters     = new List <Parameter>()
                        {
                            new Parameter()
                            {
                                Name  = "param1",
                                Value = "1"
                            },
                            new Parameter()
                            {
                                Name  = "param2",
                                Value = "2"
                            }
                        }
                    },
                    new TestCase()
                    {
                        ExpectedOutput = "4",
                        Parameters     = new List <Parameter>()
                        {
                            new Parameter()
                            {
                                Name  = "param1",
                                Value = "1"
                            },
                            new Parameter()
                            {
                                Name  = "param2",
                                Value = "2"
                            }
                        }
                    }
                }
            };

            CSharpCodeChecker checker = new CSharpCodeChecker(submission);

            var result = checker.Process();

            // Assert
            Assert.Equal(expectedScore, result.Score);
        }
Пример #7
0
        public void SetParameterThrowsExceptionWhenNotGivenICheckerImplementation()
        {
            // Arragne
            var    checker = new CSharpCodeChecker();
            string expectedErrorMessage = "Implementation of OJS.Workers.Common.IChecker not found!";

            // Act
            var exception = Assert.Throws <Exception>(() => checker.SetParameter(@"public class MyChecker { }"));

            // Assert
            Assert.AreEqual(expectedErrorMessage, exception.Message);
        }
Пример #8
0
        public void CallingCheckMethodBeforeSetParameterShouldThrowAnException()
        {
            // Arrange
            var    checker = new CSharpCodeChecker();
            string expectedErrorMessage = "Please call SetParameter first with non-null string.";

            // Act
            var exception = Assert.Throws <InvalidOperationException>(() => checker.Check(string.Empty, string.Empty, string.Empty, false));

            // Assert
            Assert.AreEqual(expectedErrorMessage, exception.Message);
        }
Пример #9
0
        public void SetParameterThrowsExceptionWhenGivenMoreThanOneICheckerImplementation()
        {
            // Arrange
            var checker      = new CSharpCodeChecker();
            var SetParameter = @"
                using OJS.Workers.Common;
                public class MyChecker1 : IChecker
                {
                    public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput, bool isTrialTest)
                    {
                        return new CheckerResult
                                    {
                                        IsCorrect = true,
                                        ResultType = CheckerResultType.Ok,
                                        CheckerDetails = new CheckerDetails(),
                                    };
                    }
                    public void SetParameter(string parameter)
                    {
                    }
                }
                public class MyChecker2 : IChecker
                {
                    public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput, bool isTrialTest)
                    {
                        return new CheckerResult
                                    {
                                        IsCorrect = true,
                                        ResultType = CheckerResultType.Ok,
                                        CheckerDetails = new CheckerDetails(),
                                    };
                    }
                    public void SetParameter(string parameter)
                    {
                    }
                }";

            string expectedErrorMessage = "More than one implementation of OJS.Workers.Common.IChecker was found!";

            // Act
            var exception = Assert.Throws <Exception>(() => checker.SetParameter(SetParameter), "Hola", null);

            // Assert
            Assert.AreEqual(expectedErrorMessage, exception.Message);
        }
        public void ProcessSubmission_WithCorrectInput_ReturnsResults()
        {
            const string expectedOutput = "3";
            const double expectedScore  = 100;

            PostedSubmission submission = new PostedSubmission()
            {
                ProblemName = "add",
                Language    = "CSharp",
                Code        = @"int add(int param1, int param2) {
                return param1 + param2;
                }",
                TestCases   = new List <TestCase>()
                {
                    new TestCase()
                    {
                        ExpectedOutput = "3",
                        Parameters     = new List <Parameter>()
                        {
                            new Parameter()
                            {
                                Name  = "param1",
                                Value = "1"
                            },
                            new Parameter()
                            {
                                Name  = "param2",
                                Value = "2"
                            }
                        }
                    }
                }
            };

            CSharpCodeChecker checker = new CSharpCodeChecker(submission);

            var result = checker.Process();

            // Assert
            Assert.Equal(expectedOutput, result.Tests.First().ActualOutput);
            Assert.Equal(expectedScore, result.Score);
        }
        public void ProcessSubmission_WithIncorrectCode_ThrowsException()
        {
            string expectedExceptionMessage =
                $"Program.cs on line 2: error CS0103: The name 'param3' does not exist in the current context";

            PostedSubmission submission = new PostedSubmission()
            {
                ProblemName = "add",
                Language    = "CSharp",
                Code        = @"int add(int param1, int param2) {
                return param3;
                }",
                TestCases   = new List <TestCase>()
                {
                    new TestCase()
                    {
                        ExpectedOutput = "3",
                        Parameters     = new List <Parameter>()
                        {
                            new Parameter()
                            {
                                Name  = "param1",
                                Value = "some string"
                            },
                            new Parameter()
                            {
                                Name  = "param2",
                                Value = "2"
                            }
                        }
                    }
                }
            };

            CSharpCodeChecker checker = new CSharpCodeChecker(submission);

            // Assert
            var exception = Assert.Throws <InvalidOperationException>(() => checker.Process());

            Assert.Equal(expectedExceptionMessage, exception.Message);
        }
        public void ProcessSubmission_WithIncorrectMainMethod_ThrowsException()
        {
            string expectedExceptionMessage =
                $"The main method should be equal to the problem's name: add.";

            PostedSubmission submission = new PostedSubmission()
            {
                ProblemName = "add",
                Language    = "CSharp",
                Code        = @"int add1(int param1, int param2) {
                return param1 + param2;
                }",
                TestCases   = new List <TestCase>()
                {
                    new TestCase()
                    {
                        ExpectedOutput = "3",
                        Parameters     = new List <Parameter>()
                        {
                            new Parameter()
                            {
                                Name  = "param1",
                                Value = "1"
                            },
                            new Parameter()
                            {
                                Name  = "param2",
                                Value = "2"
                            }
                        }
                    }
                }
            };

            CSharpCodeChecker checker = new CSharpCodeChecker(submission);

            // Assert
            var exception = Assert.Throws <ArgumentException>(() => checker.Process());

            Assert.Equal(expectedExceptionMessage, exception.Message);
        }
        public void ProcessSubmission_WithIncorrectValueParameter_ThrowsException()
        {
            string expectedExceptionMessage =
                $"Input string was not in a correct format.";

            PostedSubmission submission = new PostedSubmission()
            {
                ProblemName = "add",
                Language    = "CSharp",
                Code        = @"int add(int param1, int param2) {
                return param1 + param2;
                }",
                TestCases   = new List <TestCase>()
                {
                    new TestCase()
                    {
                        ExpectedOutput = "3",
                        Parameters     = new List <Parameter>()
                        {
                            new Parameter()
                            {
                                Name  = "param1",
                                Value = "some string"
                            },
                            new Parameter()
                            {
                                Name  = "param2",
                                Value = "2"
                            }
                        }
                    }
                }
            };

            CSharpCodeChecker checker = new CSharpCodeChecker(submission);

            var exception = Assert.Throws <InvalidOperationException>(() => checker.Process());

            Assert.Equal(expectedExceptionMessage, exception.Message);
        }
        public void SetParameterThrowsExceptionWhenGivenMoreThanOneICheckerImplementation()
        {
            var checker = new CSharpCodeChecker();

            checker.SetParameter(@"
                using OJS.Workers.Common;
                public class MyChecker1 : IChecker
                {
                    public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput)
                    {
                        return new CheckerResult
                                    {
                                        IsCorrect = true,
                                        ResultType = CheckerResultType.Ok,
                                        CheckerDetails = string.Empty,
                                    };
                    }
                    public void SetParameter(string parameter)
                    {
                    }
                }
                public class MyChecker2 : IChecker
                {
                    public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput)
                    {
                        return new CheckerResult
                                    {
                                        IsCorrect = true,
                                        ResultType = CheckerResultType.Ok,
                                        CheckerDetails = string.Empty,
                                    };
                    }
                    public void SetParameter(string parameter)
                    {
                    }
                }");
        }
 public void SetParameterThrowsExceptionWhenGivenMoreThanOneICheckerImplementation()
 {
     var checker = new CSharpCodeChecker();
     checker.SetParameter(@"
         using OJS.Workers.Common;
         public class MyChecker1 : IChecker
         {
             public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput)
             {
                 return new CheckerResult
                             {
                                 IsCorrect = true,
                                 ResultType = CheckerResultType.Ok,
                                 CheckerDetails = new CheckerDetails(),
                             };
             }
             public void SetParameter(string parameter)
             {
             }
         }
         public class MyChecker2 : IChecker
         {
             public CheckerResult Check(string inputData, string receivedOutput, string expectedOutput)
             {
                 return new CheckerResult
                             {
                                 IsCorrect = true,
                                 ResultType = CheckerResultType.Ok,
                                 CheckerDetails = new CheckerDetails(),
                             };
             }
             public void SetParameter(string parameter)
             {
             }
         }");
 }
 public void CallingCheckMethodBeforeSetParameterShouldThrowAnException()
 {
     var checker = new CSharpCodeChecker();
     checker.Check(string.Empty, string.Empty, string.Empty, false);
 }
        public void SetParameterThrowsExceptionWhenNotGivenICheckerImplementation()
        {
            var checker = new CSharpCodeChecker();

            checker.SetParameter(@"public class MyChecker { }");
        }
        public void SetParameterThrowsExceptionWhenGivenInvalidCode()
        {
            var checker = new CSharpCodeChecker();

            checker.SetParameter(@".");
        }
        public void CallingCheckMethodBeforeSetParameterShouldThrowAnException()
        {
            var checker = new CSharpCodeChecker();

            checker.Check(string.Empty, string.Empty, string.Empty, false);
        }
 public void SetParameterThrowsExceptionWhenGivenInvalidCode()
 {
     var checker = new CSharpCodeChecker();
     checker.SetParameter(@".");
 }
 public void SetParameterThrowsExceptionWhenNotGivenICheckerImplementation()
 {
     var checker = new CSharpCodeChecker();
     checker.SetParameter(@"public class MyChecker { }");
 }