public void CameryNeedsToTurnKey() { Camry camry = new Camry(); string actual = camry.UseKey(); Assert.Equal("Turns key.", actual); }
public void CamryCanBeFilledWith15GallonsOfGas() { Camry camry = new Camry(); int expected = camry.FillWithGas(); Assert.Equal(15, expected); }
public void CamryCanCostLess() { Camry camry = new Camry { Cost = 10000 }; Assert.Equal(10000, camry.Cost); }
public void CamryCanHave2Wheels() { Camry camry = new Camry { NumberOfWheels = 2 }; Assert.Equal(2, camry.NumberOfWheels); }
public void CamryCanHave2Doors() { Camry camry = new Camry { NumberOfDoors = 2 }; Assert.Equal(2, camry.NumberOfDoors); }
public void CamryIsBroken() { Camry camry = new Camry { SelfPropelled = false }; Assert.False(camry.SelfPropelled); }
public void CamryHasBrokenHorn() { Camry camry = new Camry { HasHorn = false }; Assert.False(camry.HasHorn); }
static void Main(string[] args) { Turcell turcell = new Turcell(); Camry camry = new Camry(); BRZ brz = new BRZ(); MountainBike mountainBike = new MountainBike(); Motorcycle motorcycle = new Motorcycle(); Console.WriteLine($"Class: {turcell}. Inherited Number of Wheels: {turcell.NumberOfWheels}\n" + ""); Console.WriteLine($"Class: {camry}. Inherited Number of Doors: {camry.NumberOfDoors}\n" + ""); Console.WriteLine($"Class: {brz}. Inherited Backseat Space: {brz.BackseatSpace}\n" + ""); Console.WriteLine($"Class: {motorcycle}. Inherited Number of Wheels: {motorcycle.NumberOfWheels}\n" + ""); Console.WriteLine($"Class: {mountainBike}. Inherited Self-Propelled: {mountainBike.SelfPropelled}\n" + ""); }
public static IToyota CreateInstance(ToyotaType toyotaType) { IToyota toyota; switch (toyotaType) { case ToyotaType.Alphard: toyota = new Alphard(); break; case ToyotaType.Camry: toyota = new Camry(); break; case ToyotaType.Corolla: toyota = new Corolla(); break; default: throw new Exception("IToyota CreateInstance error..."); } return(toyota); }
public static IToyota CreateInstanceConfig() { ToyotaType toyotaType = (ToyotaType)Enum.Parse(typeof(ToyotaType), ToyotaTypeConfig);//字符串转枚举 IToyota toyota; switch (toyotaType) { case ToyotaType.Alphard: toyota = new Alphard(); break; case ToyotaType.Camry: toyota = new Camry(); break; case ToyotaType.Corolla: toyota = new Corolla(); break; default: throw new Exception("IToyota CreateInstance error..."); } return(toyota); }
public void DriveCamry(Camry car) { Console.WriteLine($"{this.Name} driving..."); car.Drive(); }
static void Main(string[] args) { try { Player Player = new Player() { Name = "菜虚鲲" }; { //面向细节,依赖细节 Alphard Alphard = new Alphard(); Camry Camry = new Camry(); Corolla Corolla = new Corolla(); Player.DriveAlphard(Alphard); Player.DriveCamry(Camry); Player.DriveCorolla(Corolla); Console.WriteLine("*******************面向细节,依赖细节,上层使用者自行实例化下层对象并使用********************"); Console.WriteLine(); } { //面向接口,依赖细节 IToyota Alphard = new Alphard(); IToyota Camry = new Camry(); IToyota Corolla = new Corolla(); Player.DriveToyota(Alphard); Player.DriveToyota(Camry); Player.DriveToyota(Corolla); Console.WriteLine("*******************面向接口,依赖细节,上层使用者自行实例化下层对象并使用********************"); Console.WriteLine(); } { //面向接口,依赖工厂;使用枚举参数做对象选择条件 IToyota Alphard = ToyotaFactory.CreateInstance(ToyotaFactory.ToyotaType.Alphard); IToyota Camry = ToyotaFactory.CreateInstance(ToyotaFactory.ToyotaType.Camry); IToyota Corolla = ToyotaFactory.CreateInstance(ToyotaFactory.ToyotaType.Corolla); Player.DriveToyota(Alphard); Player.DriveToyota(Camry); Player.DriveToyota(Corolla); Console.WriteLine("*******************面向接口,依赖工厂;使用枚举参数做对象选择条件,上层使用者不需要自行实例化下层对象,只需要按需从工厂类拿对象********************"); Console.WriteLine(); } { //面向接口,依赖工厂;使用配置做对象选择条件 IToyota car = ToyotaFactory.CreateInstanceConfig(); Player.DriveToyota(car); Console.WriteLine("*******************面向接口,依赖工厂;使用配置做对象选择条件,上层使用者不需要自行实例化下层对象,只需要按需从工厂类拿对象********************"); Console.WriteLine(); } { //面向接口,依赖工厂;使用配置+反射(方便扩展)做对象选择条件 IToyota car = ToyotaFactory.CreateInstanceConfigReflection(); Player.DriveToyota(car); Console.WriteLine("*******************面向接口,依赖工厂;使用配置+反射(方便扩展)做对象选择条件,上层使用者不需要自行实例化下层对象,只需要按需从工厂类拿对象********************"); Console.WriteLine(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.Read(); }
public void CamryHas4Doors() { Camry camry = new Camry(); Assert.Equal(4, camry.NumberOfDoors); }
public override IAutomobile CreateVehicle() { Camry allNewCamry = new Camry(140, "Toyota"); return(allNewCamry); }
public void CamryHas4Wheels() { Camry camry = new Camry(); Assert.Equal(4, camry.NumberOfWheels); }
public void CamryHasCorrectCost() { Camry camry = new Camry(); Assert.Equal(15000, camry.Cost); }
public void CamryHasHorn() { Camry camry = new Camry(); Assert.True(camry.HasHorn); }
public void CamryIsSelfPropelled() { Camry camry = new Camry(); Assert.True(camry.SelfPropelled); }