Пример #1
0
        public void SendTextInputsGetValidated()
        {
            var mock = new Mock <ITelegramBotMapper>();

            TelegramModule.Initialize(ApiKey, 10);
            TelegramModule.Bot = mock.Object;

            Assert.Contains(nameof(ArgumentException), TelegramModule.SendText(string.Empty, "some text"));
            Assert.Contains(nameof(ArgumentException), TelegramModule.SendText("some text", string.Empty));
            Assert.Contains(nameof(ArgumentException), TelegramModule.StartSendText(string.Empty, "some text"));
            Assert.Contains(nameof(ArgumentException), TelegramModule.StartSendText("some text", string.Empty));
        }
Пример #2
0
        public void SendTextSucceeds()
        {
            var mock = new Mock <ITelegramBotMapper>();

            mock.Setup(x => x.SendText(It.IsAny <string>(), It.IsAny <string>())).Returns("ok");
            mock.Setup(x => x.StartSendText(It.IsAny <string>(), It.IsAny <string>())).Returns("ok");

            TelegramModule.Initialize(ApiKey, 10);
            TelegramModule.Bot = mock.Object;

            Assert.True(TelegramModule.SendText("some text", "some text") == "ok");
            Assert.True(TelegramModule.StartSendText("some text", "some text") == "ok");
        }
Пример #3
0
        public void SendTextSendsTextMessageWithEmojiToUser()
        {
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            var result = TelegramModule.SendText(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_USER_ID.ToString()),
                $"{nameof(this.SendTextSendsTextMessageToUser)} with \\U+1F601");

            var successResponse = JsonConvert.DeserializeObject <Response <Message> >(result);

            Assert.Equal($"{nameof(this.SendTextSendsTextMessageToUser)} with 😁", successResponse.Content.Text);
        }
Пример #4
0
        public void SendTextSendsTextMessageToChannel()
        {
            // Sending by @channelname only works if it is a public channel
            // SendText(Secrets.CHANNEL_NAME.ToString(), $"{nameof(this.SendTextSendsTextMessageToChannel)}")
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            var result = TelegramModule.SendText(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_CHANNEL_ID.ToString()),
                $"{nameof(this.SendTextSendsTextMessageToChannel)}");

            var successResponse = JsonConvert.DeserializeObject <Response <Message> >(result);

            Assert.Equal($"{nameof(this.SendTextSendsTextMessageToChannel)}", successResponse.Content.Text);
        }