Пример #1
0
        public void InitializationSucceeds()
        {
            var exportResponse = TelegramModule.Initialize("1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy", 10);
            var response       = JsonConvert.DeserializeObject <Response <string> >(exportResponse);

            Assert.IsType <Response <string> >(response);
        }
Пример #2
0
 public void TimeoutIsSet()
 {
     TelegramModule.Initialize(ApiKey, 10);
     Assert.True(TelegramModule.Bot.RequestTimeout == 10000);
     TelegramModule.SetRequestTimeout(20);
     Assert.True(TelegramModule.Bot.RequestTimeout == 20000);
 }
Пример #3
0
        public void EmptyApiKeyReturnsInitError()
        {
            var exportResponse = TelegramModule.Initialize(string.Empty, 10);
            var responseError  = JsonConvert.DeserializeObject <Response <Error> >(exportResponse);

            Assert.IsType <Response <Error> >(responseError);
            Assert.Equal(typeof(ArgumentException).Name, responseError.Content.ExceptionType);
        }
Пример #4
0
        public void ZeroTimoutReturnsInitError()
        {
            var exportResponse = TelegramModule.Initialize("test", 0);
            var responseError  = JsonConvert.DeserializeObject <Response <Error> >(exportResponse);

            Assert.IsType <Response <Error> >(responseError);
            Assert.Equal(typeof(ArgumentException).Name, responseError.Content.ExceptionType);
        }
Пример #5
0
        public void SetDefaultValueInputsGetValidated()
        {
            var mock = new Mock <ITelegramBotMapper>();

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

            Assert.Contains(nameof(ArgumentException), TelegramModule.SetDefaultValue(string.Empty, "some text"));
            Assert.Contains(nameof(ArgumentException), TelegramModule.SetDefaultValue("some text", string.Empty));
        }
Пример #6
0
        public void DefaultValuesAreSet()
        {
            TelegramModule.Initialize(ApiKey, 10);

            TelegramModule.SetDefaultValue(nameof(TelegramModule.Bot.DisableNotifications), "true");
            TelegramModule.SetDefaultValue(nameof(TelegramModule.Bot.DisableWebPagePreview), "true");
            TelegramModule.SetDefaultValue(nameof(TelegramModule.Bot.ParseMode), "html");
            Assert.True(TelegramModule.Bot.DisableNotifications);
            Assert.True(TelegramModule.Bot.DisableWebPagePreview);
            Assert.True(TelegramModule.Bot.ParseMode == ParseMode.Html);
        }
Пример #7
0
        public void GetMeReturnsBotUser()
        {
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            var result          = TelegramModule.GetMe();
            var successResponse = JsonConvert.DeserializeObject <Response <User> >(result);

            Assert.True(successResponse.Content.IsBot);
        }
Пример #8
0
        public void GetUpdatesReturnsNullOrMoreMessages()
        {
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            var result          = TelegramModule.GetUpdates(0, 0);
            var successResponse = JsonConvert.DeserializeObject <Response <Update[]> >(result);

            Assert.True(successResponse.IsSuccess);
        }
Пример #9
0
        public void SendPhotoInputsGetValidated()
        {
            var mock = new Mock <ITelegramBotMapper>();

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

            Assert.Contains(nameof(ArgumentException), TelegramModule.SendPhoto(string.Empty, "D:/PathToFile.png"));
            Assert.Contains(nameof(ArgumentException), TelegramModule.SendPhoto("-102264846545", string.Empty));
            Assert.Contains(nameof(ArgumentException), TelegramModule.StartSendPhoto(string.Empty, "D:/PathToFile.png"));
            Assert.Contains(nameof(ArgumentException), TelegramModule.StartSendPhoto("-102264846545", string.Empty));
        }
Пример #10
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");
        }
