Пример #1
0
        public void DownloadResourceActionWhenPracticeAndUserNotLoggedInShouldRegirectToLoginPage()
        {
            var contest = this.CreateAndSaveContest("testContest", this.InactiveContestOptions, this.ActiveContestWithPasswordOptions);
            var problem = new Problem
            {
                Name = "test problem"
            };

            var resource = new ProblemResource
            {
                File          = new byte[1],
                FileExtension = "test"
            };

            problem.Resources.Add(resource);
            contest.Problems.Add(problem);
            this.EmptyOjsData.SaveChanges();

            var controller = new CompeteController(this.EmptyOjsData, null);
            var result     = controller.DownloadResource(resource.Id, this.IsPractice) as RedirectToRouteResult;

            Assert.AreEqual("Register", result.RouteValues["action"]);
            Assert.AreEqual(this.IsPractice, result.RouteValues["official"]);
            Assert.AreEqual(contest.Id, result.RouteValues["id"]);
        }
Пример #2
0
        public void ValidateContestWhenContestCanBeCompetedShouldNotThrowAnException()
        {
            var contest = new Contest
            {
                IsVisible = true,
                StartTime = new DateTime(1990, 1, 1)
            };

            CompeteController.ValidateContest(contest, true);
        }
Пример #3
0
 public void ValidateContestWhenContestIsNotFoundShouldAndTryingToCompeteThrowException()
 {
     try
     {
         CompeteController.ValidateContest(null, true);
         Assert.Fail("Expected an exception when contest is null");
     }
     catch (HttpException ex)
     {
         Assert.AreEqual((int)HttpStatusCode.NotFound, ex.GetHttpCode());
     }
 }
Пример #4
0
        public void ValidateSubmissionTypeWhenSubmissionTypeIsFoundShouldNotThrowException()
        {
            var contest = new Contest
            {
                SubmissionTypes = new List <SubmissionType>
                {
                    new SubmissionType {
                        Id = 1
                    },
                }
            };

            CompeteController.ValidateSubmissionType(1, contest);
        }
Пример #5
0
        public void ValidateContestWhenContestIsDeletedAndTryingToPracticeShouldThrowException()
        {
            var contest = new Contest
            {
                IsDeleted = true
            };

            try
            {
                CompeteController.ValidateContest(contest, false);
                Assert.Fail("Expected an exception when contest is null");
            }
            catch (HttpException ex)
            {
                Assert.AreEqual((int)HttpStatusCode.NotFound, ex.GetHttpCode());
            }
        }
Пример #6
0
        public void ValidateContestWhenContestIsInvisibleAndTryingToCompeteShouldThrowException()
        {
            var contest = new Contest
            {
                IsVisible = false
            };

            try
            {
                CompeteController.ValidateContest(contest, true);
                Assert.Fail("Expected an exception when trying to access a contest that is not visible");
            }
            catch (HttpException ex)
            {
                Assert.AreEqual((int)HttpStatusCode.NotFound, ex.GetHttpCode());
            }
        }
Пример #7
0
        public void ValidateContestWhenContestCannotBePracticedShouldThrowException()
        {
            var contest = new Contest
            {
                IsVisible = true
            };

            try
            {
                CompeteController.ValidateContest(contest, false);
                Assert.Fail("Expected an exception when contest is null");
            }
            catch (HttpException ex)
            {
                Assert.AreEqual((int)HttpStatusCode.Forbidden, ex.GetHttpCode());
            }
        }
Пример #8
0
        public void ValidateContestWhenContestCanBeCompetedButTryingToPracticeItShouldThrowAnException()
        {
            var contest = new Contest
            {
                IsVisible = true,
                StartTime = new DateTime(1990, 1, 1)
            };

            try
            {
                CompeteController.ValidateContest(contest, false);
                Assert.Fail("Expected an exception when contest is null");
            }
            catch (HttpException ex)
            {
                Assert.AreEqual((int)HttpStatusCode.Forbidden, ex.GetHttpCode());
            }
        }
Пример #9
0
        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());
            }
        }