public void Test() { sample.Name = "A"; IPrototype image = sample.Clone(); Assert.AreEqual <string>("A", image.Name); // 副本与样本当时的内容一致 Assert.AreEqual <Type>(typeof(ConcretePrototype), image.GetType()); //具体类型 image.Name = "B"; // 独立修改副本的内容 Assert.IsTrue(sample.Name != image.Name); // 证明是两个独立的个体 }
public void TestPrototype(IPrototype testedPrototype, string expectedToString) { Assert.Equal(expectedToString, testedPrototype.ToString()); var clone = testedPrototype.Copy(); Assert.NotNull(clone); Assert.NotSame(clone, testedPrototype); Assert.Same(testedPrototype.GetType(), clone.GetType()); Assert.Equal(clone, testedPrototype); }