public void LoadMemberProfileWithNote()
        {
            var member = new Member
                             {
                                 Email = "*****@*****.**",
                                 OpenId = ConnectionHelper.OpenId,
                                 UserName = "******",
                                 Note = 2345
                             };

            var memberRepository = A.Fake<IMemberRepository>();
            var accountController = ControllerLocator.GetAccountControllerForConnectedUser(memberRepository);

            A.CallTo(() => memberRepository.Get(member.OpenId)).Returns(member);

            var result = accountController.Profile() as ViewResult;
            var memberResult = result.ViewData.Model as ProfileModel;

            Assert.That(result, Is.Not.Null);
            Assert.That(memberResult.Email, Is.EqualTo(member.Email));
            Assert.That(memberResult.UserName, Is.EqualTo(member.UserName));
            Assert.That(memberResult.Note, Is.EqualTo(new NoteModel(member.Note)));

            A.CallTo(() => memberRepository.Get(member.OpenId)).MustHaveHappened();
        }
        public void EditMemberProfile(Member member)
        {
            var dbMember = _membersCollection.AsQueryable()
                .FirstOrDefault(m => m.OpenId == member.OpenId);

            dbMember.UserName = member.UserName;
            dbMember.Email = member.Email;
            _membersCollection.Save(dbMember);

            Logger.Info("The user "+ member.UserName + " has updated its profile.");
        }
 public void AddResponse(string problemId, string text, Member member)
 {
     var problem = _problemsCollection.AsQueryable()
         .FirstOrDefault(m => m.Id == new ObjectId(problemId));
     problem.Responses.Add(new Response
                               {
                                   Text = text,
                                   UserId = member.Id
                               });
     _problemsCollection.Save(problem);
 }
        private void CloseProblemWithSolution(string problemId, Member member, Response solution)
        {
            var problem = _problemsCollection.AsQueryable()
                .FirstOrDefault(m => m.Id == new ObjectId(problemId));

            if (!member.Id.Equals(problem.UserId))
            {
                throw new AccessViolationException("Only the problem create can close it");
            }

            problem.ClosureDate = DateTime.Now;
            problem.CurrentSolution = solution;
            _problemsCollection.Save(problem);
        }
        public Problem CreateProblem(string title, string text, Member member)
        {
            ValidateMember(member);
            ValidateProblemInformations(title, text);

            var problem = new Problem
                                  {
                                      UserId = member.Id,
                                      Text = text,
                                      OpenedDate = DateTime.Now,
                                      Title = title
                                  };
            _problemsCollection.Save(problem);
            return problem;
        }
        public void LoadMemberProfileWithNoteWithoutEmail()
        {
            var member = new Member
            {
                Email = null, // No email was given by member
                OpenId = ConnectionHelper.OpenId,
                UserName = "******",
                Note = 2345
            };

            var memberRepository = A.Fake<IMemberRepository>();
            var accountController = ControllerLocator.GetAccountControllerForConnectedUser(memberRepository);

            A.CallTo(() => memberRepository.Get(member.OpenId)).Returns(member);

            var result = accountController.Profile() as ViewResult;
            var memberResult = result.ViewData.Model as ProfileModel;

            Assert.That(result, Is.Not.Null);
            Assert.That(memberResult.Email, Is.EqualTo(string.Empty));

            A.CallTo(() => memberRepository.Get(member.OpenId)).MustHaveHappened();
        }
        private Member CreateOnFirstLogIn(string openId, string email)
        {
            int nb = _membersCollection.Count() + 1;
            var member = new Member
                                {
                                    OpenId = openId,
                                    UserName = "******" + nb,
                                    FirstConnection = DateTime.Now,
                                    LastConnection = DateTime.Now
                                };
            if(!String.IsNullOrEmpty(email)) member.Email = email;
            _membersCollection.Save(member);

            Logger.Info("A new person has logged in LittleProblem. "+
                " Its account has been created with temp username : "******" and it will be linked to the openId : " + member.OpenId);

            return member;
        }
Пример #8
0
 public bool Equals(Member other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.OpenId, OpenId) && Equals(other.UserName, UserName) && Equals(other.Email, Email);
 }
 private void NoteResponse(string problemId, string responseId, Member member, int note)
 {
     var problem = _problemsCollection.AsQueryable()
         .FirstOrDefault(m => m.Id == new ObjectId(problemId));
     var response = problem.Responses.Where(r => r.Id == new ObjectId(responseId)).First();
     if (response.UserId.Equals(member.Id))
     {
         throw new Exception("You can't note yourself");
     }
     response.Note += note;
     _problemsCollection.Save(problem);
 }
Пример #10
0
 public void ValidateAsASolution(string problemId, Member member, Response response)
 {
     CloseProblemWithSolution(problemId, member, response);
     NoteResponse(problemId, response.Id.ToString(), member, +1);
 }
Пример #11
0
 public void UpResponse(string problemId, string responseId, Member member)
 {
     NoteResponse(problemId, responseId, member, +1);
 }
Пример #12
0
 public void CloseProblem(string problemId, Member member)
 {
     CloseProblemWithSolution(problemId, member, null);
 }
Пример #13
0
 private void ValidateMember(Member member)
 {
     if (member == null)
     {
         throw new ArgumentException("It require a member so null values are not accepted.");
     }
     var existingMember = _connexion.Collection<Member>(CollectionNames.Member)
         .AsQueryable().Where(m => m.Id == member.Id).FirstOrDefault();
     if (existingMember == null)
     {
         throw new ArgumentException("It requiere an existing member already persisted in db.");
     }
 }
        public ActionResult Profile(ProfileModel model)
        {
            var member = new Member{
                Email = model.Email,
                UserName = model.UserName,
                OpenId = MemberInformations.OpenId};
            _membershipService.EditMemberProfile(member);

            return RedirectToAction("Profile");
        }