Ejemplo n.º 1
0
        public void LineageIsBuiltProperly()
        {
            var sut = new Member();

            sut.SetLineage("z", new List<string> {"a", "b", "c"});

            Assert.AreEqual("z", sut.VouchedBy);
            Assert.AreEqual(4, sut.Lineage.Count);
        }
Ejemplo n.º 2
0
        public void ForgotPasswordWorksProperly()
        {
            var sut = new Member() { Password = "******" };

            sut.ForgotPassword();

            Assert.IsNull(sut.Password);
            Assert.IsNotNull(sut.PasswordResetToken);
            Assert.IsNotNull(sut.PasswordResetTokenExpiration);
        }
        public ActionResult Index(InvitationAcceptanceCommand command)
        {
            try
            {
                var invitation = _session
                                    .Include<Invitation>(x => x.VouchedBy)
                                    .Load<Invitation>(Invitation.FormatId(command.Token));

                invitation.Accept();

                var voucher = _session.Load<Member>(invitation.VouchedBy);
                voucher.RemoveInvite(invitation.Id);

                var member = new Member
                {
                    Email = invitation.Email,
                    FullName = invitation.FullName,
                    UserName = command.UserName,
                    LinkedIn = invitation.LinkedIn,
                    GitHub = invitation.GitHub,
                };

                member.SetLineage(voucher.Id, voucher.Lineage);
                member.SetPassword(command.Password);

                _session.Store(member);

                var email = Identifier.FromEmail(invitation.Email, member.Id);
                member.AddIdentifier(email.Id);
                _session.Store(email);

                var username = Identifier.FromUserName(command.UserName, member.Id);
                member.AddIdentifier(username.Id);
                _session.Store(username);

                _session.Advanced.UseOptimisticConcurrency = true;
                _session.SaveChanges();

                _authentication.Login(member.Id);

                _email.SendAcceptanceNotificationToGroup(member);

                return RedirectToAction("Index", "Welcome");
            }
            catch (ConcurrencyException)
            {
                command.UserNameIsAvailable = false;
            }
            catch (ApplicationException e)
            {
                ModelState.AddModelError("", e.Message);
            }

            return View(command);
        }
Ejemplo n.º 4
0
        public void ResetPasswordThrowsProperly()
        {
            var sut = new Member()
            {
                PasswordResetToken = "bar",
                PasswordResetTokenExpiration = DateTimeOffset.UtcNow.AddMinutes(-60)
            };

            Assert.Throws<ApplicationException>(() => sut.ResetPassword("foo", "wrong"), "wrong token");
            Assert.Throws<ApplicationException>(() => sut.ResetPassword("foo", "bar"), "old reset token");
        }
        public void InvitationCreationWorksProperly()
        {
            using (var store = NewDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    var member = new Member();
                    member.UserName = "******";

                    session.Store(member);
                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    var command = new InvitationCreationController.InviteCommand
                    {
                        FullName = "jane.doe",
                        Email = "*****@*****.**",
                        GitHub = "github/janedoe",
                        LinkedIn = "linkedin/janedoe",
                        Testimonial = "awesome"
                    };

                    var members = new Mock<IFindMembers>();
                    members.Setup(x => x.FindLoggedInMember())
                           .Returns(session.Load<Member>(Member.FormatId("john.doe")));

                    var sut = new InvitationCreationController(session, members.Object, new Mock<IEmailNotificationService>().Object);
                    sut.Index(command);
                }

                using (var session = store.OpenSession())
                {
                    var member = session
                        .Include<Member>(x => x.Invitations)
                        .Load<Member>(Member.FormatId("john.doe"));

                    var invitation = session.Load<Invitation>(member.Invitations).First();

                    Assert.AreEqual(1, member.Invitations.Count);

                    Assert.AreEqual("jane.doe", invitation.FullName);
                    Assert.AreEqual("*****@*****.**", invitation.Email);
                    Assert.AreEqual("github/janedoe", invitation.GitHub);
                    Assert.AreEqual("linkedin/janedoe", invitation.LinkedIn);
                    Assert.AreEqual("awesome", invitation.Testimonial);
                    Assert.AreEqual(Invitation.Statuses.Pending, invitation.Status);
                }
            }
        }
