Пример #1
0
        public void GetTest()
        {
            InitAddressRecords();
            using (ConfigDatabase db = CreateConfigDatabase())
            {
                AddressManager mgr = CreateManager();

                //----------------------------------------------------------------------------------------------------
                //---get the full dictionary using the smtp domain name as the key and pick one to start at
                Dictionary <string, Address> mxsAll = mgr.ToDictionary(p => p.EmailAddress);

                Assert.Equal(MAXDOMAINCOUNT * MAXADDRESSCOUNT, mxsAll.Count);

                Address[] adds = mgr.Get(db, 1, string.Empty, MAXADDRESSCOUNT).ToArray();

                //----------------------------------------------------------------------------------------------------
                //---expected that the count of mxs will be  max count for a domain
                Assert.Equal(MAXADDRESSCOUNT, adds.Length);

                //----------------------------------------------------------------------------------------------------
                //---get the first item in the list to be used as the last item
                string val = adds[0].EmailAddress;
                adds = mgr.Get(db, 1, val, MAXADDRESSCOUNT).ToArray();

                //----------------------------------------------------------------------------------------------------
                //---expected that there should be MAXADDRESSCOUNT - 1 now
                Assert.Equal(MAXADDRESSCOUNT - 1, adds.Length);
            }
        }
Пример #2
0
        public void UpdateTest2()
        {
            InitAddressRecords();

            AddressManager        mgr       = CreateManager();
            IEnumerable <Address> addresses = mgr.Get(1, String.Empty, MAXADDRESSCOUNT);

            Assert.Equal(MAXADDRESSCOUNT, addresses.Count());
            const string testType = "testtype";

            foreach (Address add in addresses)
            {
                Assert.Equal(add.Status, EntityStatus.New);
                add.Status = EntityStatus.Enabled;
                add.Type   = testType;
            }
            mgr.Update(addresses);

            addresses = mgr.Get(1, String.Empty, MAXADDRESSCOUNT);
            foreach (Address add in addresses)
            {
                Assert.Equal(EntityStatus.Enabled, add.Status);
                Assert.Equal(testType, add.Type);
            }
        }
Пример #3
0
        public IActionResult Get(int id)
        {
            Address address = addressManager.Get(id);

            if (address == null)
            {
                return(NotFound("Address couldn't be found"));
            }
            return(Ok(address));
        }
Пример #4
0
        public void Get_AddressOrDomainTest()
        {
            InitAddressRecords();
            string addressType = "SMTP";

            DomainManager dMgr   = new DomainManager(CreateConfigStore());
            Domain        domain = new Domain("address1.domain1.com");

            domain.Status = EntityStatus.New;
            dMgr.Add(domain);
            domain        = new Domain("address2.domain2.com");
            domain.Status = EntityStatus.Enabled;
            dMgr.Add(domain);

            AddressManager mgr = CreateManager();

            string[] emailAddresses = new[] { "*****@*****.**", "*****@*****.**" };

            IEnumerable <Address> actual = mgr.Get(emailAddresses, EntityStatus.New);

            Assert.Equal(0, actual.Count());

            //
            // Now search with domainSearchEnabled = true
            //
            actual = mgr.Get(emailAddresses, true, EntityStatus.Enabled);
            Assert.Equal(0, actual.Count());

            actual = mgr.Get(emailAddresses, true, EntityStatus.New);
            Assert.Equal(emailAddresses.Length, actual.Count());


            for (int t = 0; t < actual.Count(); t++)
            {
                Assert.True(emailAddresses.Contains(actual.ToArray()[t].EmailAddress));
                Assert.Equal(EntityStatus.New, actual.ToArray()[t].Status);
                Assert.Equal(addressType, actual.ToArray()[t].Type);
            }

            emailAddresses = new[] { "*****@*****.**", "*****@*****.**" };
            actual         = mgr.Get(emailAddresses, true, EntityStatus.Enabled);
            Assert.Equal(emailAddresses.Length, actual.Count());

            //
            // domainSearchEnabled and no status.
            //
            actual = mgr.Get(emailAddresses, true);
            Assert.Equal(emailAddresses.Length, actual.Count());
            for (int t = 0; t < actual.Count(); t++)
            {
                Assert.True(emailAddresses.Contains(actual.ToArray()[t].EmailAddress));
                Assert.Equal(EntityStatus.Enabled, actual.ToArray()[t].Status);
                Assert.Equal(addressType, actual.ToArray()[t].Type);
            }
        }
