Exemple #1
0
        static async Task Main(string[] args)
        {
            var configuration = new ConfigurationBuilder().AddEnvironmentVariables().AddCommandLine(args).Build();

            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new LucyComponentRegistration());
            ComponentRegistration.Add(new ConsoleComponentRegistration());

            var appName         = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
            var userStoragePath = Path.Combine(Path.GetTempPath(), appName);

            Directory.CreateDirectory(userStoragePath);
            var adapter = new ConsoleAdapter()
                          .Use(new RegisterClassMiddleware <IConfiguration>(configuration))
                          .UseStorage(new MemoryStorage())
                          .UseBotState(new ConversationState(new MemoryStorage()), new UserState(new FileStorage(userStoragePath)));

            var resourceExplorer = new ResourceExplorer()
                                   .AddFolder(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "ConsoleBot"));

            var bot = new DialogManager()
            {
                RootDialog = resourceExplorer.LoadType <AdaptiveDialog>(resourceExplorer.GetResource("ConsoleBot.dialog"))
            }
            .UseResourceExplorer(resourceExplorer)
            .UseLanguageGeneration();

            await((ConsoleAdapter)adapter).StartConversation(bot.OnTurnAsync, String.Join(" ", args));
        }
        public void SetUp()
        {
            _consoleInterface = new ConsoleInterfaceForTesting();
            _consoleInterface.BufferWidth = 80;
            _consoleInterface.WindowWidth = 80;

            _adapter = new ConsoleAdapter(_consoleInterface);
        }
 protected override void WriteDetails()
 {
     if (Result.EntryType == EntryTypes.ResultFail)
     {
         ConsoleAdapter.Write(": ");
         ConsoleAdapter.Write(Writer.Colors.ResultFailMessage, Result.Message);
     }
 }
Exemple #4
0
 static void Main(string[] args)
 {
     var adapter = new ConsoleAdapter();
     //adapter.ProcessActivity(async (context) =>
     //{
     //    //var dijitsBot = new dijits.
     //})
 }
        public UnitTestConsole(string programName = null)
        {
            _consoleInterface = new ConsoleInterfaceForTesting();
            var errorPrefix = string.Format("{0}: ", programName ?? "error");

            _console = new ConsoleAdapter(_consoleInterface);
            _error = new ErrorAdapter(_consoleInterface, errorPrefix);
        }
Exemple #6
0
        internal virtual void Write(Int32 padding)
        {
            ConsoleAdapter.Write($"{String.Empty.PadLeft(padding)}{Name} => ");

            WriteResult();
            WriteDetails();

            ConsoleAdapter.WriteLine();
        }
        private static int Main(string[] args)
        {
            var fileSystem        = new FileSystem();
            var consoleAdapter    = new ConsoleAdapter();
            var commandLineParser = new CommandLineParser();
            var excludeFileParser = new ExcludeFileParser(fileSystem);

            var appController = new AppController(fileSystem, consoleAdapter, commandLineParser, excludeFileParser);

            return(appController.Main(args));
        }
Exemple #8
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the EchoBot.");

            var adapter = new ConsoleAdapter();

            adapter.ProcessActivity(async(context) =>
            {
                var echoBot = new EchoBot();
                await echoBot.OnTurn(context);
            }).Wait();
        }
        public static void Describe(CommandLineInterpreterConfiguration config, ConsoleAdapter console, string applicationName, CommandLineParserConventions conventions)
        {
            CommandDescriber.Describe(config, console, applicationName, CommandExecutionMode.CommandLine);

            var adorner = MakeAdorner(conventions);
            foreach (var baseCommandConfig in config.Commands)
            {
                console.WriteLine();
                console.WriteLine("Description of {0} command:", baseCommandConfig.Name);
                CommandDescriber.Describe(baseCommandConfig, console, CommandExecutionMode.CommandLine, adorner);
            }
        }
 static async Task MainAsync(string[] args)
 {
     Console.WriteLine("Welcome to the EchoBot.");
     var adapter = new ConsoleAdapter();
     await adapter.ProcessActivity(async (context) =>
     {
         if (context.Request.Type == ActivityTypes.Message)
         {
             context.Reply($"echo: {context.Request.AsMessageActivity().Text}");
         }
     });
 }
