public void ConcreteFluentBuilderSetsUpParamsCorrectly() { var tankFactory = new TankFactory(); var tank = tankFactory.Construct(new TigerTankBuilder()); Assert.AreEqual("Tiger I", tank.Name); }
static void TestFactoryOverBuilder(int iterations) { int n = iterations; Console.WriteLine("Test 'Factory Over Builder', " + n + " iterations..."); var watch = new Stopwatch(); double[] times = new double[2]; string[] methodNames = new string[2] { "Builder", "Abs. Factory" }; FactoryOverBuilder.FluentBuilder.MilitaryVehicles.Tanks.Tank tankFromBuilder; FactoryOverBuilder.AbstractFactory.MilitaryVehicles.Tanks.Tank tankFromFactory; //Builder var tankFactory = new TankFactory(); //var churchillTankBuilder = new ChurchillTankBuilder(); watch.Start(); for (int i = 0; i < n; i++) { tankFromBuilder = tankFactory.Construct(new ChurchillTankBuilder()); //or: //tankFromBuilder = tankFactory.Construct(churchillTankBuilder); //churchillTankBuilder.CreateNewTank(); //reset } watch.Stop(); times[0] = watch.ElapsedMilliseconds; watch.Reset(); //Abstract Factory watch.Start(); for (int i = 0; i < n; i++) { tankFromFactory = UKMilitaryVehicleFactory.Instance.CreateTank(1); } watch.Stop(); times[1] = watch.ElapsedMilliseconds; watch.Reset(); Console.WriteLine("Method: \t time"); for (int i = 0; i < times.Length; i++) { Console.WriteLine(methodNames[i] + ":\t " + times[i] + " ms"); } }