Пример #5
0
        public void RemoveTest1()
        {
            InitAddressRecords();
            AddressManager mgr          = CreateManager();
            string         emailAddress = BuildEmailAddress(1, 1);

            mgr.Get(emailAddress);
            Assert.NotNull(emailAddress);
            mgr.Remove(emailAddress);
            Assert.Null(mgr.Get(emailAddress));
        }
Пример #6
0
        public void RemoveTest2()
        {
            InitAddressRecords();
            AddressManager mgr = CreateManager();

            string[] emailAddresses = new[] { BuildEmailAddress(1, 1), BuildEmailAddress(2, 1), BuildEmailAddress(3, 1) };
            Assert.Equal(emailAddresses.Length, mgr.Get(emailAddresses).Count());
            mgr.Remove(emailAddresses);
            Assert.Equal(0, mgr.Get(emailAddresses).Count());
            Assert.Equal(MAXADDRESSCOUNT * MAXDOMAINCOUNT - emailAddresses.Length, mgr.Count());
        }
Пример #7
0
        public void AddTest1()
        {
            //----------------------------------------------------------------------------------------------------
            //---only init the domain records which will force a cleaning of the address records
            InitDomainRecords();
            AddressManager mgr = CreateManager();

            //----------------------------------------------------------------------------------------------------
            //---make sure there are no mx records that exist
            Assert.Equal(0, mgr.Count());

            const long domainId    = 1;
            string     email       = BuildEmailAddress(1, 1);
            string     displayName = BuildEmailAddressDisplayName(1, 1);
            Address    addr        = new Address(domainId, email, displayName);

            using (CreateConfigDatabase())
            {
                mgr.Add(addr);
            }
            Assert.Equal(1, mgr.Count());
            addr = mgr.Get(email);
            Assert.Equal(domainId, addr.DomainID);
            Assert.Equal(email, addr.EmailAddress);
            Assert.Equal(displayName, addr.DisplayName);
            Assert.Equal(EntityStatus.New, addr.Status);
        }
Пример #8
0
        public void RemoveDomainTest()
        {
            InitAddressRecords();
            AddressManager mgr      = CreateManager();
            const long     domainID = 1;

            using (ConfigDatabase db = CreateConfigDatabase())
            {
                //----------------------------------------------------------------------------------------------------
                //---make sure that we have max addresses for the given domain
                Address[] adds = mgr.Get(db, domainID, string.Empty, MAXADDRESSCOUNT + 1).ToArray();
                Assert.Equal(MAXADDRESSCOUNT, adds.Count());

                mgr.RemoveDomain(db, domainID);
                adds = mgr.Get(db, domainID, string.Empty, MAXADDRESSCOUNT + 1).ToArray();
                Assert.Equal(0, adds.Count());
            }
        }
Пример #9
0
        public void GetTest10()
        {
            InitAddressRecords();
            AddressManager mgr          = CreateManager();
            string         emailAddress = BuildEmailAddress(1, 1);
            Address        add          = mgr.Get(emailAddress);

            Assert.Equal(emailAddress, add.EmailAddress);
        }
Пример #10
0
        public void UpdateTest1()
        {
            InitAddressRecords();

            AddressManager mgr = CreateManager();
            Address        add = mgr.Get(BuildEmailAddress(1, 1));

            Assert.NotNull(add);
            const string testType = "testtype";

            Assert.Equal(add.Status, EntityStatus.New);
            add.Status = EntityStatus.Enabled;
            add.Type   = testType;
            mgr.Update(add);

            add = mgr.Get(add.EmailAddress);
            Assert.Equal(EntityStatus.Enabled, add.Status);
            Assert.Equal(testType, add.Type);
        }
