Example #1
0
        private void CascadeDeleteCategories(ContestCategory contest)
        {
            foreach (var children in contest.Children.ToList())
            {
                this.CascadeDeleteCategories(children);
            }

            this.Data.ContestCategories.Delete(contest);
            this.Data.SaveChanges();
        }
Example #2
0
        public Task Save(ContestCategory contestCategory)
        {
            if (contestCategory.Id == 0)
            {
                _context.ContestCategories.Add(contestCategory);
            }
            else
            {
                _context.Entry(contestCategory).State = EntityState.Modified;
            }

            return(_context.SaveChangesAsync());
        }
        public void Copy(OjsDbContext context, TelerikContestSystemEntities oldDb)
        {
            foreach (var oldContestType in oldDb.ContestTypes)
            {
                var category = new ContestCategory
                {
                    Name      = oldContestType.Name,
                    IsVisible = oldContestType.IsVisible,
                    OrderBy   = oldContestType.Order,
                };
                context.ContestCategories.Add(category);
            }

            context.SaveChanges();
        }
Example #4
0
        private void SeedRandomContests(OjsDbContext context)
        {
            foreach (var contest in context.Contests)
            {
                context.Contests.Remove(contest);
            }

            var category = new ContestCategory
            {
                Name      = "Category",
                OrderBy   = 1,
                IsVisible = true,
                IsDeleted = false,
            };

            context.Contests.Add(
                new Contest
            {
                Name      = "DSA future",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(10),
                EndTime   = DateTime.Now.AddHours(19),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "DSA 2 out",
                IsVisible = false,
                StartTime = DateTime.Now.AddHours(10),
                EndTime   = DateTime.Now.AddHours(19),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "DSA 3 past",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(-10),
                EndTime   = DateTime.Now.AddHours(-8),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "DSA 2 active",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(-2),
                EndTime   = DateTime.Now.AddHours(2),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "JS Apps another active",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(-2),
                EndTime   = DateTime.Now.AddHours(2),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "JS Apps another active 2",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(-2),
                EndTime   = DateTime.Now.AddHours(2),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "JS Apps another active 3",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(-2),
                EndTime   = DateTime.Now.AddHours(2),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "JS Apps 2 past",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(-10),
                EndTime   = DateTime.Now.AddHours(-8),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "JS Apps 3 past",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(-10),
                EndTime   = DateTime.Now.AddHours(-8),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "JS Apps 3 past",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(10),
                EndTime   = DateTime.Now.AddHours(18),
                Category  = category,
            });
            context.Contests.Add(
                new Contest
            {
                Name      = "JS Apps 3 past",
                IsVisible = true,
                StartTime = DateTime.Now.AddHours(10),
                EndTime   = DateTime.Now.AddHours(18),
                Category  = category,
            });
        }
