Example #1
0
 public void AcceptAnswer(Answer answer)
 {
     answer.Accepted = true;
     _dataFactory.AnswerRepository.Update(answer);
     _dataFactory.Commit();
     _eventManager.AnswerEvaluated(answer);
 }
Example #2
0
 public void AnswerEvaluated(Answer answer)
 {
     var client = _socketManager.GetClient(answer.User.Email);
     if (client != null)
     {
         client.Send(SocketEvent.AnswerEvaluated(answer));
     }
 }
Example #3
0
 public bool DeclineAnswer(Answer answer)
 {
     answer.Accepted = false;
     _dataFactory.AnswerRepository.Update(answer);
     _dataFactory.Commit();
     _eventManager.AnswerEvaluated(answer);
     return SendQuestionToNewUser(answer.Question);
 }
Example #4
0
 public void AnswerSubmitted(Answer answer)
 {
     var client = _socketManager.GetClient(answer.Question.User.Email);
     if (client != null)
     {
         client.Send(SocketEvent.AnswerSubmitted(answer));
     }
 }
        public void DeclineAnswer_ShouldNotifyAdvisor()
        {
            //Arrange
            var answer = new Answer { Accepted = null, Question = new Question { ID = 1 } };

            //Act
            _adviseManager.DeclineAnswer(answer);

            //Assert
            _eventManager.Verify(x => x.AnswerEvaluated(answer), Times.Once);
        }
        public void AcceptAnswer_ShouldNotifyAdvisor()
        {
            //Arrange
            var answer = new Answer { Accepted = null };

            //Act
            _adviseManager.AcceptAnswer(answer);

            //Assert
            _eventManager.Verify(x => x.AnswerEvaluated(answer), Times.Once);
        }
Example #7
0
        public void AnswerSubmitted_ShouldReturnCorrectJson()
        {
            //Arrange
             const string expectedJson = "[\"AnswerSubmitted\",{\"ID\":1}]";
             var answer = new Answer { ID = 1, Question = new Question{ID = 1}};

             //Act
             var result = SocketEvent.AnswerSubmitted(answer);

             //Assert
             Assert.That(result, Is.EqualTo(expectedJson));
        }
Example #8
0
        public void AnswerEvaluated_ShouldReturnCorrectJson()
        {
            //Arrange
             const string expectedJson = "[\"AnswerEvaluated\",{\"ID\":1,\"Accepted\":true}]";
             var answer = new Answer { ID = 1, Accepted = true};

             //Act
             var result = SocketEvent.AnswerEvaluated(answer);

             //Assert
             Assert.That(result, Is.EqualTo(expectedJson));
        }
        public void AcceptAnswer_ShouldSetAcceptedStatus()
        {
            //Arrange
            var answer = new Answer {Accepted = null};

            //Act
            _adviseManager.AcceptAnswer(answer);

            //Assert
            Assert.That(answer.Accepted , Is.True);
            _answerRepository.Verify(x => x.Update(answer), Times.Once);
            _dataFactory.Verify(x => x.Commit(), Times.Once);
        }
        public void AcceptAnswer_ShouldSetDeclinedStatus()
        {
            //Arrange
            var answer = new Answer { Accepted = null, Question = new Question { ID = 1 } };
            _advisorLocator.Setup(x => x.GetNextInLine(It.IsAny<int>())).Returns(new User());

            //Act
            _adviseManager.DeclineAnswer(answer);

            //Assert
            Assert.That(answer.Accepted, Is.False);
            _answerRepository.Verify(x => x.Update(answer), Times.Once);
            _dataFactory.Verify(x => x.Commit(), Times.Exactly(2));
        }
        public void GetNextInLine_ShouldNotReturnUser_WhoHaveAnsweredheQuestionBefore()
        {
            //Arrange
            var question = new Question { ID = 1 };
            var answer = new Answer {ID = 1, Accepted = false, Question = question};
            question.Answers = new Collection<Answer>{answer};
            var user = new User { Answers = new Collection<Answer>{answer}, Connected = true };
            var pending = new PendingQuestion { Question = question, Status = true, User = user, Answer = answer};
            user.PendingQuestions = new Collection<PendingQuestion> { pending };

            var users = new List<User> { user };
            _userRepositoryMock.Setup(x => x.GetAvailableUsers()).Returns(users);
            _dataFactoryMock.Setup(x => x.UserRepository).Returns(_userRepositoryMock.Object);
            _advisorLocator = new AdvisorLocator(_dataFactoryMock.Object);

            //Act
            var result = _advisorLocator.GetNextInLine(question.ID);

            //Assert
            Assert.That(result, Is.Null);
        }
        public void DeclineAnswer_ShouldReturnFalse_IfNoAdvisorIsAvailable()
        {
            //Arrange
            var answer = new Answer { Accepted = null, Question = new Question { ID = 1 } };
            _advisorLocator.Setup(x => x.GetNextInLine(It.IsAny<int>())).Returns((User)null);
            //Act
            var result = _adviseManager.DeclineAnswer(answer);

            //Assert
            Assert.That(result, Is.False);
        }
 public AnswerSubmittedEvent(Answer answer)
 {
     ID = answer.Question.ID;
 }
Example #14
0
        public bool SubmitAnswer(PendingQuestion pending, string answer)
        {
            try
            {
                var now = DateTime.Now;
                if (now > GetDeadline(pending) || pending.Answer != null)
                {
                    return false;
                }

                var answerEntity = new Answer
                    {
                        Accepted = null,
                        Question = pending.Question,
                        Text = answer,
                        User = pending.User,
                        TimeStamp = now
                    };
                pending.Answer = answerEntity;
                _dataFactory.PendingQuestionRepository.Update(pending);
                _dataFactory.AnswerRepository.Insert(answerEntity);
                _dataFactory.Commit();
                _eventManager.AnswerSubmitted(answerEntity);
                return true;
            }
            catch (Exception e)
            {
                Logger.Log.Fatal("Exception during submit answer", e);
                throw;

            }
        }
        public void DeclineAnswer_ShouldPassTheQuestionOnToANewAdvisor()
        {
            //Arrange
            var answer = new Answer { Accepted = null, Question = new Question { ID = 1 } };
            _advisorLocator.Setup(x => x.GetNextInLine(It.IsAny<int>())).Returns(new User());
            //Act
            var result = _adviseManager.DeclineAnswer(answer);

            //Assert
            Assert.That(result, Is.True);
            _pendingQuestionRepository.Verify(x => x.Insert(It.IsAny<PendingQuestion>()), Times.Once);
            _dataFactory.Verify(x => x.Commit(), Times.Exactly(2));
        }
Example #16
0
 public static string AnswerSubmitted(Answer answer)
 {
     var eventData = new AnswerSubmittedEvent(answer);
     var json = string.Format(JsonBody, "AnswerSubmitted", JsonConvert.SerializeObject(eventData));
     return json;
 }
 public AnswerEvaluatedEvent(Answer answer)
 {
     ID = answer.ID;
     Accepted = answer.Accepted;
 }