Exemple #11
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the CounterBot.");

            var adapter = new ConsoleAdapter();

            adapter.Use(new ConversationState <CounterState>(new MemoryStorage()));
            adapter.ProcessActivity(async(context) =>
            {
                var counterBot = new CounterBot();
                await counterBot.OnTurn(context);
            }).Wait();
        }
Exemple #12
0
 public void ShouldReadLineFromConsoleInput()
 {
     using (StringWriter sw = new StringWriter())
     {
         Console.SetOut(sw);
         using (StringReader sr = new StringReader(_aReallyFunnyMessage))
         {
             Console.SetIn(sr);
             var result = new ConsoleAdapter().ReadLine();
             Assert.AreEqual <string>(_aReallyFunnyMessage, result);
         }
     }
 }
        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();
        }
Exemple #14
0
        private static void Main(string[] args)
        {
            IConsole console =
                new ConsoleAdapter();
            IPdfToTextConverter pdfToText =
                new PdfToTextConverter(new ConsoleAdapter());
            IEmailService email =
                new EmailService(new ConsoleAdapter());

            pdfToText.Completed += email.Send;

            pdfToText.Convert("TDDEvent.pdf");
            console.ReadLine();
        }
Exemple #15
0
        static async Task MainAsync(string[] args)
        {
            var cc = new ConsoleAdapter();

            Builder.Bot bot = new Builder.Bot(cc);
            bot.OnReceive(async(context) =>
            {
                if (context.Request.Type == ActivityTypes.Message)
                {
                    context.Reply($"echo: {context.Request.AsMessageActivity().Text}");
                }
            });

            Console.WriteLine("Welcome to the EchoBot.");
            await cc.Listen();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the EchoBot. Type something to get started.");

            // Create the Console Adapter, and add Conversation State
            // to the Bot. The Conversation State will be stored in memory.
            var adapter = new ConsoleAdapter()
                          .Use(new ConversationState <EchoState>(new MemoryStorage()));

            // Create the instance of our Bot.
            var echoBot = new EchoBot();

            // Connect the Console Adapter to the Bot.
            adapter.ProcessActivity(
                async(context) => await echoBot.OnTurn(context)).Wait();
        }
        public void Write_WritesStringToOutputStream_ExpectedOutput()
        {
            using (StringWriter sw = new StringWriter())
            {
                //Arrange
                IConsoleAdapter aConsoleAdapter = new ConsoleAdapter();
                Console.SetOut(sw);

                //Act
                aConsoleAdapter.Write("test message \n over two lines!");
                var expected = "test message \n over two lines!";
                var result   = sw.ToString();

                //Assert
                Assert.AreEqual <string>(expected, result);
            }
        }
        public void ReadLine_ReadLineFromInputStream_ReturnsString()
        {
            using (StringReader sr = new StringReader("Test Input"))
            {
                //Arrange
                IConsoleAdapter aConsoleAdapter = new ConsoleAdapter();

                //Act
                Console.SetIn(sr);
                var result   = aConsoleAdapter.ReadLine();
                var expected = "Test Input";

                //Assert
                Assert.IsNotNull(result);
                Assert.AreEqual <string>(result, expected);
            }
        }
        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();
        }