Example #5
0
        private void SeedCategoryContestProblem(IOjsDbContext context)
        {
            foreach (var categoryToBeDeleted in context.ContestCategories)
            {
                context.ContestCategories.Remove(categoryToBeDeleted);
            }

            foreach (var contestToBeDeleted in context.Contests)
            {
                context.Contests.Remove(contestToBeDeleted);
            }

            foreach (var problemToBeDeleted in context.Problems)
            {
                context.Problems.Remove(problemToBeDeleted);
            }

            var category = new ContestCategory
            {
                Name      = "Category",
                OrderBy   = 1,
                IsVisible = true,
                IsDeleted = false,
            };

            var otherCategory = new ContestCategory
            {
                Name      = "Other Category",
                OrderBy   = 1,
                IsVisible = true,
                IsDeleted = false,
            };

            var contest = new Contest
            {
                Name              = "Contest",
                OrderBy           = 1,
                PracticeStartTime = DateTime.Now.AddDays(-2),
                StartTime         = DateTime.Now.AddDays(-2),
                IsVisible         = true,
                IsDeleted         = false,
                Category          = category
            };

            var otherContest = new Contest
            {
                Name              = "Other Contest",
                OrderBy           = 2,
                PracticeStartTime = DateTime.Now.AddDays(-2),
                StartTime         = DateTime.Now.AddDays(-2),
                IsVisible         = true,
                IsDeleted         = false,
                Category          = category
            };

            var problemGroup1 = new ProblemGroup
            {
                OrderBy = 0,
                Contest = contest
            };

            var problemGroup2 = new ProblemGroup
            {
                OrderBy = 1,
                Contest = contest
            };

            var problem = new Problem
            {
                Name          = "Problem",
                MaximumPoints = 100,
                TimeLimit     = 10,
                MemoryLimit   = 10,
                OrderBy       = 1,
                ShowResults   = true,
                IsDeleted     = false,
                ProblemGroup  = problemGroup1
            };

            var otherProblem = new Problem
            {
                Name          = "Other Problem",
                MaximumPoints = 100,
                TimeLimit     = 10,
                MemoryLimit   = 10,
                OrderBy       = 1,
                ShowResults   = true,
                IsDeleted     = false,
                ProblemGroup  = problemGroup2
            };

            var test = new Test
            {
                InputDataAsString  = "Input",
                OutputDataAsString = "Output",
                OrderBy            = 0,
                IsTrialTest        = false,
                Problem            = problem,
            };

            var user = new UserProfile
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            var participant = new Participant
            {
                Contest    = contest,
                IsOfficial = false,
                User       = user
            };

            var submission = new Submission
            {
                Problem     = problem,
                Participant = participant,
                CreatedOn   = DateTime.Now
            };

            for (int i = 0; i < 10; i++)
            {
                test.TestRuns.Add(new TestRun
                {
                    MemoryUsed       = 100,
                    TimeUsed         = 100,
                    CheckerComment   = "Checked!",
                    ExecutionComment = "Executed!",
                    ResultType       = TestRunResultType.CorrectAnswer,
                    Submission       = submission
                });
            }

            context.Problems.Add(problem);
            context.Problems.Add(otherProblem);
            context.Contests.Add(otherContest);
            context.ContestCategories.Add(otherCategory);
            context.Tests.Add(test);
        }
