private void ViewQuestionAdded(IEditQuestionGroupView sender)
 {
     if (sender.QuestionType == typeof(OneAnswerQuestionBuilder))
     {
         QuestionBuilder builder = currentQuestionGroupBuider.AddQuestion(new OneAnswerQuestion());
         Argument.EditTreeView.RefreshObject(currentQuestionGroupBuider);
         Argument.EditTreeView.SelectObject(builder);
     }
 }
예제 #2
0
        public async Task Notify_When_Answer_Inserted_Success()
        {
            Question validQuestion = QuestionBuilder.Novo().Build();

            _questionRepository.Setup(o => o.GetById(_validCommand.QuestionId.Value)).ReturnsAsync(validQuestion);
            var result = await _handler.Handle(_validCommand);

            Assert.True(result.Sucess && result.Message == Message.NewAnswerInsertedSucess);
        }
예제 #3
0
        public async Task Ensure_Data_Is_Sent_To_Repository()
        {
            Question validQuestion = QuestionBuilder.Novo().Build();

            _questionRepository.Setup(o => o.GetById(_validCommand.QuestionId.Value)).ReturnsAsync(validQuestion);
            var result = await _handler.Handle(_validCommand);

            _answerRepository.Verify(r => r.Insert(It.Is <Answer>(q => q.Text == _validCommand.Text)));
        }
예제 #4
0
        private static Question CreateWhatsYourFavoriteBeer()
        {
            var questionBuilder = new QuestionBuilder();
            var question        = questionBuilder
                                  .WithQueryText("Whats is your favorite beer?")
                                  .AddMultipleAnswers("Ariana", "Hoegaarden", "Tuborg", "Staropramen")
                                  .BuildQuestion();

            return(question);
        }
예제 #5
0
        private static Question CreateWhatsYourFavoriteColor()
        {
            var questionBuilder = new QuestionBuilder();
            var question        = questionBuilder
                                  .WithQueryText("Whats is your favorite color?")
                                  .AddMultipleAnswers("Red", "Green", "Blue", "Alpha")
                                  .BuildQuestion();

            return(question);
        }
예제 #6
0
        private static Question CreateWhatsYourHomeTown()
        {
            var questionBuilder = new QuestionBuilder();
            var question        = questionBuilder
                                  .WithQueryText("What is your home town?")
                                  .AddMultipleAnswers("Sofia", "Varna", "Burgas", "Plovdiv")
                                  .BuildQuestion();

            return(question);
        }
예제 #7
0
    protected void LoadQuestion(QuestionSystemEnums.QuestionType questionType)
    {
        Question questionLoaded = QuestionBuilder.GetQuestion(questionType);
        string   question       = questionLoaded.question;

        gameObject.transform.GetChild(0).GetComponent <Text> ().text = question;
        questionAnswer = questionLoaded.answers.Length == 2 ?
                         (questionLoaded.answers[0].ToUpper() + "/" + questionLoaded.answers[1].ToUpper()):
                         questionLoaded.answers[UnityEngine.Random.Range(0, questionLoaded.answers.Length)].ToUpper();
    }
예제 #8
0
        private static Question CreateWhatsYourFavoriteProgrammingLanguage()
        {
            var questionBuilder = new QuestionBuilder();
            var question        = questionBuilder
                                  .WithQueryText("What is your favorite programming lanquage?")
                                  .AddMultipleAnswers("C#", "VB", "Java Script", "Java", "Python", "Ruby")
                                  .BuildQuestion();

            return(question);
        }
 void Start()
 {
     if (isDebug)
     {
         MyConst.Init();
         IQuestionProvider provider = new QuestionCSVProvider();
         QuestionBuilder.PopulateQuestion(provider);
         debugUI.SetActive(true);
         debugUI.transform.position = Vector3.zero;
     }
 }
 private void ViewDeleted(IEditQuestionView sender)
 {
     if (currentQuestionBuilder != null)
     {
         currentQuestionBuilder.ParentQuestionGroupBuilder.RemoveQuestion(currentQuestionBuilder);
         Argument.EditTreeView.RefreshObject(currentQuestionBuilder.ParentQuestionGroupBuilder);
         Argument.EditTreeView.SelectObject(currentQuestionBuilder.ParentQuestionGroupBuilder);
     }
     currentQuestionBuilder = null;
     sender.Hide();
 }
예제 #11
0
        public void Voteable_SameUserCannotApplyVoteTwice_Throws()
        {
            // Arrange
            var target     = new QuestionBuilder().SetupValidQuestion().Build();
            var firstVote  = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();
            var secondVote = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();

            target.ApplyVote(firstVote);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.ApplyVote(secondVote));
        }
