static void Main(string[] args)
        {
            // Instantiate the hexagon (with no right-side adapter-> hard coded poems here)
            var poetryReader = new PoetryReader();

            // Instantiate the left-side adapter(s)
            var consoleAdapter = new ConsoleAdapter(poetryReader);

            // App logic is only using left-side adapter(s).
            System.Console.WriteLine("Here is some poetry:\n");
            consoleAdapter.Ask();
            System.Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            // 1. Instantiate the right-side adapter(s) ("I want to go outside the hexagon")
            var fileAdapter = new PoetryLibraryFileAdapter(@"C:\Poetry\Rimbaud.txt");

            // 2. Instantiate the hexagon
            var poetryReader = new PoetryReader(fileAdapter);

            // 3. Instantiate the left-side adapter(s) ("I need to enter the hexagon")
            var consoleAdapter = new ConsoleAdapter(poetryReader);

            System.Console.WriteLine("Here is some...");
            consoleAdapter.Ask();

            System.Console.WriteLine("Type enter to exit...");
            System.Console.ReadLine();
        }
        public void Should_give_verses_when_asked_for_poetry_from_a_ConsoleAdapter()
        {
            // Instantiate right-side adapters (I want to go out)
            var poetryLibrary = Substitute.For <IObtainPoems>();

            poetryLibrary.GetAPoem().Returns("I want to sleep\r\nSwat the flies\r\nSoftly, please.\r\n\r\n-- Masaoka Shiki (1867-1902)");

            // Instantiate the hexagon
            var poetryReader = new PoetryReader(poetryLibrary);

            // Instantiate the left-side adapter(s)
            var writeStrategy = Substitute.For <IWriteStuffOnTheConsole>();

            ;           var consoleAdapter = new ConsoleAdapter(poetryReader, writeStrategy);

            consoleAdapter.Ask();
            writeStrategy.Received().WriteLine("A beautiful poem:\n\nI want to sleep\r\nSwat the flies\r\nSoftly, please.\r\n\r\n-- Masaoka Shiki (1867-1902)");
        }
Beispiel #4
0
        public void should_provide_verses_when_asked_for_poetry_with_the_support_of_a_console_adapter()
        {
            // 1. Instantiate the right-side adapter(s) ("I want to go outside the hexagon")
            IObtainPoems poetryLibrary = Substitute.For <IObtainPoems>();

            poetryLibrary.GetMeAPoem().Returns("If you could read a leaf or tree\r\nyou'd have no need of books.\r\n-- Alistair Cockburn (1987)");

            // 2. Instantiate the hexagon
            var poetryReader = new PoetryReader(poetryLibrary);

            IWriteLines publicationStrategy = Substitute.For <IWriteLines>();

            // 3. Instantiate the left-side adapter(s) ("I need to enter the hexagon")
            var consoleAdapter = new ConsoleAdapter(poetryReader, publicationStrategy);

            consoleAdapter.Ask();

            // Check that Console.WriteLine has been called with infra specific details "Poem:\r\n" added
            publicationStrategy.Received().WriteLine("Poem:\r\nIf you could read a leaf or tree\r\nyou'd have no need of books.\r\n-- Alistair Cockburn (1987)");
        }