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()); }
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(); }
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(); }
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(); }
static void Main(string[] args) { MallardDuck mallard = new MallardDuck(); mallard.Quack(); mallard.SetQuackBehavior(new Squeak()); Console.WriteLine("-- Change Quack Behavior --"); mallard.Quack(); Console.WriteLine("---------------------"); var model = new ModelDuck("Model Duck"); model.Fly(); model.SetFlyBehavior(new FlyRocketPowered()); Console.WriteLine("-- Change Quack Behavior --"); model.Fly(); }
public void DuckShouldQuack() { var expected = "Quack"; MallardDuck mallardDuck = new MallardDuck(); var result = mallardDuck.Quack(); result.Should().Be(expected); }
public void TestMallardDuckQuack() { Duck duck = new MallardDuck(); string text = "Quack, quack!\r\n"; using (var consoleOutput = new ConsoleOutput()) { duck.Quack(); 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(); }
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) { 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(); }
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(); }