Пример #11
0
        public void SendDocumentSendsDocumentMessageToUser()
        {
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            var result = TelegramModule.SendDocument(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_USER_ID.ToString()),
                $"assets/fake_log.txt");
            var successResponse = JsonConvert.DeserializeObject <Response <Message> >(result);

            Assert.NotEmpty(successResponse.Content.Document.FileId);
        }
Пример #12
0
        public void GetUpdatesSucceeds()
        {
            var mock = new Mock <ITelegramBotMapper>();

            mock.Setup(x => x.GetUpdates(0, 0)).Returns("ok");
            mock.Setup(x => x.StartGetUpdates(0, 0)).Returns("ok");

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

            Assert.True(TelegramModule.GetUpdates(0, 0) == "ok");
            Assert.True(TelegramModule.StartGetUpdates(0, 0) == "ok");
        }
Пример #13
0
        public void SendPhotoSendsPhotoMessageToUser()
        {
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            var result = TelegramModule.SendPhoto(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_USER_ID.ToString()),
                $"assets/favicon-32x32.png");

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

            Assert.NotEmpty(successResponse.Content.Photo);
        }
Пример #14
0
        public async Task StartGetMeReturnsCorrelationIdAsync()
        {
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            var result          = TelegramModule.StartGetMe();
            var successResponse = JsonConvert.DeserializeObject <Response <string> >(result);

            Assert.True(!string.IsNullOrWhiteSpace(successResponse.CorrelationKey));
            var messageStoreResult = await this.WaitForMessageStoreAsync(successResponse.CorrelationKey);

            Assert.IsType <Response <User> >(JsonConvert.DeserializeObject <Response <User> >(messageStoreResult));
        }
Пример #15
0
        public void RequestForCorrelationKeyReturnsErrorIfEntryIsNotFound()
        {
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            TelegramModule.SetRequestTimeout(10);
            var result = TelegramModule.GetMessageByCorrelationId("test");

            var errorResponse = JsonConvert.DeserializeObject <Response <Error> >(result);

            Assert.False(errorResponse.IsSuccess);
            Assert.Equal(typeof(KeyNotFoundException).Name, errorResponse.Content.ExceptionType);
        }
Пример #16
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);
        }
Пример #17
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);
        }
Пример #18
0
        public async Task StartSendTextReturnsCorrelationIdAsync()
        {
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            var result = TelegramModule.StartSendText(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_USER_ID.ToString()),
                $"{nameof(this.SendTextSendsTextMessageToUser)}");
            var successResponse = JsonConvert.DeserializeObject <Response <string> >(result);

            Assert.True(!string.IsNullOrWhiteSpace(successResponse.CorrelationKey));

            var messageStoreResult = await this.WaitForMessageStoreAsync(successResponse.CorrelationKey);

            var correlatedResponse = JsonConvert.DeserializeObject <Response <Message> >(messageStoreResult);

            Assert.IsType <Response <Message> >(correlatedResponse);
            Assert.Equal($"{nameof(this.SendTextSendsTextMessageToUser)}", correlatedResponse.Content.Text);
        }
Пример #19
0
        public async Task StartSendPhotoReturnsCorrelationIdAsync()
        {
            TelegramModule.Initialize(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_BOT_API_KEY.ToString()),
                10);
            TelegramModule.SetDebugOutput(true);
            var result = TelegramModule.StartSendPhoto(
                MBTHelper.ConvertMaskedSecretToRealValue(Secrets.TELEGRAM_USER_ID.ToString()),
                $"assets/favicon-32x32.png");
            var successResponse = JsonConvert.DeserializeObject <Response <string> >(result);

            Assert.True(!string.IsNullOrWhiteSpace(successResponse.CorrelationKey));

            var messageStoreResult = await this.WaitForMessageStoreAsync(successResponse.CorrelationKey);

            var correlatedResponse = JsonConvert.DeserializeObject <Response <Message> >(messageStoreResult);

            Assert.IsType <Response <Message> >(correlatedResponse);
            Assert.NotEmpty(correlatedResponse.Content.Photo);
        }