예제 #12
0
        public void ShouldReturnsAResultWithTotalAmountOfQuestionsInRepository(int amountOfQuestions)
        {
            var questions = new QuestionBuilder().Generate(amountOfQuestions);

            mockQuestionRepository.Setup(x => x.GetAll()).Returns(questions);

            var result = questionService.GetAll();

            var totalQuestions = result.Count();

            totalQuestions.Should().Be(amountOfQuestions);
        }
예제 #13
0
        public void Answer_EditingWithInvalidData_FailsValidation(string userId, string body)
        {
            // Arrange - Build Answer
            var question = new QuestionBuilder().SetupValidQuestion().Build();
            var target   = new AnswerBuilder().SetupValidAnswer(question).Build();
            var limits   = new LimitsBuilder().Build();
            var user     = new UserBuilder().BuildUser(new Guid(userId)).Build();

            // Act, Assert
            Assert.Throws <BusinessException>(() =>
                                              target.Edit(user, body, limits));
        }
예제 #14
0
        private void ViewQuestionCopied(IEditTreeView sender, QuestionCopiedArgs e)
        {
            QuestionGroupBuilder builder = e.QuestionBuilder.ParentQuestionGroupBuilder;

            CopiedQuestionBuilder = e.QuestionBuilder;
            if (e.IsCut)
            {
                CopiedQuestionBuilder.ParentQuestionGroupBuilder.RemoveQuestion(e.QuestionBuilder);
            }
            sender.RefreshObject(builder);
            sender.SelectObject(builder);
        }
        private void ViewImport(IEditQuestionGroupView sender)
        {
            Question result = null;

            ApplicationController.Run <ImportPresenter, Action <Question> >((a) => result = a);
            if (result != null)
            {
                QuestionBuilder builder = currentQuestionGroupBuider.AddQuestion(result);
                Argument.EditTreeView.RefreshObject(currentQuestionGroupBuider);
                Argument.EditTreeView.SelectObject(builder);
            }
        }
예제 #16
0
        public void Question_CannotBeAnsweredBySameUserMoreThanOnce_Throws()
        {
            // Arrange
            var target       = new QuestionBuilder().SetupValidQuestion().Build();
            var firstAnswer  = new AnswerBuilder().SetupValidAnswer(target, new Guid("00000000-0000-0000-0000-000000000001")).Build();
            var secondAnswer = new AnswerBuilder().SetupValidAnswer(target, new Guid("00000000-0000-0000-0000-000000000001")).Build();

            target.Answer(firstAnswer);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.Answer(secondAnswer));
        }
 private void ViewHiden(IEditQuestionView sender)
 {
     if (!isHiding)
     {
         isHiding = true;
         View.Show();
         currentQuestionBuilder = null;
         HideViews();
         View.Hide();
         isHiding = false;
     }
 }
예제 #18
0
        public void Question_NonExistingAnswerCannotBeAccepted_Throws()
        {
            // Arrange
            var limits       = new LimitsBuilder().Build();
            var target       = new QuestionBuilder().SetupValidQuestion().Build();
            var firstAnswer  = new AnswerBuilder().SetupValidAnswer(target).Build();
            var secondAnswer = new AnswerBuilder().SetupAnotherValidAnswer(target).Build();

            target.Answer(firstAnswer);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.AcceptAnswer(secondAnswer));
        }
예제 #19
0
        public void Voteable_CannotRevokeNonExistingVote_Throws()
        {
            // Arrange
            var target     = new QuestionBuilder().SetupValidQuestion().Build();
            var limits     = new LimitsBuilder().Build();
            var firstVote  = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();
            var secondVote = new VoteBuilder(target).SetupValidUpvote().ByAnotherUser().Build();

            target.ApplyVote(firstVote);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.RevokeVote(secondVote, limits));
        }
예제 #20
0
        public void Voteable_CanApplyVoteToQuestion_Successfully()
        {
            // Arrange
            var target = new QuestionBuilder().SetupValidQuestion().Build();
            var vote   = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();

            // Act
            target.ApplyVote(vote);

            // Assert
            Assert.Equal(1, target.VotesSum);
            Assert.Contains(vote, target.Votes);
        }
예제 #21
0
        public void RemoveInexistentQuestionShouldFail()
        {
            // Arrange
            var falseQuestion = new QuestionBuilder().Build();
            var question = new QuestionBuilder().Build();
            var topic = new TopicBuilder().WithQuestion(question).Build();

            // Act
               var actual = topic.Questions.Remove(falseQuestion);

            // Assert
            Assert.IsFalse(actual);
        }
예제 #22
0
        public void QuestionTextShouldGetAndSetValues()
        {
            // Arrange
            var question = new QuestionBuilder().Build();
            var expected = "Test Question";

            // Act
            question.Text = expected;
            var actual = question.Text;

            // Assert
            Assert.AreEqual(expected, actual);
        }