Example #6
0
        public TestsControllerBaseTestsClass()
        {
            var firstCategory = new ContestCategory()
            {
                Id   = 1,
                Name = "Category"
            };

            var secondCategory = new ContestCategory()
            {
                Id   = 2,
                Name = "Another category"
            };

            var thirdCategory = new ContestCategory()
            {
                Id   = 3,
                Name = "And another category"
            };

            var contest = new Contest
            {
                Id         = 1,
                Name       = "Contest",
                CategoryId = 1,
                Category   = firstCategory
            };

            var otherContest = new Contest
            {
                Id         = 2,
                Name       = "Other contest",
                CategoryId = 1,
                Category   = firstCategory
            };

            firstCategory.Contests.Add(contest);
            firstCategory.Contests.Add(otherContest);

            var selectedProblem = new Problem
            {
                Id        = 1,
                Name      = "Problem",
                Contest   = contest,
                ContestId = 1,
            };

            var otherProblem = new Problem
            {
                Id        = 2,
                Name      = "Other problem",
                Contest   = contest,
                ContestId = 1,
            };

            var problemWithOnlyTrialTests = new Problem
            {
                Id        = 3,
                Name      = "OnlyTrialTests",
                Contest   = contest,
                ContestId = 1,
            };

            var problemWithOnlyNormalTests = new Problem
            {
                Id        = 4,
                Name      = "OnlyNormalTests",
                Contest   = contest,
                ContestId = 1,
            };

            var testRun = new TestRun()
            {
                Id               = 1,
                TestId           = 1,
                ResultType       = TestRunResultType.CorrectAnswer,
                MemoryUsed       = 100,
                TimeUsed         = 100,
                SubmissionId     = 1,
                ExecutionComment = "Comment execution",
                CheckerComment   = "Comment checker",
                Submission       = new Submission
                {
                    Id        = 1,
                    CreatedOn = DateTime.Now,
                },
            };

            var test = new Test
            {
                Id = 1,
                InputDataAsString  = "Sample test input",
                OutputDataAsString = "Sample test output",
                IsTrialTest        = false,
                TestRuns           = new HashSet <TestRun>()
                {
                    testRun,
                },
                Problem   = selectedProblem,
                ProblemId = 1,
                OrderBy   = 5,
            };

            testRun.Test = test;

            selectedProblem.Tests.Add(test);

            selectedProblem.Tests.Add(new Test
            {
                InputDataAsString  = "Trial input test 1",
                OutputDataAsString = "Trial output test 1",
                IsTrialTest        = true,
                Problem            = selectedProblem,
                ProblemId          = 1,
            });

            selectedProblem.Tests.Add(new Test
            {
                InputDataAsString  = "Trial input test 2",
                OutputDataAsString = "Trial output test 2",
                IsTrialTest        = true,
                Problem            = selectedProblem,
                ProblemId          = 1,
            });

            problemWithOnlyTrialTests.Tests.Add(new Test
            {
                InputDataAsString  = "Zero test 1\nZero test 1 second line",
                OutputDataAsString = "Zero test 1\nZero test 1 second lint output",
                IsTrialTest        = true,
                Problem            = selectedProblem,
                ProblemId          = 1,
            });

            for (int i = 0; i < 10; i++)
            {
                selectedProblem.Tests.Add(new Test
                {
                    InputDataAsString  = i.ToString(),
                    OutputDataAsString = (i + 1).ToString(),
                    IsTrialTest        = false,
                    Problem            = selectedProblem,
                    ProblemId          = 1,
                });
            }

            otherProblem.Tests.Add(new Test
            {
                InputDataAsString  = "Trial input test 1 other",
                OutputDataAsString = "Trial output test 1 other",
                IsTrialTest        = true,
                Problem            = selectedProblem,
                ProblemId          = 1,
            });

            otherProblem.Tests.Add(new Test
            {
                InputDataAsString  = "Trial input test 2 other",
                OutputDataAsString = "Trial output test 2 other",
                IsTrialTest        = true,
                Problem            = selectedProblem,
                ProblemId          = 1,
            });

            for (int i = 0; i < 10; i++)
            {
                otherProblem.Tests.Add(new Test
                {
                    InputDataAsString  = i.ToString() + "other",
                    OutputDataAsString = (i + 1).ToString() + "other",
                    IsTrialTest        = false,
                    Problem            = selectedProblem,
                    ProblemId          = 1,
                });
            }

            for (int i = 0; i < 10; i++)
            {
                problemWithOnlyNormalTests.Tests.Add(new Test
                {
                    InputDataAsString  = "Only normal tests " + i.ToString(),
                    OutputDataAsString = "Only normal tests output" + i.ToString(),
                    IsTrialTest        = false,
                    Problem            = selectedProblem,
                    ProblemId          = 1,
                });
            }

            contest.Problems.Add(selectedProblem);
            contest.Problems.Add(otherProblem);
            contest.Problems.Add(problemWithOnlyTrialTests);
            contest.Problems.Add(problemWithOnlyNormalTests);

            this.TestViewModel = new TestViewModel
            {
                Id          = 1,
                InputFull   = "Input test",
                OutputFull  = "Output test",
                IsTrialTest = false,
                OrderBy     = 1,
                ProblemId   = 1,
            };

            //// TODO: get these mocks in base class for reuse

            var listsOfTests = new List <Test>(selectedProblem.Tests);

            this.data        = new Mock <IOjsData>();
            this.Problems    = new Mock <IDeletableEntityRepository <Problem> >();
            this.Tests       = new Mock <ITestRepository>();
            this.TestsRuns   = new Mock <ITestRunsRepository>();
            this.Categories  = new Mock <IDeletableEntityRepository <ContestCategory> >();
            this.Contests    = new Mock <IContestsRepository>();
            this.Submissions = new Mock <ISubmissionsRepository>();

            this.Problems.Setup(x => x.All()).Returns((new List <Problem>()
            {
                selectedProblem, otherProblem, problemWithOnlyTrialTests, problemWithOnlyNormalTests
            }).AsQueryable());

            this.Tests.Setup(x => x.All()).Returns(listsOfTests.AsQueryable());
            this.Tests.Setup(x => x.Add(It.IsAny <Test>())).Callback((Test t) => { listsOfTests.Add(t); });
            this.Tests.Setup(x => x.Delete(It.IsAny <int>())).Callback((int id) =>
            {
                foreach (var currentTest in listsOfTests)
                {
                    if (currentTest.Id == id)
                    {
                        listsOfTests.Remove(currentTest);
                        break;
                    }
                }
            });

            this.TestsRuns.Setup(x => x.All()).Returns(new List <TestRun>()
            {
                testRun
            }.AsQueryable());
            this.Categories.Setup(x => x.All()).Returns(new List <ContestCategory>()
            {
                firstCategory, secondCategory, thirdCategory
            }.AsQueryable());
            this.Contests.Setup(x => x.All()).Returns(new List <Contest>()
            {
                contest, otherContest
            }.AsQueryable());

            this.data.SetupGet(x => x.Problems).Returns(this.Problems.Object);
            this.data.SetupGet(x => x.Tests).Returns(this.Tests.Object);
            this.data.SetupGet(x => x.TestRuns).Returns(this.TestsRuns.Object);
            this.data.SetupGet(x => x.ContestCategories).Returns(this.Categories.Object);
            this.data.SetupGet(x => x.Contests).Returns(this.Contests.Object);
            this.data.SetupGet(x => x.Submissions).Returns(this.Submissions.Object);

            this.TestsController = new TestsController(this.data.Object);

            this.ControllerContext = new ControllerContext(this.MockHttpContestBase(), new RouteData(), this.TestsController);
        }
