Esempio n. 1
0
        public void TestProjectToolIsAvailableThroughDriver(string appName)
        {
            var appDirectory = Path.Combine(_testProjectsRoot, appName);

            new BuildCommand(Path.Combine(appDirectory, "project.json"))
                .Execute()
                .Should()
                .Pass();

            var currentDirectory = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(appDirectory);

            try
            {
                CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();

                result.Should().HaveStdOut("Hello World!" + Environment.NewLine);
                result.Should().NotHaveStdErr();
                result.Should().Pass();
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
Esempio n. 2
0
        public void TestProjectDependencyIsNotAvailableThroughDriver()
        {
            var appName = "AppWithDirectDependency";
            var appDirectory = Path.Combine(_testProjectsRoot, appName);

            new BuildCommand(Path.Combine(appDirectory, "project.json"))
                .Execute()
                .Should()
                .Pass();

            var currentDirectory = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(appDirectory);

            try
            {
                CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();

                result.StdOut.Should().Contain("No executable found matching command");
                result.Should().NotPass();
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
Esempio n. 3
0
        public void TestProjectDependencyIsNotAvailableThroughDriver()
        {
            var testInstance = TestAssets.Get("AppWithDirectDep")
                               .CreateInstance()
                               .WithSourceFiles()
                               .UseCurrentRuntimeFrameworkVersion()
                               .WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);

            // restore again now that the project has changed
            new RestoreCommand()
            .WithWorkingDirectory(testInstance.Root)
            .Execute()
            .Should().Pass();

            new BuildCommand()
            .WithWorkingDirectory(testInstance.Root)
            .Execute()
            .Should().Pass();

            var currentDirectory = Directory.GetCurrentDirectory();

            CommandResult result = new HelloCommand()
                                   .WithWorkingDirectory(testInstance.Root)
                                   .ExecuteWithCapturedOutput();

            result.StdErr.Should().Contain(string.Format(LocalizableStrings.NoExecutableFoundMatchingCommand, "dotnet-hello"));

            result.Should().Fail();
        }
Esempio n. 4
0
        public void TestPackagedCommandDependency(string appName)
        {
            string appDirectory = Path.Combine(_testProjectsRoot, appName);

            new BuildCommand(Path.Combine(appDirectory, "project.json"))
            .Execute()
            .Should()
            .Pass();

            var currentDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(appDirectory);

            try
            {
                CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();

                result.Should().HaveStdOut("Hello" + Environment.NewLine);
                result.Should().NotHaveStdErr();
                result.Should().Pass();
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
Esempio n. 5
0
        public void TestProjectDependencyIsNotAvailableThroughDriver()
        {
            var testInstance = TestAssetsManager
                               .CreateTestInstance("AppWithDirectDep")
                               .WithLockFiles();

            var appDirectory = testInstance.Path;

            new BuildCommand(Path.Combine(appDirectory, "project.json"))
            .Execute()
            .Should()
            .Pass();

            var currentDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(appDirectory);

            try
            {
                CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();

                result.StdErr.Should().Contain("No executable found matching command");
                result.Should().Fail();
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
Esempio n. 6
0
        public void TestProjectDependencyIsNotAvailableThroughDriver()
        {
            var appName      = "AppWithDirectDependency";
            var appDirectory = Path.Combine(_testProjectsRoot, appName);

            new BuildCommand(Path.Combine(appDirectory, "project.json"))
            .Execute()
            .Should()
            .Pass();

            var currentDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(appDirectory);

            try
            {
                CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();

                result.StdErr.Should().Contain("No executable found matching command");
                result.Should().Fail();
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            var bus = ConfigureBus();

            bus.Start();

            Console.WriteLine("Press ESC to stop");
            var today = DateTime.Now;

            for (var i = 0; i < 1000; i++)
            {
                var command = new HelloCommand
                {
                    Text = "Hello from Mass Transit!",
                    Date = today
                };

                bus.Publish(command);
                Thread.Sleep(1000);

                today = DateTime.Now;
            }

            bus.Stop();
        }
Esempio n. 8
0
        public void TestProjectToolIsAvailableThroughDriver(string appName)
        {
            var appDirectory = Path.Combine(_testProjectsRoot, appName);

            new BuildCommand(Path.Combine(appDirectory, "project.json"))
            .Execute()
            .Should()
            .Pass();

            var currentDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(appDirectory);

            try
            {
                CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();

                result.Should().HaveStdOut("Hello World!" + Environment.NewLine);
                result.Should().NotHaveStdErr();
                result.Should().Pass();
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
Esempio n. 9
0
        public void TestProjectDependencyIsNotAvailableThroughDriver()
        {
            var testInstance = TestAssets.Get("AppWithDirectDep")
                               .CreateInstance()
                               .WithSourceFiles()
                               .WithRestoreFiles()
                               .UseCurrentRuntimeFrameworkVersion();

            // restore again now that the project has changed
            new RestoreCommand()
            .WithWorkingDirectory(testInstance.Root)
            .Execute()
            .Should().Pass();

            new BuildCommand()
            .WithWorkingDirectory(testInstance.Root)
            .Execute()
            .Should().Pass();

            var currentDirectory = Directory.GetCurrentDirectory();

            CommandResult result = new HelloCommand()
                                   .WithWorkingDirectory(testInstance.Root)
                                   .ExecuteWithCapturedOutput();

            result.StdErr.Should().Contain("No executable found matching command");

            result.Should().Fail();
        }
Esempio n. 10
0
        public void TestPackagedCommandDependency(string appName)
        {
            string appDirectory = Path.Combine(_testProjectsRoot, appName);

            new BuildCommand(Path.Combine(appDirectory, "project.json"))
                .Execute()
                .Should()
                .Pass();

            var currentDirectory = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(appDirectory);

            try
            {
                CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();

                result.Should().HaveStdOut("Hello" + Environment.NewLine);
                result.Should().NotHaveStdErr();
                result.Should().Pass();
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
Esempio n. 11
0
        public async Task ShouldResolveCommandWithoutReturnValue()
        {
            var command = new HelloCommand();

            var commandExecutor2 = this.commandExecutorResolver.Resolve(command);
            await commandExecutor2.ExecuteAsync(command).ConfigureAwait(false);
        }
        /// <summary>
        /// Do handshake for client side.
        /// </summary>
        /// <param name="clientSocket"> Socket from client side to server side</param>
        /// <returns>null if handShake fail otherwise return instance of AProtocol</returns>
        public async Task <AProtocol> HandShakeClient(NetworkStream clientSocket)
        {
            HelloCommand hello = new HelloCommand(ClientConfig.SUPPORTED_PROTOCOLS);
            await hello.SendAsync(clientSocket);

            ACommand shouldBeOLLEH = GetCommand(await clientSocket.ReadLineAsync());

            if (shouldBeOLLEH is OllehCommand)
            {
                OllehCommand olleh    = (OllehCommand)shouldBeOLLEH;
                AProtocol    protocol = ClientConfig.PROTOCOL_FACTORY.GetProtocol(olleh.PROTOCOL);
                if (protocol != null)
                {
                    AckCommand ack = new AckCommand();
                    await ack.SendAsync(clientSocket);

                    return(protocol);
                }
                ErrorCommand error = new ErrorCommand($"Unsupported protocols '{olleh.PROTOCOL}'. Handshake failed.");
                await error.SendAsync(clientSocket);
            }
            else
            {
                printIfErrorElseSendMessage(shouldBeOLLEH, "Handshake error. Expected OllehCommand but receive " + shouldBeOLLEH.GetType().Name, clientSocket);
            }
            return(null);
        }
        /// <summary>
        /// Do handshake for server side.
        /// </summary>
        /// <param name="serverSocket"> Socket from client side to server side</param>
        /// <returns>null if handShake fail otherwise retur instance of AProtocol</returns>
        public async Task <AProtocol> HandShakeServer(SuperNetworkStream serverSocket)
        {
            ACommand shoudBeHELLO = GetCommand(await serverSocket.ReadLineAsync());

            if (shoudBeHELLO is HelloCommand)
            {
                String       selectedProtocolLabel;
                HelloCommand hello    = (HelloCommand)shoudBeHELLO;
                AProtocol    protocol = ServerConfig.PROTOCOL_FACTORY.GetProtocol(out selectedProtocolLabel, hello.SUPPORTED_PROTOCOLS);
                if (protocol != null)
                {
                    OllehCommand olleh = new OllehCommand(selectedProtocolLabel);
                    await olleh.SendAsync(serverSocket);

                    ACommand shoudBeACK = GetCommand(await serverSocket.ReadLineAsync());
                    if (shoudBeACK is AckCommand)
                    {
                        return(protocol);
                    }
                    else
                    {
                        printIfErrorElseSendMessage(shoudBeACK, "Handshake error. Expected HelloCommand but receive:" + shoudBeACK.GetType().Name, serverSocket);
                    }
                }
                await serverSocket.SendCommandAsync(new ErrorCommand(String.Format("Unsupported protocols '{0}'. Handshake failed.", hello.SUPPORTED_PROTOCOLS)));
            }
            else
            {
                printIfErrorElseSendMessage(shoudBeHELLO, "Handshake error. Expected HelloCommand but receive:" + shoudBeHELLO.GetType().Name, serverSocket);
            }

            return(null);
        }
Esempio n. 14
0
        public void DispatchClassCommand()
        {
            ICommandBus  commandBus = GetCommandBus();
            HelloCommand command    = new HelloCommand("Felix");

            commandBus.Dispatch(command);
            Assert.AreEqual("Hello Felix", command.Text);
        }
Esempio n. 15
0
        private static void AJula_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
        {
            Console.WriteLine($"От {e.Message.Chat.Id}:{e.Message.Text}");
            ICommand command;

            switch (e.Message.Text.ToLower())
            {
            case null: return;

            case "привет":
                command = new HelloCommand();
                command.Execute(e.Message);
                break;

            case "время":
                command = new TimeCommand();
                command.Execute(e.Message);
                break;

            case "погода":
                command = new WeatherCommand();
                command.Execute(e.Message);
                break;

            case "курс":
                command = new CurrencyCommand();
                command.Execute(e.Message);
                break;

            case "создание напоминания":
                Bot.Flag = true;
                break;

            case "газета":
                command = new NewsCommand();
                command.Execute(e.Message);
                break;

            case "почта":
                command = new EmailCommand(e.Message.Chat.Id);
                command.Execute(e.Message);
                break;

            default:
                Bot.AssistantJula.SendTextMessageAsync
                (
                    chatId: e.Message.Chat,
                    text: "Я вас не поняла",
                    replyMarkup: KeyboardTemplates.mainKeyboard
                ).ConfigureAwait(false);
                break;
            }
            if (Bot.Flag)
            {
                command = new ReminderCommand();
                command.Execute(e.Message);
            }
        }
Esempio n. 16
0
        public async Task ShouldResolveCommandWithReturnValue()
        {
            var command = new HelloCommand();

            var commandExecutor1 = this.commandExecutorResolver.Resolve <HelloCommand, bool>(command);
            var result           = await commandExecutor1.ExecuteAsync(command).ConfigureAwait(false);

            result.ShouldBe(true);
        }
Esempio n. 17
0
 public async Task <Result <HelloReply> > Handle(HelloCommand request, CancellationToken cancellationToken)
 {
     try
     {
         return(new HelloReply($"Hello {request.Request?.Name}"));
     }
     catch (Exception e)
     {
         _logger.LogError(e, "Error while processing VAT check");
         return(Result.Failure <HelloReply>($"Error while processing VAT check: {e.Message}"));
     }
 }
Esempio n. 18
0
        public async Task HeloResponds()
        {
            var channel = new MockSmtpChannel();
            var command = new HelloCommand(channel, TestHelpers.MakeSettings("Testexample.com"), new MockLogger());

            command.Initialize("Sender.net");
            await command.ExecuteAsync(CancellationToken.None);

            SmtpTestHelper.AssertResponse(channel, SmtpReplyCode.Okay);

            MockSmtpChannel.Entry entry = channel.Entries[0];

            Assert.Contains("Testexample.com", entry.Message);
            Assert.Contains("Sender.net", entry.Message);
        }
Esempio n. 19
0
        public static async Task <TelegramBotClient> Get()
        {
            if (client != null)
            {
                return(client);
            }

            var startCommand = new HelloCommand();

            commands.Add(startCommand);
            // TODO: Add more commands

            client = new TelegramBotClient(AppSettings.Key);
            var hook = string.Format(AppSettings.Url, "api/message/update");
            await client.SetWebhookAsync(hook);

            return(client);
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            var helloCommand   = new HelloCommand("Hello Command");
            var countCommand   = new CountCommand(10);
            var complexCommand = new CalculateRandomCommand(new RandomGenerator(), 5);

            var invoker = new Invoker();

            invoker.Command = helloCommand;
            invoker.DoWork();

            invoker.Command = countCommand;
            invoker.DoWork();

            invoker.Command = complexCommand;
            invoker.DoWork();


            Console.ReadKey();
        }
Esempio n. 21
0
        [Route(@"api/message/update")]  //web hook uri part
        public async Task <OkResult> Update([FromBody] Update update)
        {
            var commands = Bot.Commands;
            var message  = update.Message;
            var client   = await Bot.Get();

            foreach (var command in commands)
            {
                if (command.Contains(message.Text))
                {
                    command.Execute(message, client);
                    break;
                }
            }

            HelloCommand commandEx = new HelloCommand();

            commandEx.Execute(message, client);


            return(Ok());
        }
Esempio n. 22
0
        public void TestProjectDependencyIsNotAvailableThroughDriver()
        {
            var testInstance = TestAssets.Get("AppWithDirectDep")
                               .CreateInstance()
                               .WithSourceFiles()
                               .WithRestoreFiles();

            new BuildCommand()
            .WithWorkingDirectory(testInstance.Root)
            .WithFramework(NuGet.Frameworks.FrameworkConstants.CommonFrameworks.NetCoreApp10)
            .Execute()
            .Should().Pass();

            var currentDirectory = Directory.GetCurrentDirectory();

            CommandResult result = new HelloCommand()
                                   .WithWorkingDirectory(testInstance.Root)
                                   .ExecuteWithCapturedOutput();

            result.StdErr.Should().Contain("No executable found matching command");

            result.Should().Fail();
        }
Esempio n. 23
0
 //Class Constructor
 public ViewModelBase()
 {
     HelloCommand = new HelloCommand(this);
 }
Esempio n. 24
0
 public void Initialize()
 {
     _helloCommand = new HelloCommand();
 }
Esempio n. 25
0
        private string onConversationStarted(ViberCallbackEvent callbackEvent)
        {
            var command = new HelloCommand();

            return(command.Execute(callbackEvent, context));
        }
Esempio n. 26
0
 public virtual void Visit(HelloCommand command) => Default(command);
Esempio n. 27
0
        private static bool hello(MessageEventArgs e)
        {
            var command = new HelloCommand(telegramBot, e.Message.Chat.Id);

            return(command.Dispatch(e));
        }