Beispiel #1
0
 public Score(ScoreId id, ProctorId proctorId, Grade grade, QuestionId questionId, AnswerId answerId) : base(id)
 {
     ProctorId  = proctorId;
     Grade      = grade;
     QuestionId = questionId;
     AnswerId   = answerId;
 }
        private void TrySaveAnswer(OutputDto output, QuestionId id, uint retries = 25)
        {
            try
            {
                var questionnaire = Context.QuestionnaireGateway.Get(id.QuestionaireId);

                if (questionnaire.LockQuestion && Request.IsAnonymousUser && questionnaire.GetSlide(id.Id).IsCompleted)
                {
                    throw new SlideLockedException("Slide has been locked by calling Slide/Complete while LockQuestion is specified on the experiment",
                                                   "The requested slide is not available for editing");
                }

                var question = questionnaire.GetQuestion(id.Id);
                question.Output = OutputMapper.Map(output);

                Context.QuestionGateway.Save(question);
            }
            catch (InvalidRevisionException e)
            {
                if (retries > 0)
                {
                    TrySaveAnswer(output, id, retries - 1);
                }
                else
                {
                    throw new ServerException("Failed to save answer", "Your answer wasn't saved, try again.", e);
                }
            }
        }
Beispiel #3
0
 public ReceiveScoreCommand(Guid examId, Guid proctorId, double gradePercent,
                            QuestionId questionId) : base(ExamId.With(examId))
 {
     ProctorId    = ProctorId.With(proctorId);
     GradePercent = gradePercent;
     QuestionId   = questionId;
 }
Beispiel #4
0
        public async Task <Question> GetQuestionAsync(QuestionId id)
        {
            IQueryable <Question> questionsQueryable         = this._context.Questions;
            IQueryable <Question> questionsFilteredQueryable = questionsQueryable.Where(r => r.Id == id);
            Question questionsSingleOrDefaultQueryable       = await questionsFilteredQueryable.SingleOrDefaultAsync();

            return(questionsSingleOrDefaultQueryable);
        }
        public EndpointResult Set(string questionId, OutputDto output)
        {
            var id = new QuestionId(questionId);

            TrySaveAnswer(output, id);

            return(EndpointResult.Success());
        }
Beispiel #6
0
        public void TestQuestionIdQuestionCatalogAndLineNumberConstructor()
        {
            var questionId = new QuestionId(new QuestionCatalogName("question-catalog"), 10);

            Assert.That(questionId.Value, Is.EqualTo("question-catalog:10"));
            Assert.AreEqual(new QuestionCatalogName(questionId.Value.Split(':')[0]), questionId.QuestionCatalogName);
            Assert.AreEqual(int.Parse(questionId.Value.Split(':')[1]), questionId.LineNumber);
        }
 public Answer(AnswerId id, string body, long question, long responder) : base(id)
 {
     Body             = body;
     Question         = new QuestionId(question);
     Responder        = new UserId(responder);
     IsChosen         = false;
     CreationDateTime = DateTime.Now;
 }
        public void Handle(ContainsTrueAnswer command)
        {
            var questionId = new QuestionId(command.QuestionId);
            var question   = _questionRepository.Get(questionId);

            question.ContainsTrueAnswser();
            _questionRepository.Update(question);
        }
Beispiel #9
0
        public async Task <string> ReceiveScore(Guid examId, Guid proctorId,
                                                double gradePercent, QuestionId questionId, CancellationToken cancellationToken)
        {
            var command = new ReceiveScoreCommand(examId, proctorId, gradePercent, questionId);
            var result  = await _commandBus.PublishAsync(command, cancellationToken);

            return(result.ScoreId);
        }
        public QuestionDetailsDto Handle(long id)
        {
            var questionId = new QuestionId(id);
            var question   = _session.CreateCriteria <Question>().Add(Restrictions.Eq("Id", questionId))
                             .UniqueResult <Question>();
            var tags = _session.Query <Tag>().ToList();

            return(_questionMapper.MapQuestion(question, tags));
        }
        public List <AnswerDto> Handle(long id)
        {
            var questionId = new QuestionId(id);
            var answers    = _session.CreateCriteria <Answer>().Add(Restrictions.Eq("Question", questionId))
                             .List <Answer>();
            var answerMapper = new AnswerMapper(_userService);

            return(answerMapper.MapAnswers(answers));
        }
Beispiel #12
0
        public override int GetHashCode()
        {
            int idHash      = Id.ToString().GetHashCode();
            int qIdHash     = QuestionId.ToString().GetHashCode();
            int nameId      = Name.GetHashCode();
            int isRightHash = IsRight.ToString().GetHashCode();

            return(idHash + qIdHash + nameId + isRightHash);
        }
