コード例 #1
0
        public void GetPointsForUser_ShouldReturnCorrectPoints()
        {
            //Arrange
            var user = new User
                {
                    Answers = new Collection<Answer>
                        {
                            new Answer {Accepted = null},
                            new Answer {Accepted = false},
                            new Answer {Accepted = null},
                            new Answer {Accepted = false},
                            new Answer {Accepted = true},
                            new Answer {Accepted = true},
                            new Answer {Accepted = true}
                        }
                };

            _dataFactory.Setup(x => x.UserRepository.GetUserByEmail(It.IsAny<string>())).Returns(user);

            const int expectedPoints = 9;

            //Act
            var result = _scoreKeeper.GetPointsByUser("email");

            Assert.That(result, Is.EqualTo(expectedPoints));
        }
コード例 #2
0
        public CreateUserStatus CreateUser(string displayName, string email, string password)
        {
            try
            {
                if (_dataFactory.UserRepository.GetUserByEmail(email) != null)
                {
                    return CreateUserStatus.EmailAllreadyExists;
                }

                var user = new User
                {
                    Email = email,
                    Password = GetHashedPassword(email, password),
                    Created = DateTime.Now,
                    AdvisorProfile = new AdvisorProfile
                    {
                        DisplayName = displayName,
                        Description = string.Empty
                    }
                };

                _dataFactory.UserRepository.Insert(user);
                _dataFactory.Commit();
                return CreateUserStatus.Success;
            }
            catch (Exception e)
            {
                Logger.Log.Fatal("Exception during creation of a user.", e);
                return CreateUserStatus.Error;
            }
        }
コード例 #3
0
        public void PassQuestionForUser_ShouldPassQuestionsThatAreUnanswered()
        {
            var shouldPass = new PendingQuestion { Status = null, Question = new Question() { ID = 1 } };
            var shouldPass2 = new PendingQuestion { Status = true, Question = new Question() { ID = 1 } };
            var shouldNotPass = new PendingQuestion { Status = true, Answer = new Answer(), Question = new Question() { ID = 1 } };
            var shouldNotPass2 = new PendingQuestion { Status = false, Question = new Question() { ID = 1 } };

            var user = new User
            {
                PendingQuestions = new Collection<PendingQuestion>
                        {
                            shouldPass,
                            shouldPass2,
                            shouldNotPass,
                            shouldNotPass2
                        }
            };

            _dataFactory.Setup(x => x.UserRepository.GetUserByEmail(It.IsAny<string>())).Returns(user);
            _dataFactory.Setup(x => x.PendingQuestionRepository).Returns(new Mock<IPendingQuestionRepository>().Object);
            _advisorLocator.Setup(x => x.GetNextInLine(It.IsAny<int>())).Returns(new User());
            _adviseManager.PassQuestionForUser("email");

            Assert.That(shouldPass.Status, Is.False);
            Assert.That(shouldPass2.Status, Is.False);
            Assert.That(shouldNotPass.Status, Is.True);
            Assert.That(shouldNotPass2.Status, Is.False);
        }
