예제 #1
0
        public async Task SuccessOnValidQueryDML()
        {
            var exercise = new Exercise
            {
                Judge = new Judge
                {
                    AnswerQuery = "INSERT INTO employees (id, name) VALUES (50, 'joj');",
                    VerifyQuery = "SELECT * FROM employees WHERE name LIKE 'joj'",
                    Diagram     = new DbDiagram {
                        DbDiagramId = 1
                    }
                }
            };

            sut = new Exerciser(new QueryExecutor());

            var result = await sut.ExecuteExercise(exercise, exercise.Judge.AnswerQuery, new List <string>
            {
                "CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(max));"
            });

            if (!result.Key)
            {
                Assert.Equal("Nothin", result.Value);
            }
            Assert.True(result.Key);
        }
예제 #2
0
        public async Task SuccessOnValidQuerySelectExercise()
        {
            var exercise = db.EmployeesExercises.First();

            sut = new Exerciser(new QueryExecutor());

            var result = await sut.ExecuteExercise(exercise, exercise.Judge.AnswerQuery, db.EmployeesSetup);

            Assert.True(result.Key);
        }
예제 #3
0
        public async Task FailureOnWrongAnswer()
        {
            var exercise = db.EmployeesExercises.First();

            sut = new Exerciser(new QueryExecutor());

            var result = await sut.ExecuteExercise(exercise, "SELECT * FROM employees WHERE name LIKE 'adda_Dsa_d_Sa_'", db.EmployeesSetup);

            Assert.False(result.Key);
            Assert.DoesNotContain("Error", result.Value, StringComparison.OrdinalIgnoreCase);
        }
예제 #4
0
        public async Task ReturnFailureOnBadSql()
        {
            var exercise = db.EmployeesExercises.First();

            sut = new Exerciser(new QueryExecutor());

            var result = await sut.ExecuteExercise(exercise, "BadQuery", new List <string> {
                "CREATE TABLE tab_1 (id INT PRIMARY KEY);"
            });

            Assert.False(result.Key);
            Assert.StartsWith("Error", result.Value, StringComparison.OrdinalIgnoreCase);
        }
예제 #5
0
        public async Task FailureOnWrongAnswerDML()
        {
            var exercise = new Exercise
            {
                Judge = new Judge
                {
                    AnswerQuery = "INSERT INTO employees (id, name, date, departmentId) VALUES (21, 'joj', GETDATE(), 1);",
                    VerifyQuery = "SELECT * FROM employees WHERE name LIKE 'joj'",
                    Diagram     = new DbDiagram {
                        DbDiagramId = 1
                    }
                }
            };

            sut = new Exerciser(new QueryExecutor());

            var result = await sut.ExecuteExercise(exercise, "INSERT INTO employees (id, name) VALUES (28, 'kokojumbo');", db.EmployeesSetup);

            Assert.False(result.Key);
            Assert.DoesNotContain("Error", result.Value, StringComparison.OrdinalIgnoreCase);
        }