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(); 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(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()); }