예제 #23
0
        public void Answer_CreatingWithInvalidData_FailsValidation(string userId, string body)
        {
            // Arrange
            var question    = new QuestionBuilder().SetupValidQuestion().Build();
            var limits      = new LimitsBuilder().Build();
            var voteable    = new Voteable();
            var commentable = new Commentable();
            var user        = new UserBuilder().BuildUser(new Guid(userId)).Build();

            // Act, Assert
            Assert.Throws <BusinessException>(() =>
                                              Answer.Create(user, body, question, limits));
        }
예제 #24
0
        public void QuestionIdShouldGetAndSetValues()
        {
            // Arrange
            var question = new QuestionBuilder().Build();
            var expected = 45;

            // Act
            question.Id = expected;
            var actual = question.Id;

            // Assert
            Assert.AreEqual(expected, actual);
        }
예제 #25
0
        public void Question_EditingWithInvalidData_FailsValidation(string userId, int tagCount, string title, string body)
        {
            // Arrange - Build Question
            var user   = new UserBuilder().BuildUser(new Guid(userId)).Build();
            var target = new QuestionBuilder().SetupValidQuestion().Build();
            var limits = new LimitsBuilder().Build();

            // Arrange - Edit Data
            var editedTags = new TagBuilder().Build(tagCount);

            // Act
            Assert.Throws <BusinessException>(() =>
                                              target.Edit(user, title, body, editedTags, limits));
        }
예제 #26
0
        public void Question_OnAnswered_SetHasAcceptedAnswer()
        {
            // Arrange
            var target = new QuestionBuilder().SetupValidQuestion().Build();
            var answer = new AnswerBuilder().SetupValidAnswer(target).Build();

            target.Answer(answer);

            // Act
            target.AcceptAnswer(answer);

            // Assert
            Assert.True(target.HasAcceptedAnswer);
        }
예제 #27
0
        public void Question_MoreThanOneAcceptedAnswer_Throws()
        {
            // Arrange
            var target       = new QuestionBuilder().SetupValidQuestion().Build();
            var firstAnswer  = new AnswerBuilder().SetupValidAnswer(target).Build();
            var secondAnswer = new AnswerBuilder().SetupAnotherValidAnswer(target).Build();

            target.Answer(firstAnswer);
            target.Answer(secondAnswer);
            target.AcceptAnswer(firstAnswer);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.AcceptAnswer(secondAnswer));
        }
예제 #28
0
        public void Voteable_CanRevokeVoteWithinDeadline_Successfully()
        {
            // Arrange
            var target = new QuestionBuilder().SetupValidQuestion().Build();
            var vote   = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();
            var limits = new LimitsBuilder().Build();

            target.ApplyVote(vote);

            // Act
            target.RevokeVote(vote, limits);

            // Assert
            Assert.Equal(0, target.VotesSum);
        }
예제 #29
0
        public void UpdateQuestion_WithInvalidUserId_ShouldReturnErrorResult()
        {
            //---------------Arrange----------------------

            var question = new QuestionBuilder().Build();
            var command  = new AskQuestionCommandBuilder()
                           .WithInvalidUserId("")
                           .Build();

            //---------------Act--------------------------
            var notFound = Assert.ThrowsAsync <Exception>(() => command.UpdateQuestion(question, new CancellationToken()));

            //---------------Assert-----------------------
            Assert.That(notFound.Message, Is.EqualTo("User not found"));
        }
예제 #30
0
        public void RemoveQuestionToTopicShouldWork()
        {
            // Arrange
            var expectedCount = 0;
            var question = new QuestionBuilder().Build();
            var topic = new TopicBuilder().WithQuestion(question).Build();

            // Act
            topic.Questions.Remove(question);
            var actualCount = topic.Questions.Count();
            var actualQuestion = topic.Questions.FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreSame(null, actualQuestion);
        }
예제 #31
0
        public void Voteable_CannotRevokeVoteOutsideDeadline_Successfully()
        {
            // Arrange
            var target    = new QuestionBuilder().SetupValidQuestion().Build();
            var limits    = new LimitsBuilder().Build();
            var firstVote = new VoteBuilder(target)
                            .SetupValidUpvote()
                            .ByOneUser()
                            .MakeTimeGoBy()
                            .Build();

            target.ApplyVote(firstVote);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.RevokeVote(firstVote, limits));
        }
예제 #32
0
        public void ShouldReturnsAllQuestions()
        {
            var listQuestions = new List <Question>();

            var questions = new QuestionBuilder().Generate(4);

            listQuestions.ForEach(question => listQuestions.Add(question));

            mockQuestionRepository.Setup(x => x.GetAll()).Returns(listQuestions);

            var result = questionService.GetAll();

            mockQuestionRepository.Verify(x => x.GetAll(), Times.Once);

            result.Should().BeEquivalentTo(listQuestions);
        }
