Example #1
0
 public IActionResult Save(CreateEmailAccount model)
 {
     model.SiteId = SiteId;
     model.Id     = Guid.NewGuid();
     _dispatcher.SendAndPublish <CreateEmailAccount, EmailAccount>(model);
     return(new NoContentResult());
 }
Example #2
0
        private EmailAccount(CreateEmailAccount cmd) : base(cmd.Id)
        {
            SiteId             = cmd.SiteId;
            Address            = cmd.Address;
            DisplayName        = cmd.DisplayName;
            Host               = cmd.Host;
            Port               = cmd.Port;
            UserName           = cmd.UserName;
            Password           = cmd.Password;
            DefaultCredentials = cmd.DefaultCredentials;
            Ssl    = cmd.Ssl;
            Status = EmailAccountStatus.Active;

            AddEvent(new EmailAccountCreated
            {
                SiteId             = SiteId,
                AggregateRootId    = Id,
                Address            = Address,
                DisplayName        = DisplayName,
                Host               = Host,
                Port               = Port,
                UserName           = UserName,
                Password           = Password,
                DefaultCredentials = DefaultCredentials,
                Ssl    = Ssl,
                Status = Status
            });
        }
Example #3
0
 public IActionResult Save(CreateEmailAccount model)
 {
     model.SiteId = SiteId;
     model.Id     = Guid.NewGuid();
     _commandSender.Send <CreateEmailAccount, EmailAccount>(model);
     return(new NoContentResult());
 }
Example #4
0
        public void Should_validate_command_and_save_new_email_account()
        {
            var command = new CreateEmailAccount
            {
                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.Create(It.IsAny <EmailAccount>()));

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

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

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

            createEmailAccountHandler.Handle(command);

            validatorMock.Verify(x => x.Validate(command));
            emailAccountRepositoryMock.Verify(x => x.Create(It.IsAny <EmailAccount>()));
        }
Example #5
0
        public void Should_throw_validation_exception_when_validation_fails()
        {
            var command = new CreateEmailAccount
            {
                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>();

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

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

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

            Assert.Throws <ValidationException>(() => createEmailAccountHandler.Handle(command));
        }
Example #6
0
        public void SetUp()
        {
            var createEmailAccountCommand = new CreateEmailAccount
            {
                SiteId             = Guid.NewGuid(),
                Id                 = Guid.NewGuid(),
                Address            = "*****@*****.**",
                DisplayName        = "My Site",
                Host               = "host",
                Port               = 25,
                UserName           = "******",
                Password           = "******",
                DefaultCredentials = true,
                Ssl                = true
            };
            var createEmailAccountValidatorMock = new Mock <IValidator <CreateEmailAccount> >();

            createEmailAccountValidatorMock.Setup(x => x.Validate(createEmailAccountCommand)).Returns(new ValidationResult());
            _emailAccount = EmailAccount.CreateNew(createEmailAccountCommand, createEmailAccountValidatorMock.Object);

            _command = new DeleteEmailAccount
            {
                SiteId = _emailAccount.SiteId,
                Id     = _emailAccount.Id
            };

            _validatorMock = new Mock <IValidator <DeleteEmailAccount> >();
            _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());

            _emailAccount.Delete(_command, _validatorMock.Object);

            _event = _emailAccount.Events.OfType <EmailAccountDeleted>().SingleOrDefault();
        }
Example #7
0
        public async Task <IActionResult> Save(CreateEmailAccount model)
        {
            model.SiteId = SiteId;
            model.Id     = Guid.NewGuid();
            await Task.Run(() => _commandSender.Send <CreateEmailAccount, EmailAccount>(model));

            return(new NoContentResult());
        }
Example #8
0
        public static EmailAccount EmailAccount(Guid siteId, Guid id, string address)
        {
            var command = new CreateEmailAccount
            {
                SiteId  = siteId,
                Id      = id,
                Address = address,
            };

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

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

            return(Domain.EmailAccounts.EmailAccount.CreateNew(command, validatorMock.Object));
        }
Example #9
0
 private EmailAccount(CreateEmailAccount cmd) : base(cmd.Id)
 {
     AddEvent(new EmailAccountCreated
     {
         SiteId             = cmd.SiteId,
         AggregateRootId    = Id,
         Address            = cmd.Address,
         DisplayName        = cmd.DisplayName,
         Host               = cmd.Host,
         Port               = cmd.Port,
         UserName           = cmd.UserName,
         Password           = cmd.Password,
         DefaultCredentials = cmd.DefaultCredentials,
         Ssl    = cmd.Ssl,
         Status = EmailAccountStatus.Active
     });
 }
        public IActionResult ProcessEmployee(int employeeid)
        {
            EmployeeManager manager = new EmployeeManager(employeeid);
            Invoker         invoker = new Invoker();
            ICommand        command = null;

            command = new CreateEmailAccount(manager);
            invoker.Commands.Add(command);
            command = new OrderVisitingCards(manager);
            invoker.Commands.Add(command);
            command = new PrepareIdentityCard(manager);
            invoker.Commands.Add(command);

            invoker.Execute();

            ViewBag.Message = $"Commands executed for employee #{employeeid}";
            return(View("Index", employeeid));
        }
Example #11
0
        public async Task <IActionResult> AddEmailAccount([FromBody] CreateEmailAccount command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (await _emailAccountService.ExistsByEmailAndUserIdAsync(UserId, command.Email))
            {
                ModelState.AddModelError("Email", "Email address is already taken.");
                return(BadRequest(ModelState));
            }
            try {
                await _emailAccountService.CreateAsync(UserId, command.Email, command.Password, command.ImapHost, command.ImapPort, command.SmtpHost, command.SmtpPort);

                return(StatusCode(201));
            } catch (Exception e) {
                return(BadRequest(e.Message));
            }
        }
Example #12
0
        public void SetUp()
        {
            _command = new CreateEmailAccount
            {
                SiteId             = Guid.NewGuid(),
                Id                 = Guid.NewGuid(),
                Address            = "*****@*****.**",
                DisplayName        = "My Site",
                Host               = "host",
                Port               = 25,
                UserName           = "******",
                Password           = "******",
                DefaultCredentials = true,
                Ssl                = true
            };

            _emailAccountRulesMock = new Mock <IEmailAccountRules>();
            _emailAccountRulesMock.Setup(x => x.IsEmailAccountIdUnique(_command.Id)).Returns(true);

            _siteRulesMock = new Mock <ISiteRules>();
            _siteRulesMock.Setup(x => x.DoesSiteExist(_command.SiteId)).Returns(true);

            _validator = new CreateEmailAccountValidator(_emailAccountRulesMock.Object, _siteRulesMock.Object);
        }
Example #13
0
        public static EmailAccount CreateNew(CreateEmailAccount cmd, IValidator <CreateEmailAccount> validator)
        {
            validator.ValidateCommand(cmd);

            return(new EmailAccount(cmd));
        }