Esempio n. 1
0
        public Mock <StateClient> MockIBots(MockConnectorFactory mockConnectorFactory)
        {
            var botsClient = new Moq.Mock <StateClient>(MockBehavior.Loose);

            botsClient.Setup(d => d.BotState.SetConversationDataWithHttpMessagesAsync(It.IsAny <string>(),
                                                                                      It.IsAny <string>(), It.IsAny <BotData>(), It.IsAny <Dictionary <string, List <string> > >(),
                                                                                      It.IsAny <CancellationToken>()))
            .Returns <string, string, BotData, Dictionary <string, List <string> >, CancellationToken>(
                async(channelId, conversationId, data, headers, token) =>
            {
                return(await mockConnectorFactory.UpsertData(channelId, null, conversationId,
                                                             BotStoreType.BotConversationData, data));
            });

            botsClient.Setup(d => d.BotState.GetConversationDataWithHttpMessagesAsync(It.IsAny <string>(),
                                                                                      It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns <string, string, Dictionary <string, List <string> >, CancellationToken>(
                async(channelId, conversationId, headers, token) =>
            {
                return(await mockConnectorFactory.GetData(channelId, null, conversationId,
                                                          BotStoreType.BotConversationData));
            });


            botsClient.Setup(d => d.BotState.SetUserDataWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(),
                                                                              It.IsAny <BotData>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns <string, string, BotData, Dictionary <string, List <string> >, CancellationToken>(
                async(channelId, userId, data, headers, token) =>
            {
                return(await mockConnectorFactory.UpsertData(channelId, userId, null, BotStoreType.BotUserData,
                                                             data));
            });

            botsClient.Setup(d => d.BotState.GetUserDataWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(),
                                                                              It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns <string, string, Dictionary <string, List <string> >, CancellationToken>(
                async(channelId, userId, headers, token) =>
            {
                return(await mockConnectorFactory.GetData(channelId, userId, null, BotStoreType.BotUserData));
            });

            botsClient.Setup(d => d.BotState.SetPrivateConversationDataWithHttpMessagesAsync(It.IsAny <string>(),
                                                                                             It.IsAny <string>(), It.IsAny <string>(), It.IsAny <BotData>(),
                                                                                             It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns <string, string, string, BotData, Dictionary <string, List <string> >, CancellationToken>(
                async(channelId, conversationId, userId, data, headers, token) =>
            {
                return(await mockConnectorFactory.UpsertData(channelId, userId, conversationId,
                                                             BotStoreType.BotPrivateConversationData, data));
            });

            botsClient.Setup(d => d.BotState.GetPrivateConversationDataWithHttpMessagesAsync(It.IsAny <string>(),
                                                                                             It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(),
                                                                                             It.IsAny <CancellationToken>()))
            .Returns <string, string, string, Dictionary <string, List <string> >, CancellationToken>(
                async(channelId, conversationId, userId, headers, token) =>
            {
                return(await mockConnectorFactory.GetData(channelId, userId, conversationId,
                                                          BotStoreType.BotPrivateConversationData));
            });

            return(botsClient);
        }