Пример #1
0
        public void DataAdapterReader_WhenGivenMockTypeShouldReturn_AdressBookWithMockValues()
        {
            //Arrange
            AddressBooks           addressBooks = new AddressBooks();
            AddressBookDataAdapter adapter      = new AddressBookDataAdapter();

            //Act
            adapter.Reader(AddressBookDataAdapter.OperationType.Mock, ref addressBooks);
            //Assert
            Assert.AreEqual("TestFirstName", addressBooks._multiAddressBooks["TestAddressBook"].AddressBook["TestContactName"].FirstName);
            Assert.AreEqual("TestLastName", addressBooks._multiAddressBooks["TestAddressBook"].AddressBook["TestContactName"].LastName);
        }
Пример #2
0
        public void DataAdapterReader_WhenGivenJsonTypeShouldReturn_AdressBookListWithValuesInJsonFile()
        {
            //Arrange
            AddressBooks           addressBooks = new AddressBooks();
            AddressBookDataAdapter adapter      = new AddressBookDataAdapter();

            //Act
            adapter.Reader(AddressBookDataAdapter.OperationType.JSON, ref addressBooks);
            //Assert
            Assert.AreEqual("Jyoti Ranjan", addressBooks._multiAddressBooks["General"].AddressBook["Jyoti RanjanMishra"].FirstName);
            Assert.AreEqual("Mishra", addressBooks._multiAddressBooks["General"].AddressBook["Jyoti RanjanMishra"].LastName);
        }
Пример #3
0
        /// <summary>
        /// Start AddressBook Program to perform various operations
        /// </summary>
        public static void Start()
        {
            AddressBooks addressBooksCollection = new AddressBooks();

            //FileReadingOperation(ref addressBooksCollection);
            //Task readingTask = new Task(() =>
            //{
            //    FileReadingOperation(ref addressBooksCollection);
            //});
            //readingTask.Start();
            //readingTask.Wait();

            AddressBookDataAdapter adapter = new AddressBookDataAdapter();

            adapter.Reader(AddressBookDataAdapter.OperationType.JSON, ref addressBooksCollection);

            addressBooksCollection.Name = "General";
            bool contAddressBook  = true;;
            bool contContactPanel = true;;

            do
            {
                Console.WriteLine("Enter\n" +
                                  "1 : To Add a new Address Book\n" +
                                  "2 : To use current address books ( " + addressBooksCollection.Name + " )\n" +
                                  "3 : Switch Address Book\n" +
                                  "4 : Search across all address books\n" +
                                  "0 : Exit");

                string userChoice = Console.ReadLine();
                if (userChoice != "0")
                {
                    contContactPanel = false;
                    AddressBookChoiceSwitch(ref addressBooksCollection, userChoice, ref contContactPanel);
                }
                else
                {
                    contAddressBook  = false;
                    contContactPanel = false;
                }
                while (contContactPanel)
                {
                    Console.WriteLine("Enter\n" +
                                      "1 : Add Contact Details to " + addressBooksCollection.Name + " Address Book\n" +
                                      "2 : Edit a Contact Detail\n" +
                                      "3 : Delete a Contact Detail\n" +
                                      "4 : Search across a state\n" +
                                      "5 : Sort persons\n" +
                                      "0 : Exit");

                    string choice = Console.ReadLine();
                    if (choice != "0")
                    {
                        AddressBookOperationSwitch(ref addressBooksCollection, choice);
                    }
                    else
                    {
                        contContactPanel = false;
                    }
                }
            } while (contAddressBook);

            //FileWritingOperation(addressBooksCollection);
            Task writingTask = new Task(() =>
            {
                FileWritingOperation(addressBooksCollection);
            });

            writingTask.Start();
            writingTask.Wait();
            Console.WriteLine("Saved changes to database");
        }