Alternative method for using Middleware in CloudAdapter

Brass Contributor

In BotFrameworkAdapter ,we have method called 'Use(IMiddleware middleware)' to add middleware to adapter pipeline. We were able to use this method to unit test the middleware functions.

 

Now we have upgraded to .Net 6 and now using Cloud Adapter. But in this one we couldn't found any method to pass middleware object  for unit testing.

 

Is there any alternative method to add middleware object to adapter pipeline in Cloud Adapter 

5 Replies
@Lakshmi_145 - Thanks for reporting your issue.
We will check this at our end and will get back to you.

@Lakshmi_145 - CloudAdapter.ConnectNamedPipeAsync Method -Used to connect the adapter to a named pipe.
Reference Document-https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.integration.aspnet.core.cloudadap...

@Sayali-MSFT 

 

I wanted to add the middleware to cloud adapter for unit testing.

 

In ConnectNamedPipeAsync(string pipeName, IBot bot, string audience = null) , its passing bot as parameter. Instead we need to add middleware to cloud adapter for testing purpose 

Hello @Lakshmi_145 - Could you please share your code snippets that you have used for 'Use(IMiddleware middleware)' in BotFrameworkAdapter  and how are you trying it for CloudAdapter for your unit tests?.
So that we can check on it from our end?

@ChetanSharma-msft 

 

Use method to add the middleware in Bot framework adapter:

 

 

var adapter = new BotFrameworkAdapterTest(mockCredentialProvider.Object)                                                             .Use(newMiddleware(userState, Repository.Object, logger.Object));

            // Act
            await adapter.ProcessActivityAsync(
                mockClaims.Object,
                new Activity()
                {
                    Conversation = conversationReference.Conversation,
                    From = conversationReference.User,
                    Recipient = conversationReference.Bot,
                    ChannelId = conversationReference.ChannelId,
                    ServiceUrl = conversationReference.ServiceUrl
                },
                async (context, token) =>
                {
                    activity = context.Activity;
                    var userStateAccessors = userState.CreateProperty<UserDetailState>(nameof(UserDetailState));
                    userProfile = await userStateAccessors.GetAsync(context, () => new UserDetailState());

                },
                CancellationToken.None);

 

 

BotFrameworkAdapterTest Class:

 

 

 

public class BotFrameworkAdapterTest : BotFrameworkAdapter
{
public BotFrameworkAdapterTest(ICredentialProvider credentialProvider) : base(credentialProvider)
{
}

public override Task<IList<ChannelAccount>> GetConversationMembersAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
ConversationReference conversationReference = JsonConvert.DeserializeObject<ConversationReference>(File.ReadAllText(AppContext.BaseDirectory + "//TestData//ConversationReferenceTestData_Teams.json"));

IList<ChannelAccount> result = new List<ChannelAccount>()
{
new ChannelAccount()
{
AadObjectId = conversationReference.User.AadObjectId,
Id = conversationReference.User.Id,
Name = conversationReference.User.Name,
Properties = conversationReference.User.Properties,
Role = conversationReference.User.Role
}
};

return Task.FromResult(result);
}
}

 

 

 

Same I need to test using Cloud adapter by calling that middleware directly using adapter