예제 #33
0
        public void Question_CanBeAnsweredBySameUserOnlyOnce_Sucessfully()
        {
            // Arrange
            var target       = new QuestionBuilder().SetupValidQuestion().Build();
            var firstAnswer  = new AnswerBuilder().SetupValidAnswer(target).Build();
            var secondAnswer = new AnswerBuilder().SetupAnotherValidAnswer(target).Build();

            // Act
            target.Answer(firstAnswer);
            target.Answer(secondAnswer);

            // Assert
            Assert.Equal(2, target.Answers.Count());
            Assert.Contains(firstAnswer, target.Answers);
            Assert.Contains(secondAnswer, target.Answers);
        }
예제 #34
0
        public async Task WriteService_CreateQuizWithQuestionsAndAnswersAndCorrectAnswer_CreatedSucessfully()
        {
            using var dbTrans = await NoCommitFactory().Create();

            var service          = GetQuizReadService(dbTrans);
            var writeService     = GetQuizWriteService(dbTrans);
            var questionBuilder1 = QuestionBuilder.New().WithText("Question 1").WithAnswers(new List <Answer>
            {
                AnswerBuilder.New().WithText("Q1: Answer 1").Entity,
                AnswerBuilder.New().WithText("Q1: Answer 2").Entity,
                AnswerBuilder.New().WithText("Q1: Answer 3").Entity
            });

            var questionBuilder2 = QuestionBuilder.New().WithText("Question 2").WithAnswers(new List <Answer>
            {
                AnswerBuilder.New().WithText("Q2: Answer 1").Entity,
                AnswerBuilder.New().WithText("Q2: Answer 2").Entity,
                AnswerBuilder.New().WithText("Q2: Answer 3").Entity
            });

            var quizBuilder = QuizBuilder.New().WithTitle("Test Quiz").WithQuestions(new List <Question> {
                questionBuilder1.Entity, questionBuilder2.Entity
            });
            await writeService.CreateQuiz(quizBuilder.Entity);

            var quiz = Assert.Single(await service.GetAllQuiz());

            Assert.NotNull(quiz);

            Assert.InRange(quiz.Questions.ToList().Count, 2, 2);

            foreach (var question in quiz.Questions)
            {
                Assert.Null(question.CorrectAnswer);
                Assert.InRange(question.AvailableAnswers.Count(), 3, 3);
            }

            quiz = await service.GetQuizById(quiz.Id);

            Assert.NotNull(quiz);
            var q = quiz.Questions.First();

            q.CorrectAnswer = q.AvailableAnswers.First();
            await writeService.UpdateQuestion(q);

            Assert.Single(quiz.Questions.Where(a => a.CorrectAnswer != null).ToList());
        }
예제 #35
0
        public void AddQuestionToTopicShouldWork()
        {
            // Arrange
            var expectedQuestionTitle = "Test Question";
            var expectedCount = 1;
            var topic = new TopicBuilder().Build();
            var question = new QuestionBuilder().WithText(expectedQuestionTitle).Build();

            // Act
            topic.Questions.Add(question);
            var actualCount = topic.Questions.Count();
            var actualQuestion = topic.Questions.FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreSame(question, actualQuestion);
        }
예제 #36
0
        public void AddAnswerToQuestionShouldWork()
        {
            // Arrange
            var expectedAnswerTitle = "Test Answer";
            var expectedCount = 1;
            var question = new QuestionBuilder().Build();
            var answer = new AnswerBuilder().WithText(expectedAnswerTitle).Build();

            // Act
            question.Answers.Add(answer);
            var actualCount = question.Answers.Count();
            var actualAnswer = question.Answers.FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreSame(answer, actualAnswer);
        }
예제 #37
0
        public void RemoveAnswerToQuestionShouldWork()
        {
            // Arrange
            var expectedCount = 0;
            var answer = new AnswerBuilder().Build();
            var question = new QuestionBuilder().WithAnswer(answer).Build();

            // Act
            question.Answers.Remove(answer);
            var actualCount = question.Answers.Count();
            var actualAnswer = question.Answers.FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreSame(null, actualAnswer);
        }
예제 #38
0
        public void RemoveInexistentAnswerShouldFail()
        {
            // Arrange
            var falseAnswer = new AnswerBuilder().Build();
            var answer = new AnswerBuilder().Build();
            var question = new QuestionBuilder().WithAnswer(answer).Build();

            // Act
            var actual = question.Answers.Remove(falseAnswer);

            // Assert
            Assert.IsFalse(actual);
        }
예제 #39
0
        public void QuestionTypeShouldGetAndSetValues()
        {
            // Arrange
            var question = new QuestionBuilder().Build();
            var expected = QuestionTypes.SingleOption;

            // Act
            question.QuestionType = expected;
            var actual = question.QuestionType;

            // Assert
            Assert.AreEqual(expected, actual);
        }