コード例 #1
0
        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();
        }
        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();
        }
コード例 #3
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);
        }
コード例 #4
0
 public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ModelType model)
 {
     return(this.BaseDestroy(request, model));
 }
コード例 #5
0
 public ActionResult Update([DataSourceRequest] DataSourceRequest request, ModelType model)
 {
     return(this.BaseUpdate(request, model));
 }
コード例 #6
0
        private void CascadeDeleteCategories(ContestCategory contest)
        {
            foreach (var children in contest.Children.ToList())
            {
                this.CascadeDeleteCategories(children);
            }

            this.Data.ContestCategories.Delete(contest);
            this.Data.SaveChanges();
        }