예제 #1
0
 public void AnswerKnowsTheUserWhoAnswered()
 {
     const string userName = "******";
     User user = new User(userName, "******", "*****@*****.**");
     Answer answer = new Answer(new AskMeDate(), user, "");
     Assert.AreEqual(user, answer.User);
 }
예제 #2
0
 public void VerifyAnswerInsertion()
 {
     User user = new User("PakodaSingh", "******", "*****@*****.**");
     user.UserId = 1;
     Repository repository = Repository.GetInstance();
     repository.SaveUser(user);
     Answer answer = new Answer(new AskMeDate(),  user, "");
     repository.SaveAnswer(answer);
 }
예제 #3
0
파일: Answer.cs 프로젝트: bagheera/askme
 public virtual bool Equals(Answer other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.createdOn, createdOn)
         && Equals(other.user, user)
         && Equals(other.text, text)
         && other.answerId == answerId;
 }
예제 #4
0
파일: VoteTest.cs 프로젝트: bagheera/askme
        public void AnswerShouldReturnNumberOfVotes()
        {
            User user = new User("user1", "123", "*****@*****.**");
            AnswerVote vote = AnswerVote.PositiveVote(user);

            User userWhoAnswered = new User("Answerer", "123", "*****@*****.**");
            Answer answer = new Answer(new AskMeDate(), userWhoAnswered, "Dummy answer");
            answer.CastVote(vote);
            Assert.AreEqual(1, answer.Votes.Count);
        }
예제 #5
0
파일: VoteTest.cs 프로젝트: bagheera/askme
        public void AnswererShouldGetTenPointsOnReceivingPositiveVote()
        {
            User user = new User("user1", "123", "*****@*****.**");
            AnswerVote vote = AnswerVote.PositiveVote(user);

            User userWhoAnswered = new User("Answerer", "123", "*****@*****.**");
            Answer answer = new Answer(new AskMeDate(), userWhoAnswered, "Dummy answer" );
            answer.CastVote(vote);
            Assert.AreEqual(10, userWhoAnswered.Points());
        }
예제 #6
0
파일: VoteTest.cs 프로젝트: bagheera/askme
        public void OneUserCanOnlyCastOneVoteForAnAnswer()
        {
            User userWhoAnswered = new User("Answerer", "123", "*****@*****.**");
            Answer answer = new Answer(new AskMeDate(), userWhoAnswered, "Dummy answer");

            User user = new User("user1", "123", "*****@*****.**");
            AnswerVote vote = AnswerVote.PositiveVote(user);

            answer.CastVote(vote);
            Assert.IsTrue(answer.Votes.HasUserVoted(user));

            answer.CastVote(vote);  //this should throw an exception
        }
예제 #7
0
파일: Question.cs 프로젝트: bagheera/askme
 public virtual void AcceptSolution(Answer answer)
 {
     lock (localLock)
     {
         if (acceptedAnswer == null)
         {
             acceptedAnswer = answer;
             AssignPointForAcceptingAnswer();
         }
         else
         {
             throw new NotSupportedException("An answer has been already accepted");
         }
     }
 }
예제 #8
0
 public void IfUserAndDateAndTextAreSameThenAnswersAreEqual()
 {
     Answer answer1 = new Answer(new AskMeDate(), UserMother.Kamal, "this is good answer");
     Answer answer2 = new Answer(new AskMeDate(), UserMother.Kamal, "this is good answer");
     Assert.AreEqual(answer1, answer2);
 }
예제 #9
0
 public void AnswerShouldHaveText()
 {
     const string answerText = "This was supposed to be a funny answer but Chandra couldn't come up with one";
     Answer answer = new Answer(new AskMeDate(), null, answerText);
     Assert.AreSame(answerText, answer.ToString());
 }
예제 #10
0
 public void AnswerKnowsWhenItWasCreated()
 {
     AskMeDate time = new AskMeDate();
     Answer answer = new Answer(time, null, "");
     Assert.AreEqual(time, answer.CreatedOn);
 }
예제 #11
0
파일: Answers.cs 프로젝트: bagheera/askme
 public void AddAnswer(Answer answer)
 {
     answers.Add(answer);
 }
예제 #12
0
파일: Question.cs 프로젝트: bagheera/askme
 public virtual void AddAnswer(Answer answer)
 {
     answers.AddAnswer(answer);
 }
예제 #13
0
파일: User.cs 프로젝트: bagheera/askme
 public virtual void AcceptAnswer(Question question,Answer answer)
 {
     if (!question.IsOwner(this))
         throw new NotSupportedException("An answer can be accepted only by the question's owner");
     question.AcceptSolution(answer);
 }
예제 #14
0
파일: VoteTest.cs 프로젝트: bagheera/askme
        public void ShouldBeAbleToSaveAndRetrieveVotesInAnswer()
        {
            User user = UserMother.Kamal;

            Answer answer = new Answer(new AskMeDate(), user, "answer to be voted");
            Repository repository = Repository.GetInstance();
            repository.SaveUser(user);

            AnswerVote vote = AnswerVote.NegativeVote(user);
            answer.CastVote(vote);
            repository.SaveAnswer(answer);

            repository.Evict(answer);

            string searchString = "answer to be voted";
            IList<Answer> answersFound = repository.SearchKeyWordInAnswers(searchString);

            Assert.AreEqual(1, answersFound.Count);
            Assert.AreEqual(1, answersFound[0].Votes.Count);
        }
예제 #15
0
파일: VoteTest.cs 프로젝트: bagheera/askme
        public void UserShouldBeAbleCastNegativeVote()
        {
            User userWhoAnswered = new User("Answerer", "123", "*****@*****.**");
            Answer answer = new Answer(new AskMeDate(), userWhoAnswered, "Dummy answer");

            User user = new User("user1", "123", "*****@*****.**");
            AnswerVote vote = AnswerVote.NegativeVote(user);

            answer.CastVote(vote);
        }