Exemplo n.º 1
0
        public void TestInitialize()
        {
            AppHost = new BasicAppHost().Init();
            Container = AppHost.Container;
            Pusher = new MockPusher();
            IdGenerator = new GuidEntityIdGenerator();
            QuestionHelper = new QuestionHelper(Container);

            ObjectFactory.Initialize(x => x.Scan(scan =>
            {
                scan.TheCallingAssembly();
                scan.WithDefaultConventions();
            }));

            Container.Adapter = new StructureMapContainerAdapter();
            
            Container.Register<ISessionFactory>(x => new InMemorySessionFactory());
            Container.Register<IImageStorageService>(x => new MockImageStorageService());
            Container.Register<ITypedSessionProvider>(x => _sessionProvider);
            
            //Register all services
            Container.RegisterAutoWired<UsersService>();
            Container.RegisterAutoWired<QuestionService>();
            Container.RegisterAutoWired<AnswerService>();
            Container.RegisterAutoWired<SearchService>();

            new TestConfig().Configure(ObjectFactory.Container);
            ObjectFactory.Container.Configure(config => config.For<IPusher>().Use(Pusher).Singleton());
            ObjectFactory.Container.AssertConfigurationIsValid();
        }
Exemplo n.º 2
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);

        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
0
        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);

        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
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)");
        }