Пример #11
0
        public void GetTestLast3()
        {
            InitAddressRecords();
            AddressManager mgr = CreateManager();

            using (ConfigDatabase db = CreateConfigDatabase())
            {
                //----------------------------------------------------------------------------------------------------
                //---get the full dictionary using the smtp domain name as the key and pick one to start at
                Dictionary <string, Address> mxsAll = mgr.ToDictionary(p => p.EmailAddress);

                Assert.Equal(MAXDOMAINCOUNT * MAXADDRESSCOUNT, mxsAll.Count);

                //----------------------------------------------------------------------------------------------------
                //---grab the key at position 5 in the array, and use that as the "last" name to be passed in
                string val = mxsAll.Keys.ToArray()[4];

                Address[] adds = mgr.Get(db, val, MAXDOMAINCOUNT * MAXADDRESSCOUNT).ToArray();

                //----------------------------------------------------------------------------------------------------
                //---expected that the count of mxs will be  max count - 5
                Assert.Equal(MAXADDRESSCOUNT * MAXDOMAINCOUNT - 5, adds.Length);

                //----------------------------------------------------------------------------------------------------
                //---try one with a limited number less than max count
                adds = mgr.Get(val, 3);
                Assert.Equal(3, adds.Length);

                //----------------------------------------------------------------------------------------------------
                //---get the last item and see to ensure that no records are returned
                val  = mxsAll.Keys.ToArray().Last();
                adds = mgr.Get(val, MAXDOMAINCOUNT * MAXADDRESSCOUNT);
                Assert.Equal(0, adds.Length);

                //----------------------------------------------------------------------------------------------------
                //---get the first item and see to ensure that MAX - 1 records are returned
                val  = mxsAll.Keys.ToArray().First();
                adds = mgr.Get(val, MAXDOMAINCOUNT * MAXADDRESSCOUNT);
                Assert.Equal(MAXDOMAINCOUNT * MAXADDRESSCOUNT - 1, adds.Length);
            }
        }
Пример #12
0
        public void GetTest9()
        {
            InitAddressRecords();
            AddressManager mgr          = CreateManager();
            string         emailAddress = BuildEmailAddress(1, 1);

            using (ConfigDatabase db = CreateConfigDatabase())
            {
                Address add = mgr.Get(db, emailAddress);
                Assert.Equal(emailAddress, add.EmailAddress);
            }
        }
Пример #13
0
        public void Get_AddressAndDomainTest()
        {
            InitAddressRecords();
            string addressType = "SMTP";

            DomainManager dMgr   = new DomainManager(CreateConfigStore());
            Domain        domain = new Domain("address1.domain1.com");

            domain.Status = EntityStatus.New;
            dMgr.Add(domain);

            //
            // [email protected] aready exists
            //

            AddressManager mgr = CreateManager();

            string[] emailAddresses = new[] { "*****@*****.**", "*****@*****.**", "*****@*****.**" };

            IEnumerable <Address> actual = mgr.Get(emailAddresses, EntityStatus.New);

            Assert.Equal(1, actual.Count());

            //
            // Now search with domainSearchEnabled = true
            //
            actual = mgr.Get(emailAddresses, true, EntityStatus.Enabled);
            Assert.Equal(0, actual.Count());

            actual = mgr.Get(emailAddresses, true, EntityStatus.New);
            Assert.Equal(emailAddresses.Length, actual.Count());


            for (int t = 0; t < actual.Count(); t++)
            {
                Assert.True(emailAddresses.Any(e => e.Equals(actual.ToArray()[t].EmailAddress, StringComparison.OrdinalIgnoreCase)));
                Assert.Equal(EntityStatus.New, actual.ToArray()[t].Status);
                Assert.Equal(addressType, actual.ToArray()[t].Type);
            }
        }
