コード例 #1
0
        public void WhenAnswerBodyModified_ShouldUpdateViewModel()
        {
            QuestionHelper questionHelper = new QuestionHelper(AppHost.Container);

            //Arrange
            string questionOwnerUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(questionOwnerUserId);

            string answerOwnerUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(answerOwnerUserId);

            //First user asks question
            SetSession(new CustomUserSession()
            {
                UserId = questionOwnerUserId
            });

            AskQuestionResponse askQuestionResponse = questionHelper.AskQuestion();

            //Second user answers the quetion question
            SetSession(new CustomUserSession()
            {
                UserId = answerOwnerUserId
            });

            AnswerStatusResponse answerQuestionResponse = questionHelper.AnswerQuestion(askQuestionResponse.QuestionId);


            AnswerService answerService = AppHost.Container.Resolve<AnswerService>();

            answerService.Post(new ChangeAnswerRequest()
            {
                
                AnswerId = answerQuestionResponse.AnswerId,
                Body = "Here is a new body"
            });

            //Assert
            QuestionDocument question = AppHost.Container.Resolve<ViewContext>().Questions.GetById(askQuestionResponse.QuestionId);

            Assert.AreEqual(1, question.Answers.Count, "The question should containt only one answer");

            AnswerPayload answer = question.Answers[answerQuestionResponse.AnswerId];

            answer.PrintDump();

            Assert.AreEqual("Here is a new body", answer.Body);

        }
コード例 #2
0
        public void WhenQuestionAnswered_ShouldAnswerResponseBeValid()
        {
            QuestionHelper questionHelper = new QuestionHelper(AppHost.Container);

            string userId = Guid.NewGuid().ToString();

            CreateInMemoryUser(userId);
            SetSession(new CustomUserSession()
            {
                UserId = userId
            });

            AskQuestionResponse askQuestionResponse = questionHelper.AskQuestion();

            askQuestionResponse.PrintDump();
            Assert.IsNotNull(askQuestionResponse.QuestionId, "Question should be created. QuestionId cannot be null.");

            var answerResponse = questionHelper.AnswerQuestion(askQuestionResponse.QuestionId);
            answerResponse.PrintDump();
            Assert.IsNotNull(answerResponse.AnswerId, "Answer should be created. AnswerId cannot be null.");

            var removeResponse = questionHelper.RemoveAnswer(answerResponse.AnswerId);
        }
コード例 #3
0
        public void WhenVoteQuestionUp_ShouldIncreaseQuestionRating()
        {
            QuestionHelper questionHelper = new QuestionHelper(AppHost.Container);

            //Arrange
            string questionOwnerUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(questionOwnerUserId);

            string votedUserUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(votedUserUserId);

            SetSession(new CustomUserSession()
            {
                UserId = questionOwnerUserId
            });

            AskQuestionResponse askQuestionResponse = questionHelper.AskQuestion();

            //Act
            SetSession(new CustomUserSession()
            {
                UserId = votedUserUserId
            });

            QuestionService service = AppHost.Container.Resolve<QuestionService>();

            service.Post(new VoteQuestionUpRequest()
            {
                QuestionId = askQuestionResponse.QuestionId
            });

            //Assert
            QuestionDocument question = AppHost.Container.Resolve<ViewContext>()
                .Questions.GetById(askQuestionResponse.QuestionId);

            Assert.AreEqual(QuestionScoreTable.QuestionVotedUp, question.Rating, "Vote vthe question up should increase its rating +1");
        }
