public void FactoryB_Test() { var client = new Client(new FactoryB()); var item = client.Item; IItem item2 = client.Item; Assert.AreEqual(item.Do(), "B"); Assert.AreEqual(item2.Do(), "B"); Assert.AreEqual(item, item2); }
public void MultipleFactory_Test() { foreach (var i in new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }) { IFactory factory; if (i % 2 == 0) factory = new FactoryA(); else factory = new FactoryB(); var client = new Client(factory); Assert.AreEqual(client.Item.Do(), (i % 2 == 0) ? "A" : "B"); } }