public static void ValidateSubmissionType(int submissionTypeId, Contest contest)
 {
     if (contest.SubmissionTypes.All(submissionType => submissionType.Id != submissionTypeId))
     {
         throw new HttpException((int)HttpStatusCode.BadRequest, Resource.ContestsGeneral.Submission_type_not_found);
     }
 }
        public void PracticeResultsLinkShouldNavigateProperly()
        {
            var contest = new Contest { OldId = 1340, };
            this.EmptyOjsData.Contests.Add(contest);
            this.EmptyOjsData.SaveChanges();

            this.VerifyUrlRedirection("~/Contest/ContestResults/1340", string.Format("/Contests/Compete/Results/Simple/{0}", contest.Id));
        }
        public void ContestPracticeLinkShouldNavigateProperly()
        {
            var contest = new Contest { OldId = 1338, };
            this.EmptyOjsData.Contests.Add(contest);
            this.EmptyOjsData.SaveChanges();

            this.VerifyUrlRedirection("~/Contest/Practice/1338", string.Format("/Contests/Practice/Index/{0}", contest.Id));
        }
        public ContestRegistrationViewModel(Contest contest, bool isOfficial)
        {
            this.ContestName = contest.Name;
            this.ContestId = contest.Id;

            this.RequirePassword = isOfficial ? contest.HasContestPassword : contest.HasPracticePassword;

            this.Questions = contest.Questions.AsQueryable().Select(QuestionViewModel.FromQuestion);
        }
        public void ValidateContestWhenContestCanBePracticedShouldNotThrowAnException()
        {
            var contest = new Contest
            {
                IsVisible = true,
                PracticeStartTime = new DateTime(1990, 1, 1)
            };

            CompeteController.ValidateContest(contest, false);
        }
        public void DownloadTaskLinkShouldNavigateProperly()
        {
            var contest = new Contest { Name = "1337", };
            var problem = new Problem { Contest = contest, Name = "1337", OldId = 1337 };
            var resource = new ProblemResource { Problem = problem, Type = ProblemResourceType.ProblemDescription };
            this.EmptyOjsData.Resources.Add(resource);
            this.EmptyOjsData.SaveChanges();

            this.VerifyUrlRedirection("~/Contest/DownloadTask/1337", string.Format("/Contests/Practice/DownloadResource/{0}", resource.Id));
        }
        public void ValidateSubmissionTypeWhenSubmissionTypeIsFoundShouldNotThrowException()
        {
            var contest = new Contest
            {
                SubmissionTypes = new List<SubmissionType>
                {
                    new SubmissionType { Id = 1 },
                }
            };

            CompeteController.ValidateSubmissionType(1, contest);
        }
 public ContestRegistrationViewModel(Contest contest, ContestRegistrationModel userAnswers, bool isOfficial)
     : this(contest, isOfficial)
 {
     this.Questions = this.Questions.Select(x =>
     {
         var userAnswer = userAnswers.Questions.FirstOrDefault(y => y.QuestionId == x.QuestionId);
         return new QuestionViewModel
         {
             Answer = userAnswer == null ? null : userAnswer.Answer,
             QuestionId = x.QuestionId,
             Question = x.Question
         };
     });
 }
        public void ContestWithNoEndTimeAndLaterStartTimeShouldNotBeCompeted()
        {
            var contest = new Contest
            {
                Name = "Contest",
                IsVisible = true,
                IsDeleted = false,
                StartTime = DateTime.Now.AddDays(2),
                EndTime = null
            };

            var result = contest.CanBeCompeted;

            Assert.IsFalse(result);
        }
        public void ContestWithEarlyStartTimeAndLateEndTimeShouldBeCompeted()
        {
            var contest = new Contest
            {
                Name = "Contest",
                IsVisible = true,
                IsDeleted = false,
                StartTime = DateTime.Now.AddDays(-2),
                EndTime = DateTime.Now.AddDays(2)
            };

            var result = contest.CanBeCompeted;

            Assert.IsTrue(result);
        }
        public void ContestWithNoEndTimeAndEarlyStartTimeShouldNotBePracticed()
        {
            var contest = new Contest
            {
                Name = "Contest",
                IsVisible = true,
                IsDeleted = false,
                PracticeStartTime = DateTime.Now.AddDays(-2),
                PracticeEndTime = null
            };

            var result = contest.CanBePracticed;

            Assert.IsTrue(result);
        }
        public static void ValidateContest(Contest contest, bool official)
        {
            if (contest == null || contest.IsDeleted || !contest.IsVisible)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, Resource.ContestsGeneral.Contest_not_found);
            }

            if (official && !contest.CanBeCompeted)
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, Resource.ContestsGeneral.Contest_cannot_be_competed);
            }

            if (!official && !contest.CanBePracticed)
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, Resource.ContestsGeneral.Contest_cannot_be_practiced);
            }
        }
        public void DetailsActionWhenValidContestIdIsProvidedShouldReturnContest()
        {
            var contest = new Contest
            {
                Name = "test contest"
            };

            this.EmptyOjsData.Contests.Add(contest);
            this.EmptyOjsData.SaveChanges();

            var result = this.contestsController.Details(contest.Id) as ViewResult;
            var model = (ContestViewModel)result.Model;
            Assert.IsNotNull(model);
            Assert.AreEqual(contest.Id, model.Id);
            Assert.AreEqual(contest.Name, model.Name);
            Assert.AreEqual(contest.Description, model.Description);
        }
        public static void ValidateContest(Contest contest, bool official)
        {
            if (contest == null || contest.IsDeleted || !contest.IsVisible)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "Invalid contest id was provided!");
            }

            if (official && !contest.CanBeCompeted)
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, "This contest cannot be competed!");
            }

            if (!official && !contest.CanBePracticed)
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, "This contest cannot be practiced!");
            }
        }
        public void ValidateContestWhenContestCanBePracticedButTryingToCompeteItShouldThrowAnException()
        {
            var contest = new Contest
            {
                IsVisible = true,
                PracticeStartTime = new DateTime(1990, 1, 1)
            };

            try
            {
                CompeteController.ValidateContest(contest, true);
                Assert.Fail("Expected an exception when contest is null");
            }
            catch (HttpException ex)
            {
                Assert.AreEqual((int)HttpStatusCode.Forbidden, ex.GetHttpCode());
            }
        }
        public void ValidateSubmissionTypeWhenSubmissionTypeIsNotFoundThrowException()
        {
            var contest = new Contest
            {
                SubmissionTypes = new List<SubmissionType>
                {
                    new SubmissionType { Id = 1 },
                }
            };

            try
            {
                CompeteController.ValidateSubmissionType(0, contest);
                Assert.Fail("Expected an exception when submission type is null");
            }
            catch (HttpException ex)
            {
                Assert.AreEqual((int)HttpStatusCode.BadRequest, ex.GetHttpCode());
            }
        }
