From 40b02e4eec2e3aec7aceb181bd82ef6e06decdf3 Mon Sep 17 00:00:00 2001 From: "treveshan.naidoo@gmail.com" Date: Fri, 2 Aug 2024 13:44:51 +0200 Subject: [PATCH] feat: add Adapter --- .../InsurancePolicyAdapterTests.cs | 1 + src/DesignPatterns/Program.cs | 36 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/DesignPatterns.Structural.Tests/InsurancePolicyAdapterTests.cs b/src/DesignPatterns.Structural.Tests/InsurancePolicyAdapterTests.cs index aef2c98..c0e1938 100644 --- a/src/DesignPatterns.Structural.Tests/InsurancePolicyAdapterTests.cs +++ b/src/DesignPatterns.Structural.Tests/InsurancePolicyAdapterTests.cs @@ -1,4 +1,5 @@ using DesignPatterns.Structural.Adapter; +using FluentAssertions; namespace DesignPatterns.Structural.Tests { diff --git a/src/DesignPatterns/Program.cs b/src/DesignPatterns/Program.cs index 5cecddf..5fbf945 100644 --- a/src/DesignPatterns/Program.cs +++ b/src/DesignPatterns/Program.cs @@ -4,6 +4,7 @@ using DesignPatterns.Creational.FactoryMethod; using DesignPatterns.Creational.Prototype; using DesignPatterns.Creational.Singleton; +using DesignPatterns.Structural.Adapter; using DesignPatterns.Utils.Display; using Spectre.Console; @@ -31,16 +32,16 @@ Console.Clear(); MainTitle(); - var rule = new Rule("[red]Creational[/]"); - rule.Justification = Justify.Center; - AnsiConsole.Write(rule); + //var rule = new Rule("[red]Creational[/]"); + //rule.Justification = Justify.Center; + //AnsiConsole.Write(rule); var choice = AnsiConsole.Prompt( new SelectionPrompt() .Title("Please choose pattern to run:") .PageSize(10) .AddChoices(new[] { - "Factory Method","Abstract Factory","Builder","Prototype","Singleton", "Exit" + "Factory Method","Abstract Factory","Builder","Prototype","Singleton","Adapter", "Exit" })); switch (choice) @@ -60,6 +61,9 @@ case "Singleton": RunSingletonFactory(); break; + case "Adapter": + RunAdapterFactory(); + break; case "Exit": exit = true; break; @@ -201,4 +205,28 @@ void RunSingletonFactory() } } } +void RunAdapterFactory() +{ + var adapter = new Adapter(new ConsoleOutput()); + var exit = false; + while (!exit) + { + var option = AnsiConsole.Prompt( + new SelectionPrompt() + .Title("Please choose option:") + .PageSize(10) + .AddChoices(new[] { + "Start", "Exit" + })); + if (!string.IsNullOrEmpty(option)) + { + if (option.ToLower() == "exit") + { + exit = true; + break; + } + adapter.Run(); + } + } +}