Пример #14
0
        public void GetTest6()
        {
            InitAddressRecords();
            AddressManager mgr = CreateManager();

            long[] addressIDs            = new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            IEnumerable <Address> actual = mgr.Get(addressIDs);

            Assert.Equal(addressIDs.Length, actual.Count());
            for (int t = 0; t < addressIDs.Length; t++)
            {
                Assert.True(addressIDs.Contains(actual.ToArray()[t].ID));
            }
        }
Пример #15
0
        public void GetTest11()
        {
            InitAddressRecords();
            AddressManager mgr = CreateManager();

            string[] emailAddresses      = new[] { BuildEmailAddress(1, 1), BuildEmailAddress(2, 1), BuildEmailAddress(3, 1) };
            IEnumerable <Address> actual = mgr.Get(emailAddresses);

            Assert.Equal(emailAddresses.Length, actual.Count());

            for (int t = 0; t < actual.Count(); t++)
            {
                Assert.True(emailAddresses.Contains(actual.ToArray()[t].EmailAddress));
            }
        }
Пример #16
0
        public void AddTest()
        {
            InitDomainRecords();
            AddressManager mgr       = CreateManager();
            List <Address> addresses = new List <Address>();

            for (int i = 1; i <= MAXADDRESSCOUNT; i++)
            {
                addresses.Add(new Address(STARTID, BuildEmailAddress(STARTID, i)));
            }
            Assert.Equal(0, mgr.Count());
            mgr.Add(addresses);
            Assert.Equal(MAXADDRESSCOUNT, mgr.Count());
            Address[] aa = mgr.Get(string.Empty, MAXADDRESSCOUNT + 1).ToArray();
            Assert.Equal(MAXADDRESSCOUNT, aa.Length);
        }
Пример #17
0
        public void SetStatusTest1()
        {
            InitAddressRecords();
            AddressManager     mgr      = CreateManager();
            const long         domainID = STARTID;
            const EntityStatus status   = EntityStatus.Enabled;

            mgr.SetStatus(domainID, status);
            Address[] adds = mgr.Get(domainID, String.Empty, MAXADDRESSCOUNT);
            Assert.Equal(MAXADDRESSCOUNT, adds.Count());
            foreach (Address add in adds)
            {
                Assert.Equal(domainID, add.DomainID);
                Assert.Equal(status, add.Status);
            }
        }
Пример #18
0
        public void GetTest5()
        {
            InitAddressRecords();
            AddressManager mgr = CreateManager();

            using (ConfigDatabase db = CreateConfigDatabase())
            {
                long[] addressIDs            = new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                IEnumerable <Address> actual = mgr.Get(db, addressIDs, EntityStatus.New);
                Assert.Equal(addressIDs.Length, actual.Count());
                for (int t = 0; t < addressIDs.Length; t++)
                {
                    Assert.True(addressIDs.Contains(actual.ToArray()[t].ID));
                    Assert.Equal(EntityStatus.New, actual.ToArray()[t].Status);
                }
            }
        }
Пример #19
0
        public void GetTest8()
        {
            InitAddressRecords();
            AddressManager mgr = CreateManager();

            string[] emailAddresses = new[] { BuildEmailAddress(1, 1), BuildEmailAddress(2, 1), BuildEmailAddress(3, 1) };
            using (ConfigDatabase db = CreateConfigDatabase())
            {
                IEnumerable <Address> actual = mgr.Get(db, emailAddresses, EntityStatus.New);
                Assert.Equal(emailAddresses.Length, actual.Count());

                for (int t = 0; t < actual.Count(); t++)
                {
                    Assert.True(emailAddresses.Contains(actual.ToArray()[t].EmailAddress));
                    Assert.Equal(EntityStatus.New, actual.ToArray()[t].Status);
                }
            }
        }