Example #7
0
        public TestContestRepositoryAllVisibleInCategory()
        {
            ContestCategory firstCategory  = new ContestCategory();
            ContestCategory secondCategory = new ContestCategory();
            ContestCategory thirdCategory  = new ContestCategory();

            ContestCategory firstInnerCategory  = new ContestCategory();
            ContestCategory secondInnerCategory = new ContestCategory();
            ContestCategory thirdInnerCategory  = new ContestCategory();
            ContestCategory fourthInnerCategory = new ContestCategory();
            ContestCategory fifthInnerCategory  = new ContestCategory();
            ContestCategory sixthInnerCategory  = new ContestCategory();

            firstCategory.Children.Add(firstInnerCategory);
            firstCategory.Children.Add(secondInnerCategory);
            secondCategory.Children.Add(thirdInnerCategory);
            secondCategory.Children.Add(fourthInnerCategory);
            thirdCategory.Children.Add(fifthInnerCategory);
            thirdCategory.Children.Add(sixthInnerCategory);

            EmptyOjsData.ContestCategories.Add(firstCategory);
            EmptyOjsData.ContestCategories.Add(secondCategory);
            EmptyOjsData.ContestCategories.Add(thirdCategory);

            for (int i = 0; i < 5; i++)
            {
                Contest visibleActiveContest = new Contest
                {
                    Name      = "Visible",
                    IsVisible = true,
                    IsDeleted = false,
                    StartTime = DateTime.Now.AddDays(-2),
                    EndTime   = DateTime.Now.AddDays(2)
                };

                Contest visiblePastContest = new Contest
                {
                    Name      = "Visible",
                    IsVisible = true,
                    IsDeleted = false,
                    StartTime = DateTime.Now.AddDays(-2),
                    EndTime   = DateTime.Now.AddDays(-1)
                };

                Contest visibleFutureContest = new Contest
                {
                    Name      = "Visible",
                    IsVisible = true,
                    IsDeleted = false,
                    StartTime = DateTime.Now.AddDays(2),
                    EndTime   = DateTime.Now.AddDays(4)
                };

                Contest nonVisibleContest = new Contest
                {
                    Name      = "NonVisible",
                    IsVisible = false,
                    IsDeleted = false,
                    StartTime = DateTime.Now.AddDays(-2),
                    EndTime   = DateTime.Now.AddDays(4)
                };

                Contest deletedVisibleContest = new Contest
                {
                    Name      = "DeletedVisible",
                    IsVisible = true,
                    IsDeleted = true,
                    StartTime = DateTime.Now.AddDays(-2),
                    EndTime   = DateTime.Now.AddDays(4)
                };

                firstCategory.Contests.Add((Contest)visibleActiveContest.ObjectClone());
                firstCategory.Contests.Add((Contest)visiblePastContest.ObjectClone());
                firstCategory.Contests.Add((Contest)visibleFutureContest.ObjectClone());
                firstCategory.Contests.Add((Contest)nonVisibleContest.ObjectClone());
                firstCategory.Contests.Add((Contest)deletedVisibleContest.ObjectClone());
                secondCategory.Contests.Add((Contest)visibleActiveContest.ObjectClone());
                secondCategory.Contests.Add((Contest)visiblePastContest.ObjectClone());
                secondCategory.Contests.Add((Contest)visibleFutureContest.ObjectClone());
                secondCategory.Contests.Add((Contest)nonVisibleContest.ObjectClone());
                secondCategory.Contests.Add((Contest)deletedVisibleContest.ObjectClone());
                thirdCategory.Contests.Add((Contest)visibleActiveContest.ObjectClone());
                thirdCategory.Contests.Add((Contest)visiblePastContest.ObjectClone());
                thirdCategory.Contests.Add((Contest)visibleFutureContest.ObjectClone());
                thirdCategory.Contests.Add((Contest)nonVisibleContest.ObjectClone());
                thirdCategory.Contests.Add((Contest)deletedVisibleContest.ObjectClone());
                firstInnerCategory.Contests.Add((Contest)visibleActiveContest.ObjectClone());
                firstInnerCategory.Contests.Add((Contest)visiblePastContest.ObjectClone());
                firstInnerCategory.Contests.Add((Contest)visibleFutureContest.ObjectClone());
                firstInnerCategory.Contests.Add((Contest)nonVisibleContest.ObjectClone());
                firstInnerCategory.Contests.Add((Contest)deletedVisibleContest.ObjectClone());
                secondInnerCategory.Contests.Add((Contest)visibleActiveContest.ObjectClone());
                secondInnerCategory.Contests.Add((Contest)visiblePastContest.ObjectClone());
                secondInnerCategory.Contests.Add((Contest)visibleFutureContest.ObjectClone());
                secondInnerCategory.Contests.Add((Contest)nonVisibleContest.ObjectClone());
                secondInnerCategory.Contests.Add((Contest)deletedVisibleContest.ObjectClone());
                thirdInnerCategory.Contests.Add((Contest)visibleActiveContest.ObjectClone());
                thirdInnerCategory.Contests.Add((Contest)visiblePastContest.ObjectClone());
                thirdInnerCategory.Contests.Add((Contest)visibleFutureContest.ObjectClone());
                thirdInnerCategory.Contests.Add((Contest)nonVisibleContest.ObjectClone());
                thirdInnerCategory.Contests.Add((Contest)deletedVisibleContest.ObjectClone());
                fourthInnerCategory.Contests.Add((Contest)visibleActiveContest.ObjectClone());
                fourthInnerCategory.Contests.Add((Contest)visiblePastContest.ObjectClone());
                fourthInnerCategory.Contests.Add((Contest)visibleFutureContest.ObjectClone());
                fourthInnerCategory.Contests.Add((Contest)nonVisibleContest.ObjectClone());
                fourthInnerCategory.Contests.Add((Contest)deletedVisibleContest.ObjectClone());
                fifthInnerCategory.Contests.Add((Contest)visibleActiveContest.ObjectClone());
                fifthInnerCategory.Contests.Add((Contest)visiblePastContest.ObjectClone());
                fifthInnerCategory.Contests.Add((Contest)visibleFutureContest.ObjectClone());
                fifthInnerCategory.Contests.Add((Contest)nonVisibleContest.ObjectClone());
                fifthInnerCategory.Contests.Add((Contest)deletedVisibleContest.ObjectClone());
                sixthInnerCategory.Contests.Add((Contest)visibleActiveContest.ObjectClone());
                sixthInnerCategory.Contests.Add((Contest)visiblePastContest.ObjectClone());
                sixthInnerCategory.Contests.Add((Contest)visibleFutureContest.ObjectClone());
                sixthInnerCategory.Contests.Add((Contest)nonVisibleContest.ObjectClone());
                sixthInnerCategory.Contests.Add((Contest)deletedVisibleContest.ObjectClone());
            }

            EmptyOjsData.SaveChanges();
        }