コード例 #1
0
        public void TestUsingInterfaces()
        {
            var parent1 = new ParentWithInterface("Brian");
            var parent2 = new ParentWithInterfaceV2("Jeff");

            var theClient  = new ClassThatUsesObjectWithInterface(parent1);
            var theClient2 = new ClassThatUsesObjectWithInterface(parent2);

            Assert.AreEqual(theClient.parent.ReachTen(1), 10);
            Assert.AreEqual(theClient2.parent.ReachTen(1), 10);

            var a = theClient2.parent.name;

            string b = theClient.parent.name;

            theClient.parent.name = "Dan";

            Assert.AreEqual("Dan", theClient.parent.name);
            Assert.AreNotEqual("Dan", b);

            var dc = theClient;

            dc.parent.name = "Milo";
            Assert.AreEqual("Milo", theClient.parent.name);

            var marvel = theClient.parent;

            marvel.name = "Jake";

            Assert.AreEqual("Jake", marvel.name);
            Assert.AreEqual("Jake", dc.parent.name);
        }
コード例 #2
0
        public void TestUsingInterfaces()
        {
            var parent1 = new ParentWithInterface("Brian");
            var parent2 = new ParentWithInterfaceV2("Jeff");

            var theClient  = new ClassThatUsesObjectWithInterface(parent1);
            var theClient2 = new ClassThatUsesObjectWithInterface(parent2);

            Assert.AreEqual(theClient.parent.ReachTen(1), 10);
            Assert.AreEqual(theClient2.parent.ReachTen(1), 10);
        }