Пример #20
0
        /// <summary>
        /// This method will clean, load and verify address records in the DB for testing purposes
        /// </summary>
        /// <param name="mgr">AddressManager instance used for controlling the Address records</param>
        /// <param name="db">ConfigDatabase instance used as the target storage mechanism for the records</param>
        /// <remarks>
        /// this approach goes out to db each time it is called, however it ensures that clean records
        /// are present for every test that is execute, if it is taking too long, simply cut down on the
        /// number of items using the consts above
        /// </remarks>
        protected void InitAddressRecords(AddressManager mgr
                                          , ConfigDatabase db)
        {
            //----------------------------------------------------------------------------------------------------
            //---init domain records as well we want them fresh too
            InitDomainRecords(new DomainManager(CreateConfigStore()), db);
            foreach (KeyValuePair <long, KeyValuePair <int, string> > kp in TestAddressNames)
            {
                //----------------------------------------------------------------------------------------------------
                //---create new address entry with the domain id (kp.key) and the address
                mgr.Add(db, new Address(kp.Key, kp.Value.Value, BuildEmailAddressDisplayName(kp.Key, kp.Value.Key))
                {
                    Type = "SMTP"
                });
            }

            //----------------------------------------------------------------------------------------------------
            //---submit changes to db and verify existence of records
            db.SubmitChanges();
            foreach (KeyValuePair <long, KeyValuePair <int, string> > kp in TestAddressNames)
            {
                Assert.NotNull(mgr.Get(kp.Value.Value));
            }
        }
        public AddressItem Get(string id)
        {
            var m = new AddressManager();

            return(m.Get(id));
        }
Пример #22
0
        public void Get_RoutedAddress()
        {
            InitAddressRecords();
            DomainManager dMgr   = new DomainManager(CreateConfigStore());
            Domain        domain = new Domain("address1.domain1.com");

            domain.Status = EntityStatus.Enabled;
            dMgr.Add(domain);

            string         addressType = "Undeliverable";
            AddressManager aMgr        = new AddressManager(CreateConfigStore());
            MailAddress    address     = new MailAddress("*****@*****.**");

            aMgr.Add(address, EntityStatus.Enabled, addressType);
            //
            // [email protected] aready exists
            //

            AddressManager mgr = CreateManager();

            string[] emailAddresses = new[] { "*****@*****.**" };

            IEnumerable <Address> actual = mgr.Get(emailAddresses, true, EntityStatus.Enabled);

            Assert.Equal(1, actual.Count());


            for (int t = 0; t < actual.Count(); t++)
            {
                Assert.True(emailAddresses.Any(e => e.Equals(actual.ToArray()[t].EmailAddress, StringComparison.OrdinalIgnoreCase)));
                Assert.Equal(EntityStatus.Enabled, actual.ToArray()[t].Status);
                Assert.Equal(addressType, actual.ToArray()[t].Type);
            }



            actual = mgr.Get(emailAddresses, EntityStatus.Enabled);
            Assert.Equal(1, actual.Count());


            for (int t = 0; t < actual.Count(); t++)
            {
                Assert.True(emailAddresses.Any(e => e.Equals(actual.ToArray()[t].EmailAddress, StringComparison.OrdinalIgnoreCase)));
                Assert.Equal(EntityStatus.Enabled, actual.ToArray()[t].Status);
                Assert.Equal(addressType, actual.ToArray()[t].Type);
            }



            actual = mgr.Get(emailAddresses, true);
            Assert.Equal(1, actual.Count());


            for (int t = 0; t < actual.Count(); t++)
            {
                Assert.True(emailAddresses.Any(e => e.Equals(actual.ToArray()[t].EmailAddress, StringComparison.OrdinalIgnoreCase)));
                Assert.Equal(EntityStatus.Enabled, actual.ToArray()[t].Status);
                Assert.Equal(addressType, actual.ToArray()[t].Type);
            }



            actual = mgr.Get(emailAddresses);
            Assert.Equal(1, actual.Count());


            for (int t = 0; t < actual.Count(); t++)
            {
                Assert.True(emailAddresses.Any(e => e.Equals(actual.ToArray()[t].EmailAddress, StringComparison.OrdinalIgnoreCase)));
                Assert.Equal(EntityStatus.Enabled, actual.ToArray()[t].Status);
                Assert.Equal(addressType, actual.ToArray()[t].Type);
            }
        }