コード例 #4
0
        public void GetAvailableUsers_ShouldOnlyReturnConnectedUsers()
        {
            //Arrange
            var dbMock = new Mock<IRadvillContext>();

            var userOne = new User
            {
                ID = 1,
                Connected = false
            };

            var userTwo = new User
            {
                ID = 2,
                Connected = true
            };

            var userThree = new User
            {
                ID = 3,
                Connected = true
            };

            var userFour = new User
            {
                ID = 4,
                Connected = true
            };
            var userDbSet = new FakeDbSet<User>
                 {
                     userOne,
                     userTwo,
                     userThree,
                     userFour
                 };

            dbMock.Setup(x => x.Users).Returns(userDbSet);
            dbMock.Setup(x => x.PendingQuestions).Returns(new FakeDbSet<PendingQuestion>());
            dbMock.Setup(x => x.Set<User>()).Returns(userDbSet);

            var userRepository = new UserRepository(dbMock.Object);

            //Act
            var result = userRepository.GetAvailableUsers();

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count(), Is.EqualTo(3));
            Assert.That(result.Any(x => !x.Connected), Is.False);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public void GetAvailableUsers_ShouldNotReturnUsers_WhoHasAcceptedToAnswer_ButHasNotCompletedIt()
        {
            //Arrange
            var dbMock = new Mock<IRadvillContext>();

            var userOne = new User
            {
                ID = 1,
                Connected = true
            };

            var userDbSet = new FakeDbSet<User>
                 {
                     userOne
                 };

            dbMock.Setup(x => x.Users).Returns(userDbSet);

            var pendingQuestion = new PendingQuestion
            {
                ID = 1,
                User = userOne,
                Answer = null,
                Status = true
            };

            var pendingQuestionDbSet = new FakeDbSet<PendingQuestion>
                 {
                     pendingQuestion
                 };

            dbMock.Setup(x => x.PendingQuestions).Returns(pendingQuestionDbSet);
            dbMock.Setup(x => x.Set<User>()).Returns(userDbSet);

            var userRepository = new UserRepository(dbMock.Object);

            //Act
            var result = userRepository.GetAvailableUsers();

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count(), Is.EqualTo(0));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public void GetHighScores_ShouldReturnCorrectScoreForAllUsers_OrderedByPoints()
        {
            //Arrange
            var user1 = new User
            {
                AdvisorProfile = new AdvisorProfile{ID = 1, Description = "description1", DisplayName = "name1"},
                Answers = new Collection<Answer>
                        {
                            new Answer {Accepted = true},
                            new Answer {Accepted = null},
                        }
            };
            var user2 = new User
            {
                AdvisorProfile = new AdvisorProfile { ID = 2, Description = "description2", DisplayName = "name2" },
                Answers = new Collection<Answer>
                        {
                            new Answer {Accepted = true},
                            new Answer {Accepted = true}
                        }
            };

            _dataFactory.Setup(x => x.UserRepository.GetAll()).Returns(new Collection<User>{user1, user2});

            const int expectedPointsUser1 = 5;
            const int expectedPointsUser2 = 10;

            //Act
            var result = _scoreKeeper.GetHighscores();

            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].Advisor, Is.EqualTo(user2.AdvisorProfile));
            Assert.That(result[0].Points, Is.EqualTo(expectedPointsUser2));
            Assert.That(result[1].Advisor, Is.EqualTo(user1.AdvisorProfile));
            Assert.That(result[1].Points, Is.EqualTo(expectedPointsUser1));
        }
コード例 #9
0
ファイル: ScoreKeeper.cs プロジェクト: nesheimroger/Radvill
 private int CalculatePoints(User user)
 {
     var acceptedpoints = user.Answers.Count(x => x.Accepted == true) * Configuration.Points.Accepted;
     var declinedpoints = user.Answers.Count(x => x.Accepted == false) * Configuration.Points.Declined;
     return acceptedpoints + declinedpoints;
 }
コード例 #10
0
        public void GetAvailableUsers_ShouldReturnUsers_WhoIsntAnswereringAQuestion()
        {
            //Arrange
             var dbMock = new Mock<IRadvillContext>();

             var userOne = new User
                 {
                     ID = 1,
                     Connected = true
                 };

             var userTwo = new User
                 {
                     ID = 2,
                     Connected = true
                 };

             var userDbSet = new FakeDbSet<User>
                 {
                     userOne,
                     userTwo
                 };

             dbMock.Setup(x => x.Users).Returns(userDbSet);

             var pendingQuestion = new PendingQuestion
                 {
                     ID = 1,
                     User = userOne
                 };

             var pendingQuestionDbSet = new FakeDbSet<PendingQuestion>
                 {
                     pendingQuestion
                 };

             dbMock.Setup(x => x.PendingQuestions).Returns(pendingQuestionDbSet);
            dbMock.Setup(x => x.Set<User>()).Returns(userDbSet);

             var userRepository = new UserRepository(dbMock.Object);

             //Act
             var result = userRepository.GetAvailableUsers();

             //Assert
             Assert.That(result, Is.Not.Null);
             Assert.That(result.Count(), Is.EqualTo(1));
             Assert.That(result.First().ID, Is.EqualTo(userTwo.ID));
        }