Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void RateQuestion_Must_Return_NULL_If_RatedDown_Twice()
        {
            // Arrange
            var db = StaticMethods.GetDb();
            var discussionsService = new DiscussionsService(db, this.mapper);
            var testUser           = StaticMethods.GetTestUser();
            var testQBM            = GetTestQuestionBM();

            //Act
            db.Users.Add(testUser);
            db.SaveChanges();
            var addedQuestion = discussionsService.AddQuestion(testQBM, testUser);
            var questionRatingBindingModel = GetTestQuestionRatingBMRatingDown(addedQuestion);

            discussionsService.RateQuestion(questionRatingBindingModel, testUser);
            var thisMustBeNull = discussionsService.RateQuestion(questionRatingBindingModel, testUser);

            //Assert
            Assert.True(thisMustBeNull == null);
        }
Exemplo n.º 3
0
        public void RateQuestion_Must_Return_Updated_Question_RatedUp()
        {
            // Arrange
            var db = StaticMethods.GetDb();
            var discussionsService = new DiscussionsService(db, this.mapper);
            var testUser           = StaticMethods.GetTestUser();
            var testQBM            = GetTestQuestionBM();

            //Act
            db.Users.Add(testUser);
            db.SaveChanges();
            var addedQuestion = discussionsService.AddQuestion(testQBM, testUser);
            var questionRatingBindingModel = GetTestQuestionRatingBMRatingUp(addedQuestion);
            var ratedQuestion = discussionsService.RateQuestion(questionRatingBindingModel, testUser);

            //Assert
            Assert.True(ratedQuestion.Id == addedQuestion.Id);
            Assert.True(ratedQuestion.Rating == 1);
        }
Exemplo n.º 4
0
        public void IsUserDisLikedQuestion_Must_Return_True_If_User_DisLiked_Given_Question()
        {
            // Arrange
            var db = StaticMethods.GetDb();
            var discussionsService = new DiscussionsService(db, this.mapper);
            var testUser           = StaticMethods.GetTestUser();
            var testQBM            = GetTestQuestionBM();

            //Act
            db.Users.Add(testUser);
            db.SaveChanges();
            var addedQuestion = discussionsService.AddQuestion(testQBM, testUser);
            var questionRatingBindingModel = GetTestQuestionRatingBMRatingDown(addedQuestion);
            var ratedQuestion = discussionsService.RateQuestion(questionRatingBindingModel, testUser);
            var result        = discussionsService.IsUserDisLikedQuestion(ratedQuestion.Id, testUser.Id);

            //Assert
            Assert.True(result);
        }