예제 #1
0
        public virtual IEngine GetTurboEngine(int size)
        {
            IEngine e     = null;
            bool    found = turboEnginePool.TryGetValue(size, out e);

            if (!found)
            {
                e = new TurboEngine(size);
                turboEnginePool[size] = e;
            }
            return(e);
        }
        public void Test_VehicleNested_JsonWithCarTypeAndProperties_JsonWithTurbeEngineType_WithConverterAndWithDiscriminator()
        {
            JsonDiscriminatorConverter converter = new JsonDiscriminatorConverter(typeof(Vehicle), typeof(Engine));

            string json = "{\"type\": \"Car\", \"color\": \"red\", \"dateOfRegistration\": \"2016-04-09\", \"ndoors\": 5, \"engine\": {\"type\": \"Turbo\", \"power\": 100, \"acceleration\": 3.6}}";

            var vehicle = JsonConvert.DeserializeObject <Vehicle>(json, converter);

            vehicle.Should().BeOfType(typeof(Car));
            vehicle.Color.Should().BeEquivalentTo("red");
            vehicle.DateOfRegistration.Should().BeEquivalentTo("2016-04-09");
            ((Car)vehicle).NumberOfDoors.Should().Be(5);
            ((Car)vehicle).CarEngine.Should().NotBeNull();
            ((Car)vehicle).CarEngine.Should().BeOfType(typeof(TurboEngine));

            TurboEngine engine = (TurboEngine)((Car)vehicle).CarEngine;

            engine.Power.Should().Be(100m);
            engine.Acceleration = 3.6m;
        }
예제 #3
0
        static void Main(string[] args)
        {
            IEngine engine = new StandardEngine(1300);
            AbstractDriverControls controls = new StandardControls(engine);

            controls.IgnitionOn();
            controls.Accelerate();
            controls.Brake();
            controls.IgnitionOff();

            // Can use a different engine without changing the driver controls
            IEngine turbo = new TurboEngine(1300);

            controls = new SportControls(turbo);
            controls.IgnitionOn();
            controls.Accelerate();
            controls.Brake();
            controls.IgnitionOff();

            Console.Read();
        }
예제 #4
0
 public virtual IEngine GetTurboEngine(int size)
 {
     IEngine e = null;
     bool found = turboEnginePool.TryGetValue(size, out e);
     if (!found)
     {
         e = new TurboEngine(size);
         turboEnginePool[size] = e;
     }
     return e;
 }
예제 #5
0
 static void Main()
 {
     TurboEngine engine = new TurboEngine(30);
     Pickup van = new Pickup(engine);
     Console.WriteLine("engine: " + engine);
     Console.WriteLine("vehicle: " + van);
 }