static void Main(string[] args) { SimulateDuck(new MallardDuck()); SimulateDuck(new RedHeadDuck()); SimulateDuck(new RubberDuck()); SimulateDuck(new DecoyDuck()); SimulateDuck(new ModelDuck()); Duck duck = new MallardDuck(); duck.Fly(); duck.Fly(); duck.SetFlight(FlyBehaviour.FlyWithWings()); duck.Fly(); }
public void Duck_Behaviors_CanChangeBehaviorAtRuntime() { Duck mallard = new MallardDuck(); mallard.Display(); Assert.AreEqual("Quack!", mallard.Quack()); Assert.AreEqual("I can fly!", mallard.Fly()); mallard.SetQuackBehavior(new MuteQuack()); mallard.SetFlyBehavior(new FlyNoWay()); Assert.AreEqual("<silence>", mallard.Quack()); Assert.AreEqual("I can't fly", mallard.Fly()); }
public void TestMethod1() { IFlyBehaviour flyBehaviour = new FlyBehaviour(); MallardDuck mallardDuck = new MallardDuck(flyBehaviour); RedheadDuck redheadDuck = new RedheadDuck(flyBehaviour); IFlyBehaviour noFlyBehaviour = new NoFlyBehaviour(); RubberDuck rubberDuck = new RubberDuck(noFlyBehaviour); mallardDuck.Display(); mallardDuck.Fly(); redheadDuck.Display(); redheadDuck.Fly(); rubberDuck.Display(); rubberDuck.Fly(); rubberDuck.ChangeFlyBehaviour(flyBehaviour); rubberDuck.Fly(); redheadDuck.Swim(); mallardDuck.Swim(); rubberDuck.Swim(); }
static void Main(string[] args) { // Pato Bravo MallardDuck md = new MallardDuck(); md.Display(); md.Swim(); md.Fly(); md.Quack(); System.Console.WriteLine("\n"); // Pato Cabeça-vermelha RedHeadDuck rhd = new RedHeadDuck(); rhd.Display(); rhd.Swim(); rhd.Fly(); rhd.Quack(); System.Console.WriteLine("\n"); // Pato de Borracha RubberDuck rd = new RubberDuck(); rhd.Display(); rhd.Swim(); rd.Quack(); // Chia invés de grasnar System.Console.WriteLine("\n"); Console.ReadKey(); }
static void Main(string[] args) { MallardDuck duck = new MallardDuck(); WildTurkey turkey = new WildTurkey(); IDuck turkeyAdapter = new TurkeyAdapter(turkey); Console.WriteLine("\t---Turkey!!!---"); turkey.Fly(); turkey.Gobble(); // Ошибка так как Turkey реализует интерфейс ITurkey //TestDuck(turkey); TestDuck(turkeyAdapter); Console.WriteLine("\n\t---Duck!!!---"); duck.Fly(); duck.Quack(); Console.WriteLine("\t---Turkey!!!---"); TestDuck(turkeyAdapter); Console.WriteLine("\n\t---Duck!!!---"); TestDuck(duck); Console.WriteLine("\n\t---Duck!!!---"); ITurkey duckAdapter = new DuckAdapter(duck); duckAdapter.Fly(); duckAdapter.Gobble(); }
public void TestMallardDuck() { Duck mallard = new MallardDuck(); Assert.AreEqual("Quack", mallard.Quack()); Assert.AreEqual("I'm flying", mallard.Fly()); }
static void Main(string[] args) { IDuck duck = new MallardDuck(); duck.Fly(); duck.Quack(); Console.WriteLine(); ITurkey turkey = new WildTurkey(); turkey.Fly(); turkey.Gobble(); Console.WriteLine(); IDuck adapterDuck = new TurkeyAdapter(turkey); adapterDuck.Fly(); adapterDuck.Quack(); Console.WriteLine(); ITurkey adapterTurkey = new DuckAdapter(duck); adapterTurkey.Fly(); adapterTurkey.Gobble(); Console.ReadKey(); }
public void DuckShouldFly() { var expected = "Weeeee"; MallardDuck mallardDuck = new MallardDuck(); var result = mallardDuck.Fly(); result.Should().Be(expected); }
public void TestMallardDuckFly() { Duck duck = new MallardDuck(); string text = "Fly with wings!\r\n"; using (var consoleOutput = new ConsoleOutput()) { duck.Fly(); Assert.AreEqual(text, consoleOutput.GetOutput()); } Assert.AreEqual(currentConsoleOut, Console.Out); }
static void Main(string[] args) { Duck mallard = new MallardDuck(); mallard.Quack(); mallard.Fly(); Duck model = new ModelDuck(); model.Fly(); model.Fly = FlyRocketPowered; model.Fly(); }
static void Main() { MallardDuck duck = new MallardDuck(); WildTurkey turkey = new WildTurkey(); TurkeyAdapter turkeyAdapter = new TurkeyAdapter(turkey); System.Console.WriteLine("The tukey says..."); turkeyAdapter.Quack(); turkeyAdapter.Fly(); System.Console.WriteLine("\nThe Duck says..."); duck.Quack(); duck.Fly(); }
public static void Start() { var duck = new MallardDuck(); var turkey = new WildTurkey(); var turkeyLikeDuck = new TurkeyAdapter(turkey); duck.Quack(); duck.Fly(); turkey.Gobble(); turkey.Fly(); turkeyLikeDuck.Quack(); turkeyLikeDuck.Fly(); }
static void Main(string[] args) { MallardDuck duck = new MallardDuck(); WildTurkey turkey = new WildTurkey(); IDuck turkeyAdapter = new TurkeyAdapter(turkey); duck.Quack(); duck.Fly(); turkey.Gobble(); turkey.Fly(); turkeyAdapter.Quack(); turkeyAdapter.Fly(); }
static void Main(string[] args) { MallardDuck md = new MallardDuck(); WildTurkey wd = new WildTurkey(); IDuck ta = new TurkeyAdapter(wd); System.Console.WriteLine("\r\nMallard Duck:"); md.Quack(); md.Fly(); System.Console.WriteLine("\r\nWild Turkey:"); wd.Gobble(); wd.Fly(); System.Console.WriteLine("\r\nTurkey Adapter:"); ta.Quack(); ta.Fly(); Console.ReadKey(); }
public void TurkeyAdapter() { IDuck mDuck = new MallardDuck(); ITurkey wTurkey = new WildTurkey(); IDuck turkeyAdapter = new TurkeyAdapter(wTurkey); mDuck.Fly(); mDuck.Quack(); string expecteDuckBehavior = Strings.Fly + Strings.Quack; turkeyAdapter.Fly(); turkeyAdapter.Quack(); string expectedTurkeyAdapterBehavior = Strings.Fly + Strings.Fly + Strings.Fly + Strings.Fly + Strings.Fly + Strings.Gobble; Assert.AreEqual(expecteDuckBehavior, mDuck.GetStatus()); Assert.AreEqual(expectedTurkeyAdapterBehavior, turkeyAdapter.GetStatus()); Assert.AreEqual(expectedTurkeyAdapterBehavior, wTurkey.GetStatus()); }
static void Main(string[] args) { Duck duckMallard = new MallardDuck("José"); Duck duckRedhead = new RedheadDuck("Jaum"); Duck rubberDuck = new RubberDuck("Pedro"); duckMallard.Display(); duckMallard.Quack(); duckMallard.Swin(); duckMallard.Fly(); duckRedhead.Display(); duckRedhead.Quack(); duckRedhead.Swin(); duckRedhead.Fly(); rubberDuck.Display(); rubberDuck.Quack(); rubberDuck.Swin(); rubberDuck.Fly(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { DbInitializer.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } FlyWithWings fly = new FlyWithWings(); FlyNoWay noFly = new FlyNoWay(); MallardDuck md = new MallardDuck(fly); RedheadDuck red = new RedheadDuck(fly); RubberDuck rubberDuck = new RubberDuck(noFly); md.Display(); md.Fly(); red.Display(); red.Fly(); rubberDuck.Display(); rubberDuck.Fly(); host.Run(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { //var context = services.GetRequiredService<AnimalCrossingContext>(); DbInitialiser.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } FlyWithWing fly = new FlyWithWing(); FlyNoWay noFly = new FlyNoWay(); MallardDuck md = new MallardDuck(fly); RedHeadDuck red = new RedHeadDuck(fly); RubberDuck rd = new RubberDuck(noFly); md.Display(); md.Fly(); red.Display(); red.Fly(); rd.Display(); rd.Fly(); host.Run(); }