コード例 #1
0
        public void CameryNeedsToTurnKey()
        {
            Camry camry = new Camry();

            string actual = camry.UseKey();

            Assert.Equal("Turns key.", actual);
        }
コード例 #2
0
        public void CamryCanBeFilledWith15GallonsOfGas()
        {
            Camry camry = new Camry();

            int expected = camry.FillWithGas();

            Assert.Equal(15, expected);
        }
コード例 #3
0
        public void CamryCanCostLess()
        {
            Camry camry = new Camry
            {
                Cost = 10000
            };

            Assert.Equal(10000, camry.Cost);
        }
コード例 #4
0
        public void CamryCanHave2Wheels()
        {
            Camry camry = new Camry
            {
                NumberOfWheels = 2
            };

            Assert.Equal(2, camry.NumberOfWheels);
        }
コード例 #5
0
        public void CamryCanHave2Doors()
        {
            Camry camry = new Camry
            {
                NumberOfDoors = 2
            };

            Assert.Equal(2, camry.NumberOfDoors);
        }
コード例 #6
0
        public void CamryIsBroken()
        {
            Camry camry = new Camry
            {
                SelfPropelled = false
            };

            Assert.False(camry.SelfPropelled);
        }
コード例 #7
0
        public void CamryHasBrokenHorn()
        {
            Camry camry = new Camry
            {
                HasHorn = false
            };

            Assert.False(camry.HasHorn);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: ARoska/DotNetMotors
        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" +
                              "");
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
 public void DriveCamry(Camry car)
 {
     Console.WriteLine($"{this.Name} driving...");
     car.Drive();
 }
コード例 #12
0
        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();
        }
コード例 #13
0
        public void CamryHas4Doors()
        {
            Camry camry = new Camry();

            Assert.Equal(4, camry.NumberOfDoors);
        }
コード例 #14
0
        public override IAutomobile CreateVehicle()
        {
            Camry allNewCamry = new Camry(140, "Toyota");

            return(allNewCamry);
        }
コード例 #15
0
        public void CamryHas4Wheels()
        {
            Camry camry = new Camry();

            Assert.Equal(4, camry.NumberOfWheels);
        }
コード例 #16
0
        public void CamryHasCorrectCost()
        {
            Camry camry = new Camry();

            Assert.Equal(15000, camry.Cost);
        }
コード例 #17
0
        public void CamryHasHorn()
        {
            Camry camry = new Camry();

            Assert.True(camry.HasHorn);
        }
コード例 #18
0
        public void CamryIsSelfPropelled()
        {
            Camry camry = new Camry();

            Assert.True(camry.SelfPropelled);
        }