Exemplo n.º 1
0
        public void TestMethod1()
        {
            Person p1 = new Person("Fred Smith", 45);

            // check that constructor set the name correctly, and that it matches GetName
            Assert.AreEqual("Fred Smith", p1.GetName());
            // check that constructor sets the age correctly, and that it matches GetAge
            Assert.AreEqual(45, Convert.ToInt32(p1.GetAge()));

            // check that SetName sets the name correctly, and that it matches GetName
            p1.SetName("Mary Smith");
            Assert.AreEqual("Mary Smith", p1.GetName());

            // check that SetAge sets the age correctly, and that it matches GetAge
            p1.SetAge(67);
            Assert.AreEqual(67, Convert.ToInt32(p1.GetAge()));

            //Check that toString works
            Assert.AreEqual("Mary Smith is aged 67", p1.ToString());

            // Finally check that default constructor works
            p1 = new Person();
            Assert.AreEqual("", p1.GetName());
            Assert.AreEqual(0, Convert.ToInt32(p1.GetAge()));
        }