コード例 #1
0
        public QuestionApiModel AddQuestion(QuestionApiModel questionApiModel)
        {
            Question question = new Question()
            {
                QuestionText = questionApiModel.QuestionText,
                IsOpenToVotes = questionApiModel.IsOpenToVotes
            };

            return m_questionRepository.Add(question).ToApiModel();
        }
コード例 #2
0
        public void Add()
        {
            Question q = new Question
            {
                Id = ObjectId.GenerateNewId().ToString(),
                QuestionText = "Who's on first?"
            };

            IQuestionRepository repo = ObjectFactory.GetInstance<IQuestionRepository>();
            Question result = repo.Add(q);

            Assert.AreEqual(q.Id, result.Id);
        }
コード例 #3
0
        public void Update()
        {
            Question q = new Question
            {
                QuestionText = "Who's on first?",
                IsOpenToVotes = true
            };

            IQuestionRepository repo = ObjectFactory.GetInstance<IQuestionRepository>();
            Question questionFromDb = repo.Add(q);

            questionFromDb.QuestionText = "Who's on second?";
            repo.UpdateIsOpenToVotes(questionFromDb.Id, false);

            Question result = repo.GetById(questionFromDb.Id);

            Assert.AreEqual(questionFromDb.Id, result.Id);
            Assert.AreEqual(false, result.IsOpenToVotes);
        }
コード例 #4
0
        public void AddVote()
        {
            Question q = new Question
            {
                QuestionText = "What's the question?",
            };

            IQuestionRepository repo = ObjectFactory.GetInstance<IQuestionRepository>();
            Question newlyAddedQuestion = repo.Add(q);

            Vote vote = new Vote
            {
                Answer = VoteAnswer.Yes
            };

            repo.AddVote(newlyAddedQuestion.Id, vote);

            Question result = repo.GetById(newlyAddedQuestion.Id);
            Assert.AreEqual(1, result.Votes.Count);
            Assert.AreEqual(VoteAnswer.Yes, result.Votes[0].Answer);
        }
        public void AddQuestion()
        {
            QuestionApiModel questionApiModelToAdd = new QuestionApiModel
            {
                QuestionText = "Test Question",
                IsOpenToVotes = false
            };

            Question question = new Question
            {
                QuestionText = "Test Question",
                IsOpenToVotes = false
            };

            var questionRepoMock = new Mock<IQuestionRepository>();
            questionRepoMock.Setup(repo => repo.Add(It.IsAny<Question>())).Returns(question);

            QuestionsController controller = new QuestionsController(questionRepoMock.Object);
            var result = controller.AddQuestion(questionApiModelToAdd);

            Assert.AreEqual(question.QuestionText, result.QuestionText);
            Assert.IsInstanceOf<QuestionApiModel>(result);
        }
コード例 #6
0
 public Question Add(Question surveyQuestion)
 {
     return m_repository.Add(surveyQuestion);
 }