public ActionResult Index(InviteCommand command)
        {
            //TODO: validate
            try
            {
                var loggedInMember = _members.FindLoggedInMember();

                var invite = new Invitation();
                invite.FullName = command.FullName;
                invite.Email = command.Email;
                invite.LinkedIn = command.LinkedIn;
                invite.GitHub = command.GitHub;
                invite.Testimonial = command.Testimonial;
                invite.VouchedBy = loggedInMember.Id;

                _session.Store(invite);

                loggedInMember.AddInvitation(invite.Id);

                _session.SaveChanges();

                //TODO: publish event
                _email.SendInvitationToGroup(invite, loggedInMember.UserName);
                invite.Pending();
             				_session.SaveChanges(); //in the short run, this will give us a heads up if the mandril send is failing

                return RedirectToAction("Ok");
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "error");
                return View(command);
            }
        }
Example #2
0
        public void WehnPendingIsCalledStatusIsSetToPending()
        {
            var sut = new Invitation();

            sut.Pending();

            Assert.AreEqual(Invitation.Statuses.Pending, sut.Status);
        }
Example #3
0
        public void CannotSetToPendingTwice()
        {
            var sut = new Invitation();

            sut.Pending();

            Assert.Throws<ApplicationException>(sut.Pending, "pending twice");
        }
Example #4
0
        public void WhenAcceptIsCalledStatusIsSetToAccepted()
        {
            var sut = new Invitation();

            sut.Pending();
            sut.Accept();

            Assert.AreEqual(Invitation.Statuses.Accepted, sut.Status);
        }
 public void SendInvitationToGroup(Invitation invitation, string vouched)
 {
     var api = new MandrillApi(_configuration.MadrillApiKey);
     var result = api.SendMessage(
         new EmailMessage()
         {
             to =
                 new List<EmailAddress>()
                 {
                     new EmailAddress {email = _configuration.MadrillOriginTarget}
                 },
             subject = invitation.FullName
         },
         "devlink-submit-invitation",
         new List<TemplateContent>()
         {
             new TemplateContent() {name = "candidate", content = invitation.FullName},
             new TemplateContent() {name = "linkedin", content = invitation.LinkedIn},
             new TemplateContent() {name = "github", content = invitation.GitHub},
             new TemplateContent() {name = "vouchedby", content = vouched},
             new TemplateContent() {name = "testimonal", content = invitation.Testimonial}
         });
 }
        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 = "john.doe";
                    session.Store(member);

                    var invitation = new Invitation
                    {
                        FullName = "jane.doe",
                        Email = "[email protected]",
                        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 = "a password",
                        Token = token,
                        UserName = "jane.doe"
                    };

                    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);
                }
            }
        }