Beispiel #13
0
        public override byte[] GetData()
        {
            var data = new byte[16 + 16 + 16];

            Buffer.BlockCopy(QuestionId.ToOrderByteArray(), 0, data, 0, 16);
            Buffer.BlockCopy(ChoiceId.ToOrderByteArray(), 0, data, 16, 16);
            Buffer.BlockCopy(Id.ToOrderByteArray(), 0, data, 32, 16);

            return(data);
        }
        public void Handle(CreateQuestion command)
        {
            var id         = _questionRepository.GetNextId(QuestionSequenceName);
            var questionId = new QuestionId(id);
            var inquirerId = _claimHelper.GetUserId();
            var inquirer   = new UserId(inquirerId);
            var question   = new Question(questionId, command.Title, command.Body, command.Tags, inquirer);

            _questionRepository.Create(question);
        }
Beispiel #15
0
        public void Handle(ChosenAnswer command)
        {
            var answerId        = new AnswerId(command.AnswerId);
            var answer          = _answerRepository.Get(answerId);
            var questionId      = new QuestionId(command.QuestionId);
            var questionAnswers = _answerRepository.GetByQuestionId(questionId);
            var userId          = _claimHelper.GetUserId();

            answer.SetAsChosenAnswer(command.QuestionInquirerId, userId, questionAnswers);
            _answerRepository.Update(answer);
        }
        public void Handle(AddVote command)
        {
            var voterId    = _claimHelper.GetUserId();
            var voter      = new UserId(voterId);
            var vote       = new Vote(voter, command.Opinion);
            var questionId = new QuestionId(command.QuestionId);
            var question   = _questionRepository.Get(questionId);

            question.Vote(vote);
            _questionRepository.Update(question);
        }
        private void SendOpenQuestionCommand(int hourNumber, int questionNumber)
        {


            if (hourNumber < 1)
            {
                throw new InvalidOperationException("Trying to open a question when hour is less than 1");
            }

            QuestionId parameter = new QuestionId(hourNumber, questionNumber);

            TriviaCommands.OpenQuestion.Execute(parameter, null);
        }
        public QuestionTestBuilder()
        {
            var clock = new Clock();

            Id    = new QuestionId(1);
            Title = "how to ?";
            Body  = "the description";
            Tags  = new List <long> {
                1, 2, 3
            };
            Inquirer     = new UserId(2);
            CreationDate = clock.PastDateTime();
        }
Beispiel #19
0
        public override byte[] GetData()
        {
            var data = new byte[QuestionSize + ChoiceSize + TimeSize];

            Buffer.BlockCopy(QuestionId.ToOrderByteArray(), 0, data, QuestionOffSet, QuestionSize);
            Buffer.BlockCopy(ChoiceId.ToOrderByteArray(), 0, data, ChoiceOffSet, ChoiceSize);

            var time = BitConverter.GetBytes(Time);

            Array.Reverse(time);
            Buffer.BlockCopy(time, 0, data, TimeOffSet, TimeSize);

            return(data);
        }
Beispiel #20
0
 public void TestQuestionIdInvalidFormat(string input, bool throws)
 {
     if (throws)
     {
         var ex = Assert.Throws <ArgumentException>(() => new QuestionId(input));
         Assert.AreEqual($"The QuestionId has an invalid format: \"{input}\", Expected \"<question-catalog-name>:<lineNumber>\".", ex.Message);
     }
     else
     {
         var questionId = new QuestionId(input);
         Assert.AreEqual(input, questionId.Value);
         Assert.AreEqual(new QuestionCatalogName(input.Split(':')[0]), questionId.QuestionCatalogName);
     }
 }
Beispiel #21
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (QuestionId.Length != 0)
            {
                hash ^= QuestionId.GetHashCode();
            }
            hash ^= oa_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #22
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (QuestionId != null)
         {
             hashCode = hashCode * 59 + QuestionId.GetHashCode();
         }
         if (Answer != null)
         {
             hashCode = hashCode * 59 + Answer.GetHashCode();
         }
         return(hashCode);
     }
 }
Beispiel #23
0
        public override byte[] GetData()
        {
            var data = new byte[16 + 16 + Name.Length + Authorities.Sum(a => a.Length)];

            Buffer.BlockCopy(QuestionId.ToOrderByteArray(), 0, data, 0, 16);
            Buffer.BlockCopy(Id.ToOrderByteArray(), 0, data, 16, 16);
            Buffer.BlockCopy(Encoding.UTF8.GetBytes(Name), 0, data, 32, Name.Length);

            var offset = 32 + Name.Length;

            foreach (var autoridad in Authorities)
            {
                Buffer.BlockCopy(autoridad, 0, data, offset, autoridad.Length);
                offset += autoridad.Length;
            }

            return(data);
        }
        public void Should_Call_Update_On_Repository_And_Set_This_As_Chosen_Answer_When_Command_Passed()
        {
            //Arrange
            var command = CommandFactory.BuildACommandOfType().ChosenAnswer;
            var answer  = CreateAnswer(command);
            var answersOfSpecificQuestion = CreateAnswers(3);

            answersOfSpecificQuestion.Add(answer);
            _answerRepository.Setup(a => a.Get(answer.Id)).Returns(answer);
            var questionId = new QuestionId(command.QuestionId);

            _answerRepository.Setup(a => a.GetByQuestionId(questionId)).Returns(answersOfSpecificQuestion);

            //Act
            _answerCommandHandler.Handle(command);

            //Assert
            _answerRepository.Verify(a => a.Update(answer));
        }
