public async Task ProcessActivityShouldReturnNullReferenceException() { var adapter = new TwitterAdapter(_testOptions.Object); await Assert.ThrowsExceptionAsync <NullReferenceException>(async() => { await adapter.ProcessActivity(null, null); }); }
public async Task ProcessActivityShouldSucceed() { var adapter = new TwitterAdapter(_testOptions.Object); var directMessageEvent = new DirectMessageEvent(); var bot = new Mock <IBot>(); directMessageEvent.MessageText = "test message text"; directMessageEvent.Sender = new TwitterUser(); directMessageEvent.Recipient = new TwitterUser(); directMessageEvent.Sender.Id = string.Empty; directMessageEvent.Sender.ScreenName = string.Empty; directMessageEvent.Recipient.Id = string.Empty; directMessageEvent.Recipient.ScreenName = string.Empty; bot.SetupAllProperties(); await adapter.ProcessActivity(directMessageEvent, bot.Object.OnTurnAsync); bot.Verify(b => b.OnTurnAsync(It.IsAny <TurnContext>(), It.IsAny <CancellationToken>()), Times.Once); }
private async void OnDirectMessageReceived(DirectMessageEvent obj) { _logger.LogInformation( $"Direct Message from {obj.Sender.Name} (@{obj.Sender.ScreenName}): {obj.MessageText}"); // Important: Ignore messages originating from the bot else recursion happens if (obj.Sender.ScreenName == _options.BotUsername) { return; } if (_options.AllowedUsernamesConfigured() && _options.AllowedUsernames.Contains(obj.Sender.ScreenName) || !_options.AllowedUsernamesConfigured()) { // Only respond if sender is different than the bot await _adapter.ProcessActivity(obj, _bot.OnTurnAsync); } }