Exemplo n.º 1
0
        public void AssignToGroup_InvalidAssignment_TestNotAssigned()
        {
            var groupViewModel = A.Fake<AssignToGoupViewModel>();
            var startDate = DateTime.Now;
            var endDate = DateTime.Now.AddDays(1);
            var assignmentViewModel = new AssignToGroupQuizViewModel
            {
                QuizId = 1,
                StartDateTime = startDate,
                EndDateTime = endDate,
                Group = groupViewModel
            };
            A.CallTo(() => groupViewModel.ToGroup()).Returns(new Group());
            A.CallTo(() => _quizManagementService.AssignQuizToGroupAsync(A<IAssignedQuizModel>.Ignored))
                .Throws(new InvalidAssignedTestException(new List<ValidationResult>
                {
                    new ValidationResult("Quiz is required", new[] {"Quiz"})
                }));

            var result = _controller.AssignToGroup(assignmentViewModel).Result as InvalidModelStateResult;

            Assert.NotNull(result);
        }
Exemplo n.º 2
0
        public async Task<IHttpActionResult> AssignToGroup(AssignToGroupQuizViewModel assignToGroupQuizViewModel)
        {
            var quiz = new Quiz {QuizId = assignToGroupQuizViewModel.QuizId};
            var group = assignToGroupQuizViewModel.Group.ToGroup();

            try
            {
                await
                    _quizManagementService.AssignQuizToGroupAsync(new AssignedQuiz
                    {
                        EndDate = assignToGroupQuizViewModel.EndDateTime,
                        StartDate = assignToGroupQuizViewModel.StartDateTime,
                        Quiz = quiz,
                        Group = (Group)group,
                        NumberOfQuestions = assignToGroupQuizViewModel.NumberOfQuestions
                    });
            }
            catch (InvalidAssignedTestException exception)
            {
                return BadRequestWithModelState(exception);
            }
            return Ok();
        }
Exemplo n.º 3
0
        public void AssignToGroup_ValidAssignment_TestAssignedToGroup()
        {
            var groupViewModel = A.Fake<AssignToGoupViewModel>();
            A.CallTo(() => groupViewModel.Year).Returns(2009);
            A.CallTo(() => groupViewModel.GroupNumber).Returns(2);
            var startDate = DateTime.Now;
            var endDate = DateTime.Now.AddDays(1);
            var assignmentViewModel = new AssignToGroupQuizViewModel
                                      {
                                          QuizId = 1,
                                          StartDateTime = startDate,
                                          EndDateTime = endDate,
                                          Group = groupViewModel
                                      };
            A.CallTo(() => groupViewModel.ToGroup()).Returns(new Group());

            var result = _controller.AssignToGroup(assignmentViewModel).Result as OkResult;

            Assert.NotNull(result);
            A.CallTo(() => _quizManagementService.AssignQuizToGroupAsync(A<IAssignedQuizModel>.Ignored)).MustHaveHappened();
        }