Beispiel #25
0
        private static async Task Main(string[] args)
        {
            CancellationToken cancellationToken;

            RegisterServices();
            var examService = Container.Resolve <ExamService>();
            var proctorId   = Guid.NewGuid();
            var studentId   = Guid.NewGuid();

            var assignExamResult = await examService.AssignExamAsync("ABC", studentId, cancellationToken);

            Console.WriteLine($"Assign Exam Results: {assignExamResult}");

            var examId         = Guid.Parse(assignExamResult.ExamId);
            var questionIds    = assignExamResult.QuestionIds.Select(_ => Guid.Parse(_)).ToList();
            var studentAnswers = questionIds.Select(questionId =>
                                                    new Answer(QuestionId.With(questionId), StudentId.With(studentId), "True")).ToList();

            var studentAnswerSubmittalResult = await examService.StudentAnswersSubmittalAsync(
                examId, studentId, studentAnswers, cancellationToken);

            Console.WriteLine($"Student Answers Submittal Results: {studentAnswerSubmittalResult}");

            var startScoringResult = await examService.StartScoring(examId, cancellationToken);

            Console.WriteLine($"Scoring started results: {startScoringResult}");

            var receiveScoreExecutionResults = new List <string>();

            foreach (var answer in studentAnswerSubmittalResult.AggregateStudentAnswers)
            {
                var receiveScoreResult = await examService.ReceiveScore(
                    examId, proctorId, 100.00, answer.Id, cancellationToken);

                receiveScoreExecutionResults.Add(receiveScoreResult);
            }
            Console.WriteLine($"Scoring results: {receiveScoreExecutionResults}");
        }
Beispiel #26
0
        /// <summary>
        /// Returns true if QuestionAndAnswer instances are equal
        /// </summary>
        /// <param name="other">Instance of QuestionAndAnswer to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(QuestionAndAnswer other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     QuestionId == other.QuestionId ||
                     QuestionId != null &&
                     QuestionId.Equals(other.QuestionId)
                     ) &&
                 (
                     Answer == other.Answer ||
                     Answer != null &&
                     Answer.Equals(other.Answer)
                 ));
        }
 // [JsonConstructor]
 public QuestionCreatedNotification(QuestionId questionId) : base(null)
 {
     this.QuestionId = questionId;
 }
 public QuestionCreatedNotification(QuestionCreatedEvent domainEvent) : base(domainEvent)
 {
     this.QuestionId = domainEvent.QuestionId;
 }
 public QuestionChangedEvent(QuestionId id)
 {
     this.id = id;
 }
Beispiel #30
0
 public StudentExamAnswersSubmittalCommand(Guid examId, Guid studentId, List <AnswersDto> answers) : base(ExamId.With(examId))
 {
     StudentId = StudentId.With(studentId);
     Answers   = answers.Select(_ => new Answer(QuestionId.With(_.QuestionId),
                                                StudentId.With(studentId), _.AnswerText)).ToList();
 }
Beispiel #31
0
 public Question()
 {
     // Exists for XML serialization...
     this.mQuestionId = new QuestionId(-1, -1);  // Illegal and must be changed later
 }
Beispiel #32
0
		public Question(int hour, int questionNumber)
		{
            if (hour <= 0)
            {
                throw new ArgumentOutOfRangeException("hour");
            }

            if (questionNumber <= 0)
            {
                throw new ArgumentOutOfRangeException("questionNumber");
            }

            this.mQuestionId = new QuestionId(hour, questionNumber);
		}
 public QuestionTestBuilder WithId(long id)
 {
     Id = new QuestionId(id);
     return(this);
 }
Beispiel #34
0
 public QuestionChanges(QuestionId id) : this()
 {
     this.Hour = id.Hour;
     this.Number = id.Number;
 }
Beispiel #35
0
        /// <summary>
        /// A question may not always exist, for example, if someone submits an answer for an hour that's not loaded from the server yet (i.e. a past hour).  So try to get the hour if it exists.
        /// </summary>
        public bool TryGetQuestion(QuestionId id, out QuestionViewModel question)
        {
            Contract.Requires(id != null);

            return this.TryGetQuestion(id.Hour, id.Number, out question);
        }