Exemple #20
0
        protected override void WriteDetails()
        {
            ConsoleAdapter.Write($" [Total: {ResultsTotal}; Ok: ");
            ConsoleAdapter.Write(Writer.Colors.ResultsOk, $"{ResultsSuccessful}");
            ConsoleAdapter.Write("; Failed: ");

            if (HasFails)
            {
                ConsoleAdapter.Write(Writer.Colors.ResultsFailed, $"{ResultsFailed + Errors}");
            }
            else
            {
                ConsoleAdapter.Write("0");
            }

            ConsoleAdapter.Write("]");
        }
        public void WriteLine_WriteLineNoParameters_WritesCarriageReturnToOutputStream()
        {
            using (StringWriter sw = new StringWriter())
            {
                //Arrange
                IConsoleAdapter aConsoleAdapter = new ConsoleAdapter();
                Console.SetOut(sw);

                //Act
                aConsoleAdapter.WriteLine();
                var expected = string.Format("{0}", Environment.NewLine);

                var result = sw.ToString();

                //Assert
                Assert.AreEqual <string>(expected, result);
            }
        }
        public void WriteLine_WritesLineToOutputStream_ExpectedOutput()
        {
            using (StringWriter sw = new StringWriter())
            {
                //Arrange
                IConsoleAdapter aConsoleAdapter = new ConsoleAdapter();
                Console.SetOut(sw);

                //Act
                aConsoleAdapter.WriteLine("Press any key to Continue!");
                var expected = string.Format("Press any key to Continue!{0}", Environment.NewLine);

                var result = sw.ToString();

                //Assert
                Assert.AreEqual <string>(expected, result);
            }
        }
        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)");
        }
        public static void Main(string[] args)
        {
            //Initialise Application Dependancies
            var title   = Resources.ApplicationTitle;
            var author  = Resources.ApplicationAuthor;
            var players = new List <IPlayer>();

            var rulesDictionary = new Dictionary <GameAction, List <GameAction> >()
            {
                {
                    GameAction.Rock,
                    new List <GameAction>()
                    {
                        GameAction.Scissors
                    }
                },
                {
                    GameAction.Paper,
                    new List <GameAction>()
                    {
                        GameAction.Rock
                    }
                },
                {
                    GameAction.Scissors,
                    new List <GameAction>()
                    {
                        GameAction.Paper
                    }
                }
            };

            var rules = new GameRules(rulesDictionary);
            Dictionary <IPlayer, int> scoresDictionary = new Dictionary <IPlayer, int>();
            var score                 = new Score(scoresDictionary);
            var consoleAdapter        = new ConsoleAdapter();
            var interactionController = new ConsoleInteractionController(consoleAdapter);

            //Initialise Application
            var application = new Application(title, author, players, rules, interactionController, null, score, null);

            //Run Application
            application.Run();
        }
 protected override void WriteResult()
 {
     if (IsIgnored)
     {
         ConsoleAdapter.Write(Writer.Colors.IgnoreMessage, IgnoreReason);
     }
     else if (IsEmpty && !IsFailed)
     {
         ConsoleAdapter.Write(Writer.Colors.StateEmpty, "Method has no test instructions!");
     }
     else if (IsFailed)
     {
         ConsoleAdapter.Write(Writer.Colors.StateFailed, "Failed");
     }
     else
     {
         ConsoleAdapter.Write(Writer.Colors.StateOk, "Ok");
     }
 }
Exemple #26
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)");
        }
        public void TestShowWeatherResultToConsoleAdapter()
        {
            //Hexagon
            var todayWeahterInFahrenheit = 68;
            var formatedWeatherStatus    = "دمای هوای امروز 20 درجه است";

            IWeatherForecastPort weatherReaderPort = CreateForecastPort(WeatherReaderPortStub.WhichReturn(todayWeahterInFahrenheit));

            IConsoleWriter consoleWriter = new MockConsoleWriter();

            ((MockConsoleWriter)consoleWriter).Setup(expectedMessage: formatedWeatherStatus);

            //Driver Side
            IConsoleAdapter sut = new ConsoleAdapter(consoleWriter, port: weatherReaderPort);

            sut.Run();

            //Assert
            ((MockConsoleWriter)consoleWriter).Verify();
        }
        public void SetUp()
        {
            _posix = new CommandLineInterpreterConfiguration(CommandLineParserConventions.PosixConventions);
            _msDos = new CommandLineInterpreterConfiguration(CommandLineParserConventions.MsDosConventions);
            _msStd = new CommandLineInterpreterConfiguration(CommandLineParserConventions.MicrosoftStandard);
            Configure(_posix);
            Configure(_msDos);
            Configure(_msStd);

            _consoleOutInterface = new ConsoleInterfaceForTesting();
            _console = new ConsoleAdapter(_consoleOutInterface);
        }
