Beispiel #1
0
        static void PlayWithContacts()
        {
            var ch = new ContactHelper <Person>();

            ch.Add(new Person("Betty", "White"));
            ch.Add(new Person("Crocker", "Davis"));
            ch.Add(new Person("Horace", "Slughorn"));

            var alfred = new Person("Alfred", "the Great", "777", "345-3455");

            ch.Add(alfred);

            foreach (var item in ch.Read())
            {
                Console.WriteLine(item);
            }
            // ch.WriteToText();
            ch.WriteToXml();
            Person p = ch.ReadFromXml() as Person;

            ch.Add(p);
            ch.WriteToText();
            ch.Clear();

            Console.WriteLine("\n\n");
            ch.PlayWithDelegates();
        }
Beispiel #2
0
        static void PlayWithContact()  //PlayWithContact static because Main is static so it must exist when Main runs
        {
            var ch = new ContactHelper <Person>();

            ch.Add(new Person());

            // Console.WriteLine("\nEntering a new person:");
            // Person p = Person.EnterPersonInfo();
            // ch.Add(p);

            Company c = new Company("Revature");

            ch.Add(c);

            Console.WriteLine("\nEnter a new Company name: ");
            string name = Console.ReadLine();
            var    cc   = new Company(name);

            ch.Add(cc);

            Console.WriteLine("\n\nPrinting out all Persons.");
            foreach (var item in ch.Read())  // Iterates to completion, some people call it the "exhaustive loop"
            {
                System.Console.WriteLine(item);
            }
            Console.WriteLine("\n\n");
            ch.WriteToText();
            ch.WriteToXml();

            Person p3 = ch.ReadPersonFromTxt();

            Console.WriteLine(p3);

            Person p4 = ch.ReadFromXml();

            Console.WriteLine(p4);

            //Person p2 = Person.ReadPersonFromTxt();

            Console.WriteLine("Before Delete: {0}", ch.Size());
            ch.Delete();
            Console.WriteLine("After Delete: {0}", ch.Size());



            // for (int a = 0; a < length; a += 1)   // For each is pretty much same as for
            // {
            //     list[a];
            // }
            // for (;;)  //can
            // {
            // }
            // while(true)
            // {
            // }
        }
Beispiel #3
0
        public void Test_ContactHelper_Add()
        {
            //arrange
            var ch = new ContactHelper <Person>();

            //act
            var actual = ch.Add(new Person());

            //assert
            Assert.True(actual);
        }
Beispiel #4
0
        // [Theory] // Theory Means you expect it to happen
        // [InlineData(typeof(Person))]  // Theory means you use some extra InlineData
        public void Test_ContactHelper_AddPerson()
        {
            var ch       = new ContactHelper <Person>();
            var expected = new Name();

            ch.Add(p);                     // creates an instant of a person
            var actual = ch.Read().Last(); // Need System.Linq to get Last()

            Assert.True(expected.First == actual.Name.First);
            Assert.True(expected.Last == actual.Name.Last);
        }
Beispiel #5
0
        public void Test_ContactHelper_Add_Negative()
        {
            //arrange
            var ch = new ContactHelper <Person>();

            //act
            var added  = ch.Add(new Person());
            var actual = ch.Read();  //Testing Read and Add technically

            //Assert
            Assert.False(!added);
        }
Beispiel #6
0
        public void Test_ContactHelper_AddPerson()
        {
            var p           = new Person();
            var defaultName = new Name();

            var ch = new ContactHelper <Person>();

            ch.Add(p);

            var lastPerson = ch.Read().Last();

            Assert.True(defaultName.First == lastPerson.Name.First);
            Assert.True(defaultName.Last == lastPerson.Name.Last);
        }