コード例 #4
0
ファイル: UsersServiceTest.cs プロジェクト: Ontropix/whowhat
        public void WhenQuestionAnswered_ShouldNotificationBeCreated()
        {
            QuestionHelper questionHelper = new QuestionHelper(AppHost.Container);

            //Arrange
            string questionOwnerUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(questionOwnerUserId);

            string answerOwnerUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(answerOwnerUserId);

            //First user asks question
            OpenSession(questionOwnerUserId); 

            AskQuestionResponse askQuestionResponse = questionHelper.AskQuestion();

            //Second user answers the quetion question
            OpenSession(answerOwnerUserId);

            questionHelper.AnswerQuestion(askQuestionResponse.QuestionId);

            OpenSession(questionOwnerUserId);

            //The first user shoud get a notification that the question has been answered
            UsersService usersService = AppHost.Container.Resolve<UsersService>();

            NotificationsResponse response = usersService.Get(new NotificationsRequest() { Take = 20 });

            string votedUserUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(votedUserUserId);
            OpenSession(votedUserUserId);

            QuestionService questionService = AppHost.Container.Resolve<QuestionService>();

            OpenSession(votedUserUserId);
            //Vote up
            questionService.Post(new VoteQuestionUpRequest()
            {
                QuestionId = askQuestionResponse.QuestionId
            });

            //Vote down
            questionService.Post(new VoteQuestionDownRequest()
            {
                QuestionId = askQuestionResponse.QuestionId
            });

            questionService.Post(new VoteQuestionUpRequest()
            {
                QuestionId = askQuestionResponse.QuestionId
            });

            OpenSession(questionOwnerUserId);
            NotificationsResponse response2 = usersService.Get(new NotificationsRequest() { Take = 20});


            //Assertions
            Assert.IsNotNull(response);
            Console.WriteLine(response.Dump());
            Assert.AreEqual(1, response.Notifications.Count);

            Notification notification = response.Notifications[0];
            Assert.AreEqual(NotificationType.QuestionAnswered, notification.Type);
            Assert.AreEqual(askQuestionResponse.QuestionId, notification.QuestionId);

        }
コード例 #5
0
ファイル: UsersServiceTest.cs プロジェクト: Ontropix/whowhat
        public void WhenSubscriptionExists_AnsweringQuestion_ShouldInvokePusher()
        {
            QuestionHelper questionHelper = new QuestionHelper(AppHost.Container);

            //Arrange
            string questionOwnerUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(questionOwnerUserId);

            string answerOwnerUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(answerOwnerUserId);

            //First user asks question
            SetSession(new CustomUserSession()
            {
                UserId = questionOwnerUserId
            });

            AskQuestionResponse askQuestionResponse = questionHelper.AskQuestion();

            //Subscribe to notifications
            UsersService usersService = AppHost.Container.Resolve<UsersService>();
            usersService.Post(new SubscribeToPushupsRequest()
            {
                DeviceId = Guid.NewGuid().ToString(),
                DeviceOs = DeviceOS.WP,
                Token = "http://token.test"
            });

            //Second user answers the quetion question
            SetSession(new CustomUserSession()
            {
                UserId = answerOwnerUserId
            });
            questionHelper.AnswerQuestion(askQuestionResponse.QuestionId);

            Assert.IsNotNull(this.Pusher.WpToast);
            Console.WriteLine(this.Pusher.WpToast);
        }
コード例 #6
0
        public void WhenVoteAnswerUp_ShouldIncreaseUserRating()
        {
            QuestionHelper questionHelper = new QuestionHelper(AppHost.Container);

            //Arrange
            string questionOwnerUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(questionOwnerUserId);

            string answerOwnerUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(answerOwnerUserId);

            string votedUserUserId = Guid.NewGuid().ToString();
            CreateInMemoryUser(votedUserUserId);

            //First user asks question
            SetSession(new CustomUserSession()
            {
                UserId = questionOwnerUserId
            });

            AskQuestionResponse askQuestionResponse = questionHelper.AskQuestion();

            //Second user answers the quetion question
            SetSession(new CustomUserSession()
            {
                UserId = answerOwnerUserId
            });

            AnswerStatusResponse answerQuestionResponse = questionHelper.AnswerQuestion(askQuestionResponse.QuestionId);

            //Third user votes for the answer up.
            SetSession(new CustomUserSession()
            {
                UserId = votedUserUserId
            });

            AnswerService service = AppHost.Container.Resolve<AnswerService>();

            service.Post(new VoteAnswerUpRequest()
            {
                AnswerId = answerQuestionResponse.AnswerId
            });

            //Assert
            AnswerDocument answer = AppHost.Container.Resolve<ViewContext>().Answers.GetById(answerQuestionResponse.AnswerId);

            Assert.IsTrue(answer.Rating > 0);

            UserDocument user = AppHost.Container.Resolve<ViewContext>().Users.GetById(answerOwnerUserId);

            Assert.AreEqual(QuestionScoreTable.QuestionVotedUp, user.Reputation, "Vote for the answer up should increase rating of the user who answered (+10)");
        }