public void SavedUserGetsId()
 {
     var user = new User { Name = "Ron", SignupDate = DateTime.Now, OpenId = "asdf" };
     Assert.AreEqual(0, user.Id);
     _userRepository.Save(user);
     Assert.AreNotEqual(0, user.Id);
 }
 public static Question CreateQuestion(User user)
 {
     var creationDate = DateTime.Now;
     return new Question {Author = user, Title = "Is there a god?", Body = "Well, is there?",
         UpdateDate = creationDate,
                          CreatedDate = creationDate
     };
 }
        public void SavedUsersDetails_AreRetrieved()
        {
            var user = new User { Name = "Ron", SignupDate = DateTime.Now, OpenId = "asdf" ,WebsiteUrl = new Uri("http://foo.com")};
            _userRepository.Save(user);
            var savedUser = _userRepository.GetById(user.Id);

            Assert.AreEqual("Ron", savedUser.Name);
            Assert.AreEqual("http://foo.com/", savedUser.WebsiteUrl.AbsoluteUri);
        }
        //
        // Get: /Authentication/Login/openid
        public ActionResult Authenticate()
        {
            using (var relayingParty = new OpenIdRelyingParty())
            {
                var response = relayingParty.GetResponse();

                if (response == null)
                {
                    // Stage 2: user submitting Identifier
                    var openId = Request.Form["openId"];
                    relayingParty.CreateRequest(openId).RedirectToProvider();

                    throw new Exception("Never gets here");
                }

                // Stage 3: OpenID Provider sending assertion response
                switch (response.Status)
                {
                    case AuthenticationStatus.Authenticated:
                        var claimedIdentifier = response.ClaimedIdentifier;
                        var user = Users.FindByOpenId(claimedIdentifier);
                        if (user != null)
                        {
                            // login
                            return RedirectFromLoginPage(user);
                        }

                        // register
                        var username = response.FriendlyIdentifierForDisplay;
                        user = new User
                                       {
                                           Name = username,
                                           OpenId = claimedIdentifier,
                                           Reputation = 1,
                                           SignupDate = DateTime.Now
                                       };
                        Users.Save(user);
                        return RedirectFromLoginPage(user);

                    case AuthenticationStatus.Canceled:
                        ViewData["Message"] = "Canceled at provider";
                        // todo
                        return View("Login");

                    case AuthenticationStatus.Failed:
                        ViewData["Message"] = response.Exception.Message;
                        // todo
                        return View("Login");

                    default:
                        throw new Exception("Unknown status");
                }
            }
        }
예제 #5
0
        public User CreateUser()
        {
            var user = new User
                           {
                               Name = "User" + _id,
                               SignupDate = DateTime.Now,
                               OpenId = "OpenId" + _id,

                           };
            ++_id;
            _userRepository.Save(user);
            return user;
        }
 public void SaveProblem()
 {
     var u = new User { SignupDate = DateTime.Now, Name = "Foo", OpenId = "Bar" };
     ActiveRecordMediator<User>.Save(u);
     var q = new Question
     {
         Author = u,
         Body = "",
         CreatedDate = DateTime.Now,
         LastRelatedUser = u,
         Title = "",
         UpdateDate = DateTime.Now
     };
     ActiveRecordMediator<Question>.Save(q);
     var v = new VoteOnQuestion { Key = new VoteKey(u.Id, q.Id) };
     ActiveRecordMediator<VoteOnQuestion>.Save(v);
 }
 public RichQuestion GetById(User viewingUser, int questionId, int answerStart, int numAnswers)
 {
     var question = _questionsRepository.GetById(questionId);
     var votesOnQuestions = _questionVoteRepository.GetVoteCount(questionId);
     VoteType? vote = null;
     if (viewingUser != null)
     {
         var voteOnQuestion = _questionVoteRepository.GetVote(viewingUser.Id, questionId);
         if (voteOnQuestion != null)
             vote = voteOnQuestion.Vote;
     }
     var answers = _answersRepository.GetTopAnswers(questionId, answerStart, numAnswers);
     var answerCount = _answersRepository.GetAnswerCount(questionId);
     var answerIDs = answers.Select(x => x.Id);
     var votesOnAnswers = viewingUser == null ? null : _answerVoteRepository.GetVotes(viewingUser.Id, answerIDs);
     return new RichQuestion(question, votesOnQuestions.Total, vote, CreateRichAnswers(answers, votesOnAnswers), answerCount);
 }
예제 #8
0
 private void AddAnswers()
 {
     for (int i = 0; i < 10; ++i)
     {
         int questionId = _random.Next(_questions.Count) + 1;
         int authorId = _random.Next(_users.Count) + 1;
         var author = new User { Id = authorId };
         var date = GetRandomDate();
         var answer = new Answer
                          {
                              Author = author,
                              Body = RandomText(20),
                              CreatedDate = date,
                              LastRelatedUser = author,
                              QuestionId = questionId,
                              UpdateDate = date,
                          };
         _answers.Add(answer);
         _answersRepository.Save(answer);
     }
 }
예제 #9
0
 public EmptyModel(User loggedInUser)
     : base(loggedInUser)
 {
 }
예제 #10
0
 protected ModelBase(User loggedInUser)
 {
     LoggedInUser = loggedInUser;
 }
예제 #11
0
 private void AddUsers(params string []names)
 {
     foreach (var name in names)
     {
         var user = new User
                        {
                            Name = name,
                            SignupDate = DateTime.Now.Subtract(TimeSpan.FromHours(_random.Next(200))),
                            OpenId = "abc" + _random.Next(1000000),
                        };
         _userRepository.Save(user);
         _users.Add(user);
     }
 }
 private ActionResult RedirectFromLoginPage(User user)
 {
     FormsAuthentication.RedirectFromLoginPage(user.Id.ToString(), false);
     return new EmptyResult();
 }
 protected Question SaveQuestion(User user)
 {
     var question = QuestionsFactory.CreateQuestion(user);
     QuestionsRepository.Save(question);
     return question;
 }
 public void SavingQuestionWithDefaultDate_Fails()
 {
     var user = new User {Name = "Foob"};
     _userRepository.Save(user);
     var question = new Question{Author = user, Body = "Asdf", Title = "ASd"};
     _questionsRepository.Save(question);
 }
 public void SaveUserWithoutWebsite()
 {
     var user = new User {Name = "Ron", SignupDate = DateTime.Now, OpenId = "asdf"};
     _userRepository.Save(user);
     _userRepository.GetById(user.Id);
 }
        private void CreateData()
        {
            _questionAuthor = UserFactory.CreateUser();
            _question = SaveQuestion(_questionAuthor);
            for (int i = 0; i < 5; ++i)
            {
                var answer = new Answer
                {
                    Author = _questionAuthor,
                    Body = i.ToString(),
                    CreatedDate = DateTime.Now,
                    LastRelatedUser = _questionAuthor,
                    QuestionId = _question.Id,
                    UpdateDate = DateTime.Now
                };
                _answersRepository.Save(answer);
                _answers.Add(answer);

                // add i up-votes for answer i
                for (int j = 0; j < i; ++j)
                {
                    var voter = UserFactory.CreateUser();
                    AnswerVoteRepository.CreateOrUpdateVote(voter, answer, VoteType.ThumbUp);
                }
            }
        }