示例#17
0
        public void DetailsActionWhenContestIsNotVisibleShouldThrowException()
        {
            try
            {
                var contest = new Contest
                {
                    Name = "test contest",
                    IsVisible = false
                };

                this.EmptyOjsData.Contests.Add(contest);
                this.EmptyOjsData.SaveChanges();

                var result = this.contestsController.Details(contest.Id) as ViewResult;
            }
            catch (HttpException ex)
            {
                Assert.AreEqual((int)HttpStatusCode.NotFound, ex.GetHttpCode());
            }
        }
        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();
        }
        public void DeletedContestShouldNotBePracticed()
        {
            var contest = new Contest
            {
                Name = "Contest",
                IsVisible = true,
                IsDeleted = true,
                PracticeStartTime = DateTime.Now.AddHours(-2),
                PracticeEndTime = DateTime.Now.AddHours(2),
            };

            var result = contest.CanBePracticed;

            Assert.IsFalse(result);
        }
        private void CopyQuestionsToContest(Contest contest, IEnumerable<ContestQuestion> questions)
        {
            foreach (var question in questions)
            {
                var newQuestion = new DatabaseModelType
                {
                    Text = question.Text,
                    Type = question.Type,
                    AskOfficialParticipants = question.AskOfficialParticipants,
                    AskPracticeParticipants = question.AskPracticeParticipants,
                    RegularExpressionValidation = question.RegularExpressionValidation
                };

                foreach (var answer in question.Answers)
                {
                    newQuestion.Answers.Add(new DatabaseAnswerModelType { Text = answer.Text });
                }

                contest.Questions.Add(newQuestion);
            }

            this.Data.SaveChanges();
        }
        protected virtual Contest CreateAndSaveContest(string name, ContestInitializationOptions compete, ContestInitializationOptions practice)
        {
            var contestQuestions = new List<ContestQuestion>();

            if (compete.HasQuestions || practice.HasQuestions)
            {
                contestQuestions.Add(new ContestQuestion
                {
                    AskOfficialParticipants = compete.HasQuestions,
                    AskPracticeParticipants = practice.HasQuestions,
                    Text = "SampleQuestion"
                });
            }

            var contest = new Contest
            {
                Name = name,
                PracticeStartTime = practice.Enabled ? (DateTime?)new DateTime(2000, 1, 1) : null,
                PracticePassword = practice.HasPassword ? this.DefaultPracticePassword : null,
                StartTime = compete.Enabled ? (DateTime?)new DateTime(2000, 1, 1) : null,
                ContestPassword = compete.HasPassword ? this.DefaultCompetePassword : null,
                Questions = contestQuestions,
                IsVisible = true
            };

            this.EmptyOjsData.Contests.Add(contest);
            this.EmptyOjsData.SaveChanges();

            return contest;
        }
        public void ValidateContestWhenContestCannotBeCompetedShouldThrowException()
        {
            var contest = new Contest
            {
                IsVisible = true
            };

            try
            {
                CompeteController.ValidateContest(contest, true);
                Assert.Fail("Expected an exception when contest is null");
            }
            catch (HttpException ex)
            {
                Assert.AreEqual((int)HttpStatusCode.Forbidden, ex.GetHttpCode());
            }
        }
        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);
        }
        public void ValidateContestWhenContestIsInvisibleAndTryingToPracticeShouldThrowException()
        {
            var contest = new Contest
            {
                IsVisible = false
            };

            try
            {
                CompeteController.ValidateContest(contest, false);
                Assert.Fail("Expected an exception when contest is null");
            }
            catch (HttpException ex)
            {
                Assert.AreEqual((int)HttpStatusCode.NotFound, ex.GetHttpCode());
            }
        }
        public void NonVisibleContestShouldNotBeCompeted()
        {
            var contest = new Contest
            {
                Name = "Contest",
                IsVisible = false,
                IsDeleted = false,
                StartTime = DateTime.Now.AddHours(-2),
                EndTime = DateTime.Now.AddHours(2),
            };

            var result = contest.CanBeCompeted;

            Assert.IsFalse(result);
        }
        public void Copy(OjsDbContext context, TelerikContestSystemEntities oldDb)
        {
            var cSharpSubmissionType = context.SubmissionTypes.FirstOrDefault(x => x.Name == "C# code");
            var cPlusPlusSubmissionType = context.SubmissionTypes.FirstOrDefault(x => x.Name == "C++ code");
            var javaScriptSubmissionType = context.SubmissionTypes.FirstOrDefault(x => x.Name == "JavaScript code (NodeJS)");

            foreach (var oldContest in oldDb.Contests)
            {
                var contest = new Contest
                                  {
                                      OldId = oldContest.Id,
                                      CreatedOn = oldContest.AddedOn,
                                      PreserveCreatedOn = true,
                                      StartTime = oldContest.ActiveFrom,
                                      EndTime = oldContest.ActiveTo,
                                      ContestPassword = oldContest.Password,
                                      PracticePassword = oldContest.Password,
                                      OrderBy = oldContest.Order,
                                      Name = oldContest.Name.Trim(),
                                      IsVisible = oldContest.IsVisible,
                                      LimitBetweenSubmissions = oldContest.SubmissionsTimeLimit,
                                  };

                // Practice times
                if (!oldContest.ActiveFrom.HasValue && !oldContest.ActiveTo.HasValue)
                {
                    contest.PracticeStartTime = DateTime.Now;
                    contest.PracticeEndTime = null;
                }
                else if (oldContest.CanBePracticedAfterContest)
                {
                    contest.PracticeStartTime = oldContest.ActiveTo;
                    contest.PracticeEndTime = null;
                }
                else if (oldContest.CanBePracticedDuringContest)
                {
                    contest.PracticeStartTime = oldContest.ActiveFrom;
                    contest.PracticeEndTime = null;
                }
                else
                {
                    contest.PracticeStartTime = null;
                    contest.PracticeEndTime = null;
                }

                // Contest category
                var categoryName = oldContest.ContestType.Name;
                var category = context.ContestCategories.FirstOrDefault(x => x.Name == categoryName);
                contest.Category = category;

                // Contest question
                if (oldContest.Question != null)
                {
                    var question = new ContestQuestion
                                       {
                                           AskOfficialParticipants = true,
                                           AskPracticeParticipants = true,
                                           Text = oldContest.Question.Trim(),
                                           Type = ContestQuestionType.Default,
                                       };

                    if (oldContest.Answers != null)
                    {
                        var answers = oldContest.Answers.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var answerText in answers)
                        {
                            if (!string.IsNullOrWhiteSpace(answerText))
                            {
                                var answer = new ContestQuestionAnswer { Text = answerText.Trim() };
                                question.Answers.Add(answer);
                            }
                        }
                    }

                    contest.Questions.Add(question);
                }

                // Contest submission types
                if (oldContest.ContestType.AllowCSharpCode)
                {
                    contest.SubmissionTypes.Add(cSharpSubmissionType);
                }

                if (oldContest.ContestType.AllowCPlusPlusCode)
                {
                    contest.SubmissionTypes.Add(cPlusPlusSubmissionType);
                }

                if (oldContest.ContestType.AllowJavaScriptCode)
                {
                    contest.SubmissionTypes.Add(javaScriptSubmissionType);
                }

                context.Contests.Add(contest);
            }

            context.SaveChanges();
        }
        public void ContestWithNoStartTimeShouldNotBeCompeted()
        {
            var contest = new Contest
            {
                Name = "Contest",
                IsVisible = true,
                IsDeleted = false,
                StartTime = null
            };

            var result = contest.CanBeCompeted;

            Assert.IsFalse(result);
        }