Ejemplo n.º 6
0
        public void ResetPasswordWorksProperly()
        {
            var sut = new Member()
            {
                PasswordResetToken = "bar",
                PasswordResetTokenExpiration = DateTimeOffset.UtcNow.AddMinutes(20)
            };

            sut.ResetPassword("foo", "bar");

            Assert.IsTrue(sut.VerifyPassword("foo"));
            Assert.IsNull(sut.PasswordResetToken);
            Assert.IsNull(sut.PasswordResetTokenExpiration);
        }
Ejemplo n.º 7
0
 public void SendAcceptanceNotificationToGroup(Member member)
 {
     var api = new MandrillApi(_configuration.MadrillApiKey);
     var result = api.SendMessage(
         new EmailMessage()
         {
             to =
                 new List<EmailAddress>()
                 {
                     new EmailAddress {email = _configuration.MadrillOriginTarget}
                 },
             subject = member.FullName
         },
         "devlink-accept-invitation",
         new List<TemplateContent>()
         {
             new TemplateContent() {name = "candidate", content = member.FullName},
         });
 }
Ejemplo n.º 8
0
        public void PasswordResetWorksProperly()
        {
            var authentication = new Mock<IAuthentication>();

            using (var store = NewDocumentStore())
            {
                using(var session = store.OpenSession())
                {
                    var member = new Member();
                    member.UserName = "******";
                    member.PasswordResetToken = "foo";
                    member.PasswordResetTokenExpiration = DateTimeOffset.UtcNow.AddMinutes(20);

                    session.Store(member);
                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    var command = new MemberPasswordResetCommand
                    {
                        Password = "******",
                        Token = "foo",
                        UserName = "******"
                    };

                    var members = new Mock<IFindMembers>();
                    members.Setup(x => x.FindMemberByUserName(It.IsAny<string>()))
                           .Returns(session.Load<Member>(Member.FormatId(command.UserName)));

                    var sut = new MemberPasswordResetController(session, members.Object, authentication.Object);
                    sut.Post(command);
                }

                using (var session = store.OpenSession())
                {
                    var member = session.Load<Member>(Member.FormatId("john.doe"));

                    Assert.IsTrue(member.VerifyPassword("a new password"));
                    authentication.Verify(x => x.Login(Member.FormatId("john.doe")), Times.Once);
                }
            }
        }
        public void WorksProperly()
        {
            var notification = new Mock<IEmailNotificationService>();
            var authentication = new Mock<IAuthentication>();

            using (var store = NewDocumentStore())
            {
                string token;

                using (var session = store.OpenSession())
                {
                    var member = new Member();
                    member.UserName = "******";
                    session.Store(member);

                    var invitation = new Invitation
                    {
                        FullName = "jane.doe",
                        Email = "*****@*****.**",
                        GitHub = "github/janedoe",
                        LinkedIn = "linkedin/janedoe",
                        Testimonial = "awesome",
                        VouchedBy = member.Id,
                        Status = Invitation.Statuses.Pending
                    };
                    token = invitation.Token;
                    session.Store(invitation);

                    member.AddInvitation(invitation.Id);

                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    var command = new InvitationAcceptanceController.InvitationAcceptanceCommand
                    {
                        Password = "******",
                        Token = token,
                        UserName = "******"
                    };

                    var sut = new InvitationAcceptanceController(session, notification.Object, authentication.Object);
                    sut.Index(command);
                }

                using (var session = store.OpenSession())
                {
                    var john = session.Load<Member>(Member.FormatId("john.doe"));
                    var jane = session
                        .Include<Member>(x => x.Identifiers)
                        .Load<Member>(Member.FormatId("jane.doe"));
                    var identifiers = session.Load<Identifier>(jane.Identifiers).ToList();

                    var invitation = session.Load<Invitation>(Invitation.FormatId(token));

                    Assert.AreEqual(0, john.Invitations.Count);
                    Assert.AreEqual(2, identifiers.Count);
                    Assert.AreEqual(Invitation.Statuses.Accepted, invitation.Status);

                    notification.Verify(x => x.SendAcceptanceNotificationToGroup(It.IsAny<Member>()), Times.Once);
                    authentication.Verify(x => x.Login(Member.FormatId("jane.doe")), Times.Once);
                }
            }
        }