Ejemplo n.º 1
0
        public MockServer(ServerSetup setup)
            : base(setup)
        {
            _serverData = MockServerData.GetInstance();

            _serverData.Domains.Clear();
            _serverData.Mailboxes.Clear();
            _serverData.Groups.Clear();

            _domainDal      = new WebDomainDal(setup.Tenant);
            _mailboxDal     = new MailboxDal(setup.Tenant, SetupInfo.Limits.MailboxMaxCountPerUser);
            _mailgroupDal   = new MailGroupDal(setup.Tenant);
            _mailaddressDal = new MailAddressDal(setup.Tenant);

            var domains = _domainDal.GetTenantDomains();

            foreach (var domain in domains)
            {
                _serverData.Domains.Add(new WebDomainBase(domain.name));
            }

            var mailboxes_dto = _mailboxDal.GetMailboxes();

            foreach (var mailbox_dto in mailboxes_dto)
            {
                var alias_list =
                    _mailaddressDal.GetMailboxAliases(mailbox_dto.mailbox.id)
                    .Select(
                        alias_dto =>
                        new MailAddressBase(alias_dto.name, new WebDomainBase(alias_dto.domain.name)))
                    .ToList();

                var result_mailbox = new MailboxBase(
                    new MailAccountBase(mailbox_dto.mailbox.address),
                    //Its not login. It adress. Needed only for testing
                    new MailAddressBase(mailbox_dto.mailbox_address.name,
                                        new WebDomainBase(mailbox_dto.mailbox_address.domain.name)), alias_list);

                _serverData.Mailboxes.Add(result_mailbox);
            }

            var groups_dto = _mailgroupDal.GetMailGroups();

            foreach (var group_dto in groups_dto)
            {
                var group_addresses = group_dto.addresses.Select(address =>
                                                                 new MailAddressBase(address.name,
                                                                                     new WebDomainBase(
                                                                                         address.domain.name))).ToList();

                var result_group = new MailGroupBase(
                    new MailAddressBase(group_dto.address.name,
                                        new WebDomainBase(group_dto.address.domain.name)), group_addresses);

                _serverData.Groups.Add(result_group);
            }
        }
Ejemplo n.º 2
0
        protected override MailGroupBase _CreateMailGroup(MailAddressBase address, List <MailAddressBase> mailboxAddressList)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address", "MockServer::_CreateMailGroup");
            }

            if (_serverData.Groups.Any(r => r.Address.ToString().Equals(address.ToString())))
            {
                throw new ArgumentException();
            }

            var resultGroup = new MailGroupBase(address, mailboxAddressList);

            _serverData.Groups.Add(resultGroup);
            return(resultGroup);
        }
Ejemplo n.º 3
0
        protected override MailGroupBase _DeleteMailGroup(MailGroupBase mail_group)
        {
            var mailgroup_delete_query = new SqlDelete(AliasTable.name)
                                         .Where(AliasTable.Columns.address, mail_group.Address.ToString());
            var rows_deleted = 0;

            using (var db = _dbManager.GetAdminDb())
            {
                rows_deleted = db.ExecuteNonQuery(mailgroup_delete_query);
                if (rows_deleted > 1)
                {
                    var m = String.Format("Invalid addresses count was deleted: {0}. Address: {1}", rows_deleted, mail_group.Address);
                    throw new InvalidOperationException(m);
                }
            }
            return(rows_deleted == 0 ? null: mail_group);
        }
Ejemplo n.º 4
0
 protected abstract MailGroupBase _DeleteMailGroup(MailGroupBase mailGroup);
Ejemplo n.º 5
0
        public override IMailGroup CreateMailGroup(string groupName, IWebDomain domain, List <int> addressIds, IMailServerFactory factory)
        {
            if (string.IsNullOrEmpty(groupName))
            {
                throw new ArgumentNullException("groupName", "ServerModel::CreateMailGroup");
            }

            if (domain == null)
            {
                throw new ArgumentNullException("domain");
            }

            if (addressIds == null)
            {
                throw new ArgumentNullException("addressIds");
            }

            if (!addressIds.Any())
            {
                throw new ArgumentException("Empty address_ids list");
            }

            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            MailGroupDto mailgroupDto;

            using (var dbContextWithTran = TeamlabMailGroupDal.CreateMailDbContext(true))
            {
                var addressDtoList = TeamlabMailAddressDal.GetMailAddresses(addressIds, dbContextWithTran.DbManager);

                var addressBaseList =
                    addressDtoList
                    .Select(dto =>
                            new MailAddressBase(dto.name,
                                                new WebDomainBase(dto.domain.name)))
                    .ToList();

                var mailgroupBase = new MailGroupBase(new MailAddressBase(groupName, new WebDomainBase(domain)),
                                                      addressBaseList)
                {
                    Address = { DateCreated = DateTime.UtcNow }
                };

                mailgroupDto = TeamlabMailGroupDal.SaveMailGroup(mailgroupBase.Address.LocalPart,
                                                                 mailgroupBase.Address.DateCreated,
                                                                 domain.Id,
                                                                 domain.Name,
                                                                 domain.IsVerified,
                                                                 addressDtoList, dbContextWithTran.DbManager);
                _CreateMailGroup(mailgroupBase.Address, addressBaseList);

                dbContextWithTran.CommitTransaction();
            }

            var mailgroupAddress = factory.CreateMailAddress(mailgroupDto.address.id, mailgroupDto.address.tenant, mailgroupDto.address.name, domain);

            var inAddresses =
                mailgroupDto.addresses.Select(
                    addressDto => factory.CreateMailAddress(addressDto.id, addressDto.tenant, addressDto.name, domain))
                .ToList();

            var mailgroup = factory.CreateMailGroup(mailgroupDto.id, mailgroupDto.id_tenant,
                                                    mailgroupAddress, inAddresses.ToList(), this);

            return(mailgroup);
        }
Ejemplo n.º 6
0
 protected override MailGroupBase _DeleteMailGroup(MailGroupBase mailGroup)
 {
     _serverData.Groups.Remove(mailGroup);
     return(mailGroup);
 }