Example #1
0
        public void MissingInitializationLeedsToErrors()
        {
            var exportResponse = TelegramModule.GetMe();
            var responseError  = JsonConvert.DeserializeObject <Response <Error> >(exportResponse);

            Assert.Equal(typeof(ApplicationException).Name, responseError.Content.ExceptionType);
        }
Example #2
0
 public void TimeoutIsSet()
 {
     TelegramModule.Initialize(ApiKey, 10);
     Assert.True(TelegramModule.Bot.RequestTimeout == 10000);
     TelegramModule.SetRequestTimeout(20);
     Assert.True(TelegramModule.Bot.RequestTimeout == 20000);
 }
Example #3
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);
        }
Example #4
0
        public frmMain()
        {
            InitializeComponent();

            this.m_client                   = new FFXIVModule();
            this.m_client.OnNewChat        += Client_OnNewChat;
            this.m_client.OnClientFound    += Client_OnClientFound;
            this.m_client.OnClientSelected += Client_OnClientSelected;
            this.m_client.OnClientExited   += Client_OnClientExited;
            this.m_client.OnTTFEnabled     += Client_OnTTFEnabled;

            this.m_telegram                      = new TelegramModule();
            this.m_telegram.OnMessage           += Telegram_OnMessage;
            this.m_telegram.OnTelegramConnected += Telegram_OnTelegramConnected;

            this.m_user                     = new UserList();
            this.m_user.OnUserAdded        += User_OnUserAdded;
            this.m_user.OnUserRemoved      += User_OnUserRemoved;
            this.m_user.OnUsersAdded       += User_OnUsersAdded;
            this.m_user.OnUserUpdated      += User_OnUserUpdated;
            this.m_user.OnUserConnected    += User_OnUserConnected;
            this.m_user.OnUserDisconnected += User_OnUserDisconnected;

            this.txtTTFKey.Text = "F8";
            this.txtTTFKey.Tag  = Keys.F8;

            this.ntf.Text = this.Text;
            this.ntf.Icon = this.Icon;

            this.Enabled = false;
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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));
        }
        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);
        }
        public TelegramModuleIntegrationTests()
        {
            // https://colinmackay.scot/2007/06/16/unit-testing-a-static-class/
            Type            staticType = typeof(TelegramModule);
            ConstructorInfo ci         = staticType.TypeInitializer;

            object[] parameters = new object[0];
            ci.Invoke(null, parameters);

            TelegramModule.SetDebugOutput(true);
        }
        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);
        }
Example #11
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);
        }
Example #12
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));
        }
Example #13
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");
        }
        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);
        }
Example #15
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");
        }
        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);
        }
        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);
        }
        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));
        }
        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);
        }
        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);
        }
        private async Task <string> WaitForMessageStoreAsync(string correlationKey)
        {
            var messageStoreResult = string.Empty;

            for (int i = 0; i <= 10; i++)
            {
                messageStoreResult = TelegramModule.GetMessageByCorrelationId(correlationKey);
                if (messageStoreResult.Contains(nameof(KeyNotFoundException)))
                {
                    await Task.Delay(1000);
                }
                else
                {
                    break;
                }
            }

            return(messageStoreResult);
        }
        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);
        }
        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);
        }
 public TelegramController(
     TelegramModule telegramModule)
 {
     _telegramModule = telegramModule;
 }