Exemplo n.º 1
0
        public void UpdateDetails(UpdateEmailAccountDetails cmd, IValidator <UpdateEmailAccountDetails> validator)
        {
            validator.ValidateCommand(cmd);

            Address            = cmd.Address;
            DisplayName        = cmd.DisplayName;
            Host               = cmd.Host;
            Port               = cmd.Port;
            UserName           = cmd.UserName;
            Password           = cmd.Password;
            DefaultCredentials = cmd.DefaultCredentials;
            Ssl = cmd.Ssl;

            AddEvent(new EmailAccountDetailsUpdated
            {
                SiteId             = SiteId,
                AggregateRootId    = Id,
                Address            = Address,
                DisplayName        = DisplayName,
                Host               = Host,
                Port               = Port,
                UserName           = UserName,
                Password           = Password,
                DefaultCredentials = DefaultCredentials,
                Ssl = Ssl
            });
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Update(UpdateEmailAccountDetails model)
        {
            model.SiteId = SiteId;
            await Task.Run(() => _commandSender.Send <UpdateEmailAccountDetails, EmailAccount>(model));

            return(new NoContentResult());
        }
        public void Should_validate_command_and_save_new_email_account()
        {
            var command = new UpdateEmailAccountDetails
            {
                SiteId             = Guid.NewGuid(),
                Id                 = Guid.NewGuid(),
                Address            = "*****@*****.**",
                DisplayName        = "My Site",
                Host               = "host",
                Port               = 25,
                UserName           = "******",
                Password           = "******",
                DefaultCredentials = true,
                Ssl                = false
            };

            var emailAccountRepositoryMock = new Mock <IEmailAccountRepository>();

            emailAccountRepositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns(new EmailAccounts.EmailAccount());
            emailAccountRepositoryMock.Setup(x => x.Update(It.IsAny <EmailAccounts.EmailAccount>()));

            var validatorMock = new Mock <IValidator <UpdateEmailAccountDetails> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var createEmailAccountHandler = new UpdateEmailAccountDetailsHandler(emailAccountRepositoryMock.Object, validatorMock.Object);

            createEmailAccountHandler.Handle(command);

            validatorMock.Verify(x => x.Validate(command));
            emailAccountRepositoryMock.Verify(x => x.Update(It.IsAny <EmailAccounts.EmailAccount>()));
        }
        public void Should_throw_validation_exception_when_validation_fails()
        {
            var command = new UpdateEmailAccountDetails
            {
                SiteId             = Guid.NewGuid(),
                Id                 = Guid.NewGuid(),
                Address            = "*****@*****.**",
                DisplayName        = "My Site",
                Host               = "host",
                Port               = 25,
                UserName           = "******",
                Password           = "******",
                DefaultCredentials = true,
                Ssl                = false
            };

            var emailAccountRepositoryMock = new Mock <IEmailAccountRepository>();

            emailAccountRepositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns(new EmailAccounts.EmailAccount());

            var validatorMock = new Mock <IValidator <UpdateEmailAccountDetails> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult(new List <ValidationFailure> {
                new ValidationFailure("Address", "Address Error")
            }));

            var createEmailAccountHandler = new UpdateEmailAccountDetailsHandler(emailAccountRepositoryMock.Object, validatorMock.Object);

            Assert.Throws <ValidationException>(() => createEmailAccountHandler.Handle(command));
        }
        public void Should_throw_exception_when_email_account_is_not_found()
        {
            var command = new UpdateEmailAccountDetails
            {
                SiteId             = Guid.NewGuid(),
                Id                 = Guid.NewGuid(),
                Address            = "*****@*****.**",
                DisplayName        = "My Site",
                Host               = "host",
                Port               = 25,
                UserName           = "******",
                Password           = "******",
                DefaultCredentials = true,
                Ssl                = false
            };

            var emailAccountRepositoryMock = new Mock <IEmailAccountRepository>();

            emailAccountRepositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns((EmailAccounts.EmailAccount)null);

            var validatorMock = new Mock <IValidator <UpdateEmailAccountDetails> >();

            var createEmailAccountHandler = new UpdateEmailAccountDetailsHandler(emailAccountRepositoryMock.Object, validatorMock.Object);

            Assert.Throws <Exception>(() => createEmailAccountHandler.Handle(command));
        }
 public void Setup()
 {
     _command = new UpdateEmailAccountDetails
     {
         SiteId             = Guid.NewGuid(),
         Id                 = Guid.NewGuid(),
         Address            = "*****@*****.**",
         DisplayName        = "My Site",
         Host               = "host",
         Port               = 25,
         UserName           = "******",
         Password           = "******",
         DefaultCredentials = true,
         Ssl                = true
     };
     _validatorMock = new Mock <IValidator <UpdateEmailAccountDetails> >();
     _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());
     _emailAccount = new EmailAccount();
     _emailAccount.UpdateDetails(_command, _validatorMock.Object);
     _event = _emailAccount.Events.OfType <EmailAccountDetailsUpdated>().SingleOrDefault();
 }
Exemplo n.º 7
0
 public IActionResult Update(UpdateEmailAccountDetails model)
 {
     model.SiteId = SiteId;
     _commandSender.Send <UpdateEmailAccountDetails, EmailAccount>(model);
     return(new NoContentResult());
 }
Exemplo n.º 8
0
 public IActionResult Update(UpdateEmailAccountDetails model)
 {
     model.SiteId = SiteId;
     _dispatcher.SendAndPublish <UpdateEmailAccountDetails, EmailAccount>(model);
     return(new NoContentResult());
 }