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(); }
public void CheckRubberDuck() { var wd = new RubberDuck(); wd.Show(); wd.Fly(); wd.Quack(); wd.Swim(); }
public void TestRubberDuckFly() { Duck duck = new RubberDuck(); string text = "Fly with rocket!\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 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(); }
static void Main(string[] args) { Duck exp1 = new Duck(); Console.WriteLine("Я живая утка:\n"); exp1.Fly(); exp1.Swim(); exp1.Quack(); WoodenDuck exp2 = new WoodenDuck(); Console.WriteLine("\nЯ деревянная утка:\n"); exp2.Fly(); exp2.Swim(); exp2.Quack(); RubberDuck exp3 = new RubberDuck(); Console.WriteLine("\nЯ резиновая утка:\n"); exp3.Fly(); exp3.Swim(); exp3.Quack(); Console.ReadLine(); }
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(); }
public static void Main(string[] args) { // First approach (DI and base class of type duck) Console.WriteLine("First approach using base class"); Console.WriteLine("WildDuck using base class"); var wildDuck = new WildDuck(); wildDuck.Fly(); wildDuck.Quack(); Console.WriteLine(""); Console.WriteLine("MountainDuck using base class"); var mountainDuck = new MountainDuck(); mountainDuck.Fly(); mountainDuck.Quack(); Console.WriteLine(""); Console.WriteLine("RubberDuck using base class"); var RubberDuck = new RubberDuck(); RubberDuck.Fly(); RubberDuck.Quack(); Console.WriteLine(""); // // Better approach Console.WriteLine("Better approach using interfaces"); // // Create fly behaviours IFlyable flyingNormal = new FlyingNormal(); IFlyable flyingHigh = new FlyingHigh(); IFlyable wontFly = new WontFly(); // Create quack behaviours IQuackable quackingLoud = new QuackingLoud(); IQuackable squeek = new Squeak(); // Create wildDuck (flying normal, quacking loud) Console.WriteLine("WildDuck-Interface (flying normal, quacking loud"); var betterWildDuck = new BetterDuckClass(flyingNormal, quackingLoud); betterWildDuck.Fly(); betterWildDuck.Quack(); Console.WriteLine(""); // Create mountainDuck (flying high, quacking loud) Console.WriteLine("MountainDuck-Interface (flying high, quacking loud"); var betterMountainDuck = new BetterDuckClass(flyingHigh, quackingLoud); betterMountainDuck.Fly(); betterMountainDuck.Quack(); Console.WriteLine(""); // Create rubberDuck (won't fly, squeeks) Console.WriteLine("RubberDuck-Interface (won't fly, squeeks"); var betterRubberDuck = new BetterDuckClass(null, squeek); betterRubberDuck.Quack(); Console.WriteLine(""); }