コード例 #1
0
        public void TestAnonymousType()
        {
            Person fred = new Person("Fred", "Flintstone");

            var bob = new { Name = "Bob", Job = new { Role = "Butler" }, Friend = fred };
            Assert.AreEqual("Bob", bob.Name);
            Assert.AreEqual("Butler", bob.Job.Role);
            Assert.AreEqual("Flintstone", bob.Friend.LastName);

            bob.Friend.addNicknames("Freddy", "Fred the Rockman");

            Assert.AreEqual(2, bob.Friend.Nicknames.Count);
            Assert.IsTrue(fred.Nicknames.Contains("Freddy"));
        }
コード例 #2
0
        public void TestName()
        {
            Person joe = new Person("Joe", "Smith");
            Assert.AreEqual("Joe", joe.FirstName);
            Assert.AreEqual("Smith", joe.LastName);

            Person backwards = new Person(lastName: "htimS", firstName: "eoJ");
            Assert.AreEqual("eoJ", backwards.FirstName);
            Assert.AreEqual("htimS", backwards.LastName);

            Person nobody = new Person();
            Assert.AreEqual("John", nobody.FirstName);
            Assert.AreEqual("Doe", nobody.LastName);

            Person nfn = new Person(lastName: "Smith");
            Assert.AreEqual("John", nfn.FirstName);
            Assert.AreEqual("Smith", nfn.LastName);

            // nfn.FirstName = "Ted";  compiler error because setters are private
        }
コード例 #3
0
 public void TestNicknames()
 {
     Person charles = new Person(firstName: "Charles", lastName: "Winchester");
     Assert.AreEqual(0, charles.Nicknames.Count);
 }