Exemple #29
0
 protected override void WriteResult() => ConsoleAdapter.Write(HasFails ? Writer.Colors.StateFailed : Writer.Colors.StateOk, HasFails ? "Failed" : "Ok");
        public void SetUp()
        {
            _longText = "ABCDEF GHIJKLM NOPQRST UVWXYZ ABCDEF GHIJKLM NOPQRST UVWXYZ ABCDEF GHIJKLM NOPQRST UVWXYZ ABCDEF GHIJKLM NOPQRST UVWXYZ ABCDEF GHIJKLM NOPQRST UVWXYZ ABCDEF GHIJKLM NOPQRST UVWXYZ";

            _consoleInterface = new ConsoleInterfaceForTesting();
            _consoleInterface.BufferWidth = 80;
            _consoleInterface.WindowWidth = 80;

            _adapter = new ConsoleAdapter(_consoleInterface);
        }
 protected override void WriteDetails() => ConsoleAdapter.Write(Writer.Colors.InjectionMessage, $"'{Result.Message}'");
        public void SetUp()
        {
            _config = new CommandLineInterpreterConfiguration();
            _config.Command("first", s => new TestCommand())
                .Description("Description of the first commmand.");
            _config
                .Command("second", s => new TestCommand())
                .Description("The second command is a command with a number of parameters.")
                .Positional<string>("dateofthing", (command, s) => { })
                    .Description("The date the thing should have.")
                .Positional<string>("numberofthing", (command, s) => { })
                    .Description("The number of things that should be.");
            _config
                .Command("third", s => new TestCommand())
                .Description("The third command has a number of options but no parameters.")
                .Option("on", (command, b) => { })
                    .Description("A simple option with no argument.")
                .Option<string, int>("fiddly", (command, s, n) => { })
                    .Alias("f")
                    .Description("An option with two arguments. The arguments need to be described in the text.");
            _config
                .Command("fourth", s => new TestCommand())
                .Description("The fourth command is really complicated with a number of parameters and also options. This is the sort of command that needs lots of text.")
                .Positional<string>("date", (command, s) => { })
                    .Description("The date the complicated nonsense should be forgotten.")
                .Positional<string>("crpyticnum", (command, s) => { })
                    .Description("The amount of nonsense the user needs to forget.")
                .Option("ignore", (command, b) => { })
                    .Description("Use this option to consign this command to history, where it belongs.")
                .Option<string, int>("more", (command, s, n) => { })
                    .Description("Even more.");

            _config
                .Command("desc", s => new TestCommand())
                .Description(
                    @"Descriptions can contain embedded line breaks -->
            <-- like that one. These should be respected in the formatting. (This is meant to look a bit odd. Also, you should be aware that the deliberate line break is the only one in this text.)")
                .Positional<string>("pos", (command, s) => { })
                    .Description(@"A parameter with
            a line break.")
                .Option("lb", (command, b) => { })
                    .Description("Another\nbreak.");

            _config
                .Command("exp", s => new TestCommand())
                .Description(@"Command with a positional and options configured using a Linq Expression, not a lambda.")
                .Positional("pos", command => command.StringProp)
                    .Description(@"A positional configured with an expression.")
                .Option("B", command => command.BoolProp)
                    .Description("A boolean option configured with an expression.")
                .Option("I", command => command.IntProp)
                    .Description("A boolean option configured with an expression.");

            _customParser = new CustomParser();

            _consoleOutInterface = new ConsoleInterfaceForTesting();
            _console = new ConsoleAdapter(_consoleOutInterface);

            _console.WriteLine(RulerFormatter.MakeRuler(40));
        }
        public void SetUp()
        {
            _interface = new ConsoleInterfaceForTesting();
            _adapter = new ConsoleAdapter(_interface);

            StringVal = null;
            IntVal = 0;

            _goodStream = MakeStream(new [] {"text", "45"});
            _stringOnlyStream = MakeStream(new [] {"text"});
            _selectStream = MakeStream(new [] {"bad", "2", "C"});
            _validationStream = MakeStream(new[] { "2", "10", "11" });
        }
 public void SetUp()
 {
     Toolkit.GlobalReset();
     _consoleInterface = new ConsoleInterfaceForTesting();
     _adapter = new ConsoleAdapter(_consoleInterface);
 }
 public void SetUp()
 {
     _outInterface = new ConsoleInterfaceForTesting();
     _adapter = new ConsoleAdapter(_outInterface);
     _stream = new ConsoleAdapterStream(_adapter);
 }
Exemple #36
0
 public ConsoleAdapterTest()
 {
     sut        = ConsoleAdapter.Instance;
     shimResult = new List <string>(10);
 }
 public ConsoleAdapteurTests()
 {
     console = new ConsoleImplementation();
 }
 public ConsoleAdapterStream(ConsoleAdapter adapter)
 {
     _adapter = adapter;
 }
 protected override void WriteResult()
 => ConsoleAdapter.Write(Result.EntryType == EntryTypes.ResultOk ? Writer.Colors.StateOk : Writer.Colors.StateFailed,
                         Result.EntryType == EntryTypes.ResultOk ? "Ok" : "Failed");
        public void SetUp()
        {
            _interface = new ConsoleInterfaceForTesting();
            _adapter = new ConsoleAdapter(_interface);

            StringVal = null;
            IntVal = 0;
        }