Dec 21 2022 04:04 AM
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
Dec 21 2022 08:56 PM
Dec 27 2022 03:04 AM - edited Dec 29 2022 02:05 AM
@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...
Dec 29 2022 01:56 AM
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
Jan 20 2023 02:24 AM - edited Jan 20 2023 02:31 AM
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?
Jan 20 2023 06:58 AM - edited Jan 20 2023 07:01 AM
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