public Mock <OAuthClient> MockOAuthClient(MockConnectorFactory mockConnectorFactory) { var botsClient = new Moq.Mock <OAuthClient>(MockBehavior.Loose); botsClient.Setup(d => d.OAuthApi.GetSignInLinkAsync(It.IsAny <IActivity>(), It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns <IActivity, string, CancellationToken>(async(activity, connectionName, token) => { return("http://www.cnn.com"); }); botsClient.Setup(d => d.GetOAuthApiEx().GetUserTokenAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns <string, string, string, string, CancellationToken>(async(channelId, userId, connectionName, magicCode, token) => { return(new TokenResponse() { Token = "HappyToken", ConnectionName = connectionName }); }); botsClient.Setup(d => d.OAuthApi.SendEmulateOAuthCardsAsync(It.IsAny <bool>())) .Returns <bool>(async(value) => { }); botsClient.Setup(d => d.GetOAuthApiEx().SignOutUserAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns <string, string, string, CancellationToken>(async(channelId, userId, connectionName, token) => { return(true); }); return(botsClient); }
public static IContainer Build(Options options, MockConnectorFactory mockConnectorFactory, params object[] singletons) { var builder = new ContainerBuilder(); builder.RegisterModule(new DialogModule_MakeRoot()); builder .Register((c, p) => mockConnectorFactory) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); if (options.HasFlag(Options.InMemoryBotDataStore)) { //Note: memory store will be single instance for the bot builder.RegisterType <InMemoryBotDataStore>() .As <IBotDataStore>() .SingleInstance(); } foreach (var singleton in singletons) { builder .Register(c => singleton) .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType()); } return(builder.Build()); }
public static IContainer Build(Options options, params object[] singletons) { var builder = new ContainerBuilder(); builder.RegisterModule(new DialogModule_MakeRoot()); // make a "singleton" MockConnectorFactory per unit test execution IConnectorClientFactory factory = null; builder .Register((c, p) => factory ?? (factory = new MockConnectorFactory(c.Resolve <IAddress>().BotId))) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); var r = builder .Register <Queue <IMessageActivity> >(c => new Queue <IMessageActivity>()) .AsSelf() .InstancePerLifetimeScope(); // truncate AlwaysSendDirect_BotToUser/IConnectorClient with null implementation builder .RegisterType <BotToUserQueue>() .Keyed <IBotToUser>(typeof(AlwaysSendDirect_BotToUser)) .InstancePerLifetimeScope(); if (options.HasFlag(Options.InMemoryBotDataStore)) { //Note: memory store will be single instance for the bot builder.RegisterType <InMemoryDataStore>() .AsSelf() .SingleInstance(); builder.Register(c => new CachingBotDataStore(c.Resolve <InMemoryDataStore>(), CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency)) .As <IBotDataStore <BotData> >() .AsSelf() .InstancePerLifetimeScope(); } if (options.HasFlag(Options.NeedsInputHint)) { builder.Register(c => new AlwaysNeedInputHintChannelCapability(new ChannelCapability(c.Resolve <IAddress>()))) .AsImplementedInterfaces() .InstancePerLifetimeScope(); } foreach (var singleton in singletons) { builder .Register(c => singleton) .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType()); } return(builder.Build()); }
public static IContainer Build(Options options, MockConnectorFactory mockConnectorFactory, params object[] singletons) { var builder = new ContainerBuilder(); builder.RegisterModule(new DialogModule_MakeRoot()); builder .Register((c, p) => mockConnectorFactory) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); builder .Register(c => new BotIdResolver("testBot")) .As <IBotIdResolver>() .SingleInstance(); var r = builder .Register <Queue <IMessageActivity> >(c => new Queue <IMessageActivity>()) .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType <BotToUserQueue>() .AsSelf() .As <IBotToUser>() .InstancePerLifetimeScope(); if (options.HasFlag(Options.InMemoryBotDataStore)) { //Note: memory store will be single instance for the bot builder.RegisterType <InMemoryDataStore>() .AsSelf() .SingleInstance(); builder.Register(c => new CachingBotDataStore(c.Resolve <InMemoryDataStore>(), CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency)) .As <IBotDataStore <BotData> >() .AsSelf() .InstancePerLifetimeScope(); } foreach (var singleton in singletons) { builder .Register(c => singleton) .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType()); } return(builder.Build()); }
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); }
public static IContainer Build(MockConnectorFactory mockConnectorFactory, params object[] singletons) { var builder = new ContainerBuilder(); builder.RegisterModule(new DialogModule_MakeRoot()); builder .Register((c, p) => mockConnectorFactory) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); foreach (var singleton in singletons) { builder .Register(c => singleton) .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType()); } return(builder.Build()); }
public static Mock <IBots> MockIBots(MockConnectorFactory mockConnectorFactory) { var botsClient = new Moq.Mock <IBots>(MockBehavior.Loose); botsClient.Setup(d => d.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(botId, conversationId, data, headers, token) => { return(mockConnectorFactory.UpsertData(botId, null, conversationId, data)); }); botsClient.Setup(d => d.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(botId, conversationId, headers, token) => { return(mockConnectorFactory.GetData(botId, null, conversationId)); }); botsClient.Setup(d => d.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(botId, userId, data, headers, token) => { return(mockConnectorFactory.UpsertData(botId, userId, null, data)); }); botsClient.Setup(d => d.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(botId, userId, headers, token) => { return(mockConnectorFactory.GetData(botId, userId, null)); }); botsClient.Setup(d => d.SetPerUserInConversationDataWithHttpMessagesAsync(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(botId, conversationId, userId, data, headers, token) => { return(mockConnectorFactory.UpsertData(botId, userId, conversationId, data)); }); botsClient.Setup(d => d.GetPerUserConversationDataWithHttpMessagesAsync(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(botId, conversationId, userId, headers, token) => { return(mockConnectorFactory.GetData(botId, userId, conversationId)); }); return(botsClient); }
public static IContainer Build(Options options, params object[] singletons) { var builder = new ContainerBuilder(); if (options.HasFlag(Options.ResolveDialogFromContainer)) { builder.RegisterModule(new DialogModule()); } else { builder.RegisterModule(new DialogModule_MakeRoot()); } // make a "singleton" MockConnectorFactory per unit test execution IConnectorClientFactory factory = null; builder .Register((c, p) => factory ?? (factory = new MockConnectorFactory(c.Resolve <IAddress>().BotId))) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); if (options.HasFlag(Options.Reflection)) { builder.RegisterModule(new ReflectionSurrogateModule()); } var r = builder .Register <Queue <IMessageActivity> >(c => new Queue <IMessageActivity>()) .AsSelf(); if (options.HasFlag(Options.ScopedQueue)) { r.InstancePerLifetimeScope(); } else { r.SingleInstance(); } builder .RegisterType <BotToUserQueue>() .AsSelf() .InstancePerLifetimeScope(); builder .Register(c => new MapToChannelData_BotToUser( c.Resolve <BotToUserQueue>(), new List <IMessageActivityMapper> { new KeyboardCardMapper() })) .As <IBotToUser>() .InstancePerLifetimeScope(); if (options.HasFlag(Options.LastWriteWinsCachingBotDataStore)) { builder.Register <CachingBotDataStore>(c => new CachingBotDataStore(c.ResolveKeyed <IBotDataStore <BotData> >(typeof(ConnectorStore)), CachingBotDataStoreConsistencyPolicy.LastWriteWins)) .As <IBotDataStore <BotData> >() .AsSelf() .InstancePerLifetimeScope(); } foreach (var singleton in singletons) { builder .Register(c => singleton) .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType()); } return(builder.Build()); }
public static IContainer Build(Options options, MockConnectorFactory mockConnectorFactory, params object[] singletons) { var builder = new ContainerBuilder(); builder.RegisterModule(new DialogModule_MakeRoot()); builder .Register((c, p) => mockConnectorFactory) .As<IConnectorClientFactory>() .InstancePerLifetimeScope(); builder .Register(c => new BotIdResolver("testBot")) .As<IBotIdResolver>() .SingleInstance(); var r = builder .Register<Queue<IMessageActivity>>(c => new Queue<IMessageActivity>()) .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType<BotToUserQueue>() .AsSelf() .As<IBotToUser>() .InstancePerLifetimeScope(); if (options.HasFlag(Options.InMemoryBotDataStore)) { //Note: memory store will be single instance for the bot builder.RegisterType<InMemoryDataStore>() .As<IBotDataStore<BotData>>() .AsSelf() .SingleInstance(); } foreach (var singleton in singletons) { builder .Register(c => singleton) .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType()); } return builder.Build(); }
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 mockConnectorFactory.UpsertData(botIdResolver.BotId, null, $"{channelId}-{conversationId}", 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 mockConnectorFactory.GetData(botIdResolver.BotId, null, $"{channelId}-{conversationId}"); }); 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 mockConnectorFactory.UpsertData(botIdResolver.BotId, $"{channelId}-{userId}", null, 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 mockConnectorFactory.GetData(botIdResolver.BotId, $"{channelId}-{userId}", null); }); 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 mockConnectorFactory.UpsertData(botIdResolver.BotId, $"{channelId}-{userId}", $"{channelId}-{conversationId}", 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 mockConnectorFactory.GetData(botIdResolver.BotId, $"{channelId}-{userId}", $"{channelId}-{conversationId}"); }); return botsClient; }