예제 #1
0
        public void TestGetPhonebook()
        {
            phonebooksPhonebook phonebook = _fb.GetPhonebook("Telefonbuch");

            Assert.IsNotNull(phonebook);

            Console.WriteLine(phonebook.name);
            foreach (phonebooksPhonebookContact contact in phonebook.contact)
            {
                Console.WriteLine($"{contact.uniqueid}\t{contact.person[0].realName}\t{contact.telephony[0].number[0].Value}");
            }
        }
예제 #2
0
        private Dictionary <string, string> GetPhoneBook(string userName, string password)
        {
            Dictionary <string, string> book = new Dictionary <string, string>();

            Internals = new Dictionary <string, string>();

            FritzClient _fb = new FritzClient {
                UserName = userName, Password = password
            };

            phonebooksPhonebook phonebook = _fb.GetPhonebook("Telefonbuch");

            foreach (phonebooksPhonebookContact contact in phonebook.contact)
            {
                Log.Debug($"{contact.uniqueid}\t{contact.person[0].realName}\t{contact.telephony[0].number[0].Value}");

                foreach (phonebooksPhonebookContactTelephony phone in contact.telephony)
                {
                    foreach (phonebooksPhonebookContactTelephonyNumber number in phone.number)
                    {
                        string dial = Align(number.Value);
                        if (!string.IsNullOrEmpty(dial) &&
                            !book.ContainsKey(dial))
                        {
                            Log.Trace($"\t->{dial}");
                            book.Add(dial, contact.person[0].realName);
                        }
                        if (dial.StartsWith("**6"))
                        {
                            string homephone = dial.Substring(3);
                            if (!Internals.ContainsKey(homephone))
                            {
                                Log.Trace($"\t(internal)->{homephone}");
                                Internals.Add(homephone, contact.person[0].realName);
                            }
                        }
                    }
                }
            }
            return(book);
        }
예제 #3
0
        public void TestPhonebook()
        {
            // Create a name for the test phonebook.
            string testPhonebookName = $"Test Phonebook {Utility.GetTimestamp()}";



            // Create the test phonebook on the device.
            _fb.AddPhonebook(name: testPhonebookName);
            Assert.IsTrue(_fb.PhonebookExists(testPhonebookName));



            // Get the phonebook id.
            bool success = _fb.GetPhonebookId(name: testPhonebookName, out ushort testPhonebookId);

            Assert.IsTrue(success);
            Assert.IsTrue(testPhonebookId > 0);



            // Add an inital phonebook entry.
            string testPhonebookEntryUniqueId = _fb.AddPhonebookEntry(phonebookId: testPhonebookId,
                                                                      name: "Siciliani Salvatore",
                                                                      telephonyNumbers: new List <contactTelephonyNumber>()
            {
                new contactTelephonyNumber()
                {
                    Value = "+1 205 111 0010", type = NumberType.Home.ToString("G")
                },
                new contactTelephonyNumber()
                {
                    Value = "+1 205 111 0010", type = NumberType.Mobile.ToString("G")
                },
                new contactTelephonyNumber()
                {
                    Value = "+1 205 111 0010", type = NumberType.Work.ToString("G")
                },
                new contactTelephonyNumber()
                {
                    Value = "+1 205 111 0010", type = NumberType.Fax_Work.ToString("G")
                },
            },
                                                                      category: 0,
                                                                      email: "*****@*****.**");

            Assert.IsNotNull(testPhonebookEntryUniqueId);
            Assert.IsTrue(testPhonebookEntryUniqueId.Length > 0);



            // Add a second phonebook entry.
            testPhonebookEntryUniqueId = _fb.AddPhonebookEntry(phonebookId: testPhonebookId,
                                                               name: "Guzman Miguela",
                                                               telephonyNumbers: new List <contactTelephonyNumber>()
            {
                new contactTelephonyNumber()
                {
                    Value = "+1 205 222 0011", type = NumberType.Home.ToString("G")
                },
                new contactTelephonyNumber()
                {
                    Value = "+1 205 222 0012", type = NumberType.Mobile.ToString("G")
                },
                new contactTelephonyNumber()
                {
                    Value = "+1 205 222 0013", type = NumberType.Work.ToString("G")
                },
                new contactTelephonyNumber()
                {
                    Value = "+1 205 222 0014", type = NumberType.Fax_Work.ToString("G")
                },
            },
                                                               category: 0,
                                                               email: "*****@*****.**");
            Assert.IsNotNull(testPhonebookEntryUniqueId);
            Assert.IsTrue(testPhonebookEntryUniqueId.Length > 0);



            // Get the phonebook entry by uid.
            contact result = _fb.GetPhonebookEntryUID(phonebookId: testPhonebookId, entryUniqueId: testPhonebookEntryUniqueId);

            Assert.IsNotNull(result);

            string name = result.person.realName;

            Assert.IsTrue(name.Length > 0);

            string email = result.services.email?.Value ?? string.Empty;

            Assert.AreEqual(expected: "*****@*****.**", actual: email);



            // Update phonebook entry.
            _fb.UpdatePhonebookEntry(phonebookId: testPhonebookId,
                                     uniqueId: testPhonebookEntryUniqueId,
                                     name: "Guzman E. Miguela",
                                     telephonyNumbers: new List <contactTelephonyNumber>()
            {
                new contactTelephonyNumber()
                {
                    Value = "+1 205 222 0021", type = NumberType.Home.ToString("G")
                },
                new contactTelephonyNumber()
                {
                    Value = "+1 205 222 0022", type = NumberType.Mobile.ToString("G")
                },
                new contactTelephonyNumber()
                {
                    Value = "+1 205 222 0023", type = NumberType.Work.ToString("G")
                },
                new contactTelephonyNumber()
                {
                    Value = "+1 205 222 0024", type = NumberType.Fax_Work.ToString("G")
                },
            },
                                     category: 0,
                                     email: "*****@*****.**"
                                     );



            // Delete phonebook entry.
            _fb.DeletePhonebookEntryUID(phonebookId: testPhonebookId, uniqueId: testPhonebookEntryUniqueId);



            // Write the phonebook to console.
            var phonebook = _fb.GetPhonebook(name: testPhonebookName);

            Assert.IsNotNull(phonebook);
            Assert.IsTrue(phonebook.contact.Count() > 0);

            foreach (var contact in phonebook.contact)
            {
                email = (contact.telephony[0].services != null && contact.telephony[0].services.Count() > 0)
                    ? contact.telephony[0].services[0].Value
                    : string.Empty;

                Console.WriteLine($"{contact.uniqueid}\t{contact.person[0].realName}\t{contact.telephony[0].number[0].Value}\t{email}");
            }



            // Backup the test phonebook as csv file.
            // Note: In VS, the deployment directories created for running tests are deleted after each test run.
            // If the test fails, these directories are retained for easier analysis. You can override this behavior
            // with the DeleteDeploymentDirectoryAfterTestRunIsComplete setting.See http://msdn.microsoft.com/en-us/library/jj635153.aspx
            _fb.WritePhonebookCsv(name: testPhonebookName, folder: TestContext.TestDeploymentDir);



            // Backup the test phonebook as xml file.
            _fb.WritePhonebookXml(name: testPhonebookName, folder: TestContext.TestDeploymentDir);



            // Remove the test phonebook from the device.
            _fb.DeletePhonebook(name: testPhonebookName);
        }