public void InitializationSucceeds() { var exportResponse = TelegramModule.Initialize("1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy", 10); var response = JsonConvert.DeserializeObject <Response <string> >(exportResponse); Assert.IsType <Response <string> >(response); }
public void TimeoutIsSet() { TelegramModule.Initialize(ApiKey, 10); Assert.True(TelegramModule.Bot.RequestTimeout == 10000); TelegramModule.SetRequestTimeout(20); Assert.True(TelegramModule.Bot.RequestTimeout == 20000); }
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); }
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); }
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 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); }
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 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); }
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)); }
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 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); }
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 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 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 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); }
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 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); }