示例#1
0
        public void GetTopQuestion_Must_Return_Question_With_Highest_Rated_Question_By_Category()
        {
            // Testing with 2 categories
            // Arrange
            var db = StaticMethods.GetDb();
            var discussionsService = new DiscussionsService(db, this.mapper);
            var testUser1          = StaticMethods.GetTestUser();
            var testUser2          = StaticMethods.GetTestUser();
            var testQBM1           = GetTestQuestionBM(Category.AndroidDevelopment);
            var testQBM2           = GetTestQuestionBM(Category.AndroidDevelopment);
            var testQBM3           = GetTestQuestionBM(Category.C);
            var testQBM4           = GetTestQuestionBM(Category.C);

            //Act
            db.Users.Add(testUser1);
            db.SaveChanges();
            var addedQuestion1 = discussionsService.AddQuestion(testQBM1, testUser1);
            var addedQuestion2 = discussionsService.AddQuestion(testQBM2, testUser1);
            var addedQuestion3 = discussionsService.AddQuestion(testQBM3, testUser1);
            var addedQuestion4 = discussionsService.AddQuestion(testQBM4, testUser1);

            discussionsService.RateQuestion(GetTestQuestionRatingBMRatingUp(addedQuestion1), testUser2);
            discussionsService.RateQuestion(GetTestQuestionRatingBMRatingDown(addedQuestion2), testUser2);

            discussionsService.RateQuestion(GetTestQuestionRatingBMRatingUp(addedQuestion3), testUser2);
            discussionsService.RateQuestion(GetTestQuestionRatingBMRatingDown(addedQuestion4), testUser2);

            var result = discussionsService.GetTopQuestions();

            //Assert
            Assert.True(result.Count == 2);
            Assert.True(result[0].QuestionId == addedQuestion1.Id);
            Assert.True(result[1].QuestionId == addedQuestion3.Id);
        }