Пример #1
0
        public async Task CreateSeedOnValidInput()
        {
            SetupDbMock();
            testerMock.Setup(m => m.TestCRUD(It.IsAny <string>(), It.Is <string>(s => s.Contains("seed")))).ReturnsAsync("OK");

            sut = new SeedController(dbMock.Object, testerMock.Object);
            await sut.Create(1);

            await sut.Create(new SeedCreateViewModel
            {
                DiagramId = SampleDiagram.DbDiagramId,
                SeedQuery = "seed"
            });

            dbMock.VerifyAll();
        }
Пример #2
0
        public async Task CreateDiagramSeedsAndExercise()
        {
            db.Mock.Setup(d => d.SaveAsync()).ReturnsAsync(1);
            {
                DiagramController diagramController = new DiagramController(db, tester);
                var diagrams = (await diagramController.Index()).Model as List <DbDiagram>;

                Assert.Empty(diagrams);

                const string q1 = "CREATE TABLE tab_1(id int PRIMARY KEY, name VARCHAR(30));";

                await diagramController.Create(new DbDiagram
                {
                    Name          = "Diagram1",
                    CreationQuery = q1,
                    Diagram       = new byte[] { 1, 2, 3 }
                }, null);

                diagrams = (await diagramController.Index()).Model as List <DbDiagram>;

                Assert.Single(diagrams, d => d.Name == "Diagram1" && d.CreationQuery == q1);
            }
            {
                SeedController seedController = new SeedController(db, tester);
                var            diagram        = db.Diagrams.Single();
                var            seeds          = (await seedController.Index()).Model as IEnumerable <IGrouping <int, Seed> >;

                Assert.Empty(seeds);

                var model1 = seedController.Create(diagram.DbDiagramId).Result.Model as SeedCreateViewModel;
                Assert.Equal(model1.DiagramId, diagram.DbDiagramId);

                const string seedQuery = "INSERT INTO tab_1 (id, name) VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc');";

                await seedController.Create(new SeedCreateViewModel
                {
                    DiagramId = diagram.DbDiagramId,
                    SeedQuery = seedQuery
                });

                Assert.Single(db.Seeds, s => s.Diagram == diagram && s.SeedQuery == seedQuery);
            }
            {
                ExerciseController exerciseController = new ExerciseController(db, exerciser, tester);
                var          diagram = db.Diagrams.Single();
                var          seed    = db.Seeds.Single();
                const string query   = "SELECT id FROM tab_1 WHERE name LIKE 'aaa';";

                var testQ = await exerciseController.TestQuery(query, diagram.DbDiagramId);

                await exerciseController.Create(new CreateExercise
                {
                    Diagram       = diagram.DbDiagramId,
                    Description   = "Exercising",
                    Title         = "Exercise_1",
                    SolutionQuery = query,
                    Difficulty    = 30
                });

                var exercise = db.Exercises.Single();
                var result   = await exerciseController.Solve(exercise.ExerciseId, "SELECT id FROM tab_1 WHERE name NOT LIKE 'bbb' AND name NOT LIKE 'ccc'");

                Assert.Single(db.Statuses, s => s.Accepted);

                result = await exerciseController.Solve(exercise.ExerciseId, "SELECT name FROM tab_1 WHERE name LIKE 'aaa'");

                Assert.All(db.Statuses, s => Assert.False(s.Resolution != null && s.Resolution.Contains("Error")));
                Assert.Single(db.Statuses, s => !s.Accepted);

                result = await exerciseController.Solve(exercise.ExerciseId, "SELECT sad");

                Assert.Single(db.Statuses, s => s.Resolution != null && s.Resolution.Contains("Error") && !s.Accepted);
            }
        }