예제 #1
0
        public void Handle(RedeemEmailConfirmationCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            // get the confirmation
            var confirmation = _entities.Get <EmailConfirmation>()
                               .EagerLoad(_entities, new Expression <Func <EmailConfirmation, object> >[]
            {
                c => c.EmailAddress
            })
                               .ByToken(command.Token);

            // redeem
            if (!confirmation.RedeemedOnUtc.HasValue)
            {
                confirmation.EmailAddress.IsConfirmed = true;
                confirmation.RedeemedOnUtc            = DateTime.UtcNow;
                confirmation.Ticket = GenerateRandomSecretHandler.Handle(
                    new GenerateRandomSecretQuery(256));
                _entities.Update(confirmation);
            }

            command.Ticket = confirmation.Ticket;
        }
        public void Handle(SendConfirmEmailMessageCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            // get the person
            var person = _entities.Get <Person>()
                         .EagerLoad(_entities, new Expression <Func <Person, object> >[]
            {
                p => p.Emails,
            })
                         .ByEmail(command.EmailAddress);

            // get the email
            var email = person.GetEmail(command.EmailAddress);

            // create the confirmation
            var secretCode = GenerateRandomSecretHandler.Handle(
                new GenerateRandomSecretQuery(12));
            var confirmation = new EmailConfirmation(command.Intent)
            {
                EmailAddress = email,
                SecretCode   = secretCode,
            };

            command.ConfirmationToken = confirmation.Token;
            _entities.Create(confirmation);

            // get the email template
            var template = _queryProcessor.Execute(
                new GetEmailTemplateByNameQuery
            {
                Name = command.TemplateName.AsSentenceFragment(),
            }
                );

            // create the message
            var message = _queryProcessor.Execute(
                new ComposeEmailMessageQuery(template, email)
            {
                Formatters = _queryProcessor.Execute(
                    new GetConfirmEmailFormattersQuery(confirmation, command.SendFromUrl)
                    )
            }
                );

            _entities.Create(message);

            // send the message
            _sendHandler.Handle(
                new SendEmailMessageCommand
            {
                PersonId      = message.ToPerson.RevisionId,
                MessageNumber = message.Number,
            }
                );
        }
            public void GeneratesRandomSecret_OfExactLength()
            {
                const int length = 12;
                var       query  = new GenerateRandomSecretQuery(length);

                var result = GenerateRandomSecretHandler.Handle(query);

                result.ShouldNotBeNull();
                result.Length.ShouldEqual(length);
            }
            public void GeneratesRandomSecret_OfVariableLength()
            {
                const int minLength = 44;
                const int maxLength = 792;
                var       query     = new GenerateRandomSecretQuery(minLength, maxLength);

                var result = GenerateRandomSecretHandler.Handle(query);

                result.ShouldNotBeNull();
                result.Length.ShouldBeInRange(minLength, maxLength);
            }
            public void ThrowsArgumentNullException_WhenQueryArgIsNull()
            {
                ArgumentNullException exception = null;

                try
                {
                    GenerateRandomSecretHandler.Handle(null);
                }
                catch (ArgumentNullException ex)
                {
                    exception = ex;
                }

                exception.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                exception.ParamName.ShouldEqual("query");
                // ReSharper restore PossibleNullReferenceException
            }