Beispiel #1
0
 public void AllRecipientsPassed(Question question)
 {
     var client = _socketManager.GetClient(question.User.Email);
     if (client != null)
     {
         client.Send(SocketEvent.AllRecipientsPassed(question));
     }
 }
        public void AllRecipientsPassed_ShouldReturnCorrectJson()
        {
            //Arrange
             const string expectedJson = "[\"AllRecipientsPassed\",{\"ID\":1}]";
             var question = new Question {ID = 1};

             //Act
             var result = SocketEvent.AllRecipientsPassed(question);

             //Assert
             Assert.That(result, Is.EqualTo(expectedJson));
        }
        public void GetNextInLine_ShouldNotReturnUser_WhoSubmittedQuestion()
        {
            //Arrange
            var question = new Question { ID = 1 };
            var user = new User { Questions = new Collection<Question>{question}, Answers = new Collection<Answer>(), Connected = true, PendingQuestions = new Collection<PendingQuestion>()};

            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 GetNextInLine_ShouldNotReturnUser_WhoHavePassedTheQuestionBefore()
        {
            //Arrange
            var question = new Question{ID = 1};
            var question2 = new Question{ID = 2};
            var user = new User { Answers = new Collection<Answer>(), Questions = new Collection<Question>(),Connected = true};
            var pending = new PendingQuestion {Question = question, Status = false, User = user};
            var pending2 = new PendingQuestion {Question = question2, Status = false, User = user};
            user.PendingQuestions = new Collection<PendingQuestion>{pending, pending2};

            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(question2.ID);

            //Assert
            Assert.That(result, Is.Null);
        }
Beispiel #5
0
 public static string AllRecipientsPassed(Question question)
 {
     var eventData = new AllRecipientsPassedEvent(question);
     var json = string.Format(JsonBody, "AllRecipientsPassed", JsonConvert.SerializeObject(eventData));
     return json;
 }
 public AllRecipientsPassedEvent(Question question)
 {
     ID = question.ID;
 }
        private int GetStatusForQuestion(Question question)
        {
            if (question.Answers.Any(x => x.Accepted == true))
            {
                return 6;
            }

            if (question.Answers.All(x => x.Accepted == false) && question.Stopped)
            {
                return 5;
            }

            if (question.Answers.Any(x => x.Accepted == false))
            {
                return 4;
            }

            if (question.Answers.Any(x => x.Accepted == null))
            {
                return 3;
            }

            var pendingQuestions = _dataFactory.PendingQuestionRepository.GetByQuestionID(question.ID);
            if (pendingQuestions.Any(x => x.Status == true))
            {
                return 2;
            }

            if (pendingQuestions.Any(x => x.Status == null))
            {
                return 1;
            }
            return 0;
        }
Beispiel #8
0
        private bool SendQuestionToNewUser(Question question)
        {
            var reciever = _advisorLocator.GetNextInLine(question.ID);
            if (reciever == null)
            {
                AllRecipientsPassed(question);
                return false;
            }

            var newPending = new PendingQuestion
            {
                Question = question,
                Status = null,
                TimeStamp = DateTime.Now,
                User = reciever
            };

            _dataFactory.PendingQuestionRepository.Insert(newPending);
            _dataFactory.Commit();
            _eventManager.QuestionAssigned(newPending);
            return true;
        }
Beispiel #9
0
 private void AllRecipientsPassed(Question question)
 {
     question.Stopped = true;
     _dataFactory.QuestionRepository.Update(question);
     _dataFactory.Commit();
     _eventManager.AllRecipientsPassed(question);
 }
Beispiel #10
0
        public bool SubmitQuestion(int userid, int categoryId, string question)
        {
            try
            {
                var user = _dataFactory.UserRepository.GetByID(userid);
                var category = _dataFactory.CategoryRepository.GetByID(categoryId);
                var timeStamp = DateTime.Now;

                var questionEntity = new Question
                {
                    Text = question,
                    Category = category,
                    User = user,
                    TimeStamp = timeStamp
                };

                _dataFactory.QuestionRepository.Insert(questionEntity);
                _dataFactory.Commit();

                var reciever = _advisorLocator.GetNextInLine(questionEntity.ID);

                if (reciever == null)
                {
                    _dataFactory.QuestionRepository.Delete(questionEntity);
                    _dataFactory.Commit();
                    return false;
                }

                var pendingEntity = new PendingQuestion
                {
                    Question = questionEntity,
                    Status = null,
                    User = reciever,
                    TimeStamp = timeStamp
                };

                _dataFactory.PendingQuestionRepository.Insert(pendingEntity);
                _dataFactory.Commit();
                _eventManager.QuestionAssigned(pendingEntity);
                return true;
            }
            catch (Exception e)
            {
                Logger.Log.Fatal("Exception during Submit Question", e);
                throw;
            }
        }