public async Task DialogTask_Frame_Scoring_Stops_At_Maximum() { var state1 = new object(); var item = new object(); var scorable1 = MockScorable(item, state1, 1.0); var scorable2 = new Mock <IScorable <object, double> >(MockBehavior.Strict); var inner = new Mock <IPostToBot>(); var stack = new Mock <IDialogStack>(); IPostToBot task = new ScoringDialogTask <double>(inner.Object, stack.Object, new TraitsScorable <object, double>(new NormalizedTraits(), Comparer <double> .Default, new[] { scorable1.Object, scorable2.Object })); stack .SetupGet(i => i.Frames) .Returns(Array.Empty <Delegate>()); var token = new CancellationToken(); scorable1 .Setup(s => s.PostAsync(item, state1, token)) .Returns(Task.FromResult(0)); await task.PostAsync(item, token); scorable1.Verify(); scorable2.Verify(); }
public static async Task DialogTask_Frame_Scoring_Throws_Out_Of_Range(double score) { var state = new object(); var item = new object(); var scorable = MockScorable(item, null, state, score); var inner = new Mock <IDialogTask>(); var task = new ScoringDialogTask <double>(inner.Object, Comparer <double> .Default, new NormalizedTraits(), scorable.Object); inner .SetupGet(i => i.Frames) .Returns(Array.Empty <Delegate>()); try { await task.PostAsync(item); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } scorable.Verify(); }
public static async Task DialogTask_Frame_Scoring_Throws_Out_Of_Range(double score) { var state = new object(); var item = new Activity(); var scorable = MockScorable(item, state, score); var inner = new Mock <IPostToBot>(); var stack = new Mock <IDialogStack>(); IPostToBot task = new ScoringDialogTask <double>(inner.Object, stack.Object, new TraitsScorable <IActivity, double>(new NormalizedTraits(), Comparer <double> .Default, new[] { scorable.Object })); stack .SetupGet(i => i.Frames) .Returns(Array.Empty <Delegate>()); try { var token = new CancellationToken(); await task.PostAsync(item, token); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } scorable.Verify(); }
public static void Register(HttpConfiguration config) { var builder = new ContainerBuilder(); builder .Register(c => new BingTranslatorClient("Test187871", "dAnT3r/eIc8KedBRUgRCV+juxpf4Wl312jn1Bd2SXzk=")) .As<ITranslator>() .InstancePerDependency(); builder .Register(c => new LogBotToUser(new MapToChannelData_BotToUser( c.Resolve<AlwaysSendDirect_BotToUser>(), new List<IMessageActivityMapper> { new KeyboardCardMapper() }), c.Resolve<IActivityLogger>())) .AsSelf() .InstancePerLifetimeScope(); builder .Register(c => new TranslatedBotToUser(c.Resolve<LogBotToUser>(), c.Resolve<ITranslator>())) .As<IBotToUser>() .InstancePerLifetimeScope(); builder .Register(c => { var cc = c.Resolve<IComponentContext>(); Func<IPostToBot> makeInner = () => { var task = cc.Resolve<DialogTask>(); IDialogStack stack = task; IPostToBot post = task; post = new ReactiveDialogTask(post, stack, cc.Resolve<IStore<IFiberLoop<DialogTask>>>(), cc.Resolve<Func<IDialog<object>>>()); post = new ExceptionTranslationDialogTask(post); post = new LocalizedDialogTask(post); post = new ScoringDialogTask<double>(post, stack, cc.Resolve<TraitsScorable<IActivity, double>>()); return post; }; IPostToBot outer = new PersistentDialogTask(makeInner, cc.Resolve<IBotData>()); outer = new SerializingDialogTask(outer, cc.Resolve<IAddress>(), c.Resolve<IScope<IAddress>>()); outer = new PostUnhandledExceptionToUserTask(outer, cc.Resolve<IBotToUser>(), cc.Resolve<ResourceManager>(), cc.Resolve<TraceListener>()); outer = new LogPostToBot(outer, cc.Resolve<IActivityLogger>()); outer = new TranslatedPostToBot(outer, cc.Resolve<ITranslator>()); return outer; }) .As<IPostToBot>() .InstancePerLifetimeScope(); builder.Update(Conversation.Container); }
public static async Task DialogTask_Frame_Scoring_Allows_Value(double score) { var state = new object(); var item = new object(); var scorable = MockScorable(item, state, score); var inner = new Mock <IPostToBot>(); IPostToBot task = new ScoringDialogTask <double>(inner.Object, new TraitsScorable <IActivity, double>(new NormalizedTraits(), Comparer <double> .Default, new[] { scorable.Object })); var token = new CancellationToken(); scorable .Setup(s => s.PostAsync(item, state, token)) .Returns(Task.FromResult(0)); await task.PostAsync(item, token); scorable.Verify(); }
public static async Task DialogTask_Frame_Scoring_Allows_Value(double score) { var state = new object(); var item = new object(); var scorable = MockScorable(item, null, state, score); var inner = new Mock <IDialogTask>(); var task = new ScoringDialogTask <double>(inner.Object, Comparer <double> .Default, new NormalizedTraits(), scorable.Object); inner .SetupGet(i => i.Frames) .Returns(Array.Empty <Delegate>()); scorable .Setup(s => s.PostAsync(inner.Object, item, state)) .Returns(Task.FromResult(0)); await task.PostAsync(item); scorable.Verify(); }
public async Task DialogTask_Frame_Scoring_Stops_At_Maximum() { var state1 = new object(); var item = new object(); var scorable1 = MockScorable(item, null, state1, 1.0); var scorable2 = new Mock <IScorable <double> >(MockBehavior.Strict); var inner = new Mock <IDialogTask>(); var task = new ScoringDialogTask <double>(inner.Object, Comparer <double> .Default, new NormalizedTraits(), scorable1.Object, scorable2.Object); inner .SetupGet(i => i.Frames) .Returns(Array.Empty <Delegate>()); scorable1 .Setup(s => s.PostAsync(inner.Object, item, state1)) .Returns(Task.FromResult(0)); await task.PostAsync(item); scorable1.Verify(); scorable2.Verify(); }
public static async Task DialogTask_Frame_Scoring_Allows_Value(double score) { var state = new object(); var item = new object(); var scorable = MockScorable(item, state, score); var inner = new Mock <IPostToBot>(); var stack = new Mock <IDialogStack>(); IPostToBot task = new ScoringDialogTask <double>(inner.Object, stack.Object, new CompositeScorable <double>(Comparer <double> .Default, new NormalizedTraits(), scorable.Object)); stack .SetupGet(i => i.Frames) .Returns(Array.Empty <Delegate>()); var token = new CancellationToken(); scorable .Setup(s => s.PostAsync(item, state, token)) .Returns(Task.FromResult(0)); await task.PostAsync(item, token); scorable.Verify(); }
protected override void Load(ContainerBuilder builder) { base.Load(builder); builder.RegisterModule(new FiberModule<DialogTask>()); // every lifetime scope is driven by a message builder .Register((c, p) => p.TypedAs<IMessageActivity>()) .AsSelf() .InstancePerMatchingLifetimeScope(LifetimeScopeTag); // components not marked as [Serializable] builder .RegisterType<MicrosoftAppCredentials>() .AsSelf() .SingleInstance(); builder .RegisterType<BotIdResolver>() .As<IBotIdResolver>() .SingleInstance(); builder .Register(c => new ConnectorClientFactory(c.Resolve<IMessageActivity>(), c.Resolve<MicrosoftAppCredentials>())) .As<IConnectorClientFactory>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve<IConnectorClientFactory>().MakeConnectorClient()) .As<IConnectorClient>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve<IConnectorClientFactory>().MakeStateClient()) .As<IStateClient>() .InstancePerLifetimeScope(); builder .Register(c => new DetectChannelCapability(c.Resolve<IMessageActivity>())) .As<IDetectChannelCapability>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve<IDetectChannelCapability>().Detect()) .As<IChannelCapability>() .InstancePerLifetimeScope(); builder.RegisterType<ConnectorStore>() .As<IBotDataStore<BotData>>() .AsSelf() .InstancePerLifetimeScope(); // If bot wants to use InMemoryDataStore instead of // ConnectorStore, the below registration should be used /*builder.RegisterType<InMemoryDataStore>() .As<IBotDataStore<BotData>>() .AsSelf() .SingleInstance(); */ builder.RegisterType<CachingBotDataStore_LastWriteWins>() .As<IBotDataStore>() .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType<JObjectBotData>() .As<IBotData>() .InstancePerLifetimeScope(); builder .Register(c => new BotDataBagStream(c.Resolve<IBotData>().PrivateConversationData, BlobKey)) .As<Stream>() .InstancePerLifetimeScope(); builder .RegisterType<DialogTask>() .AsSelf() .As<IDialogStack>() .InstancePerLifetimeScope(); // Scorable implementing "/deleteprofile" builder .RegisterType<DeleteProfileScorable>() .As<IScorable<double>>() .InstancePerLifetimeScope(); builder .Register(c => { var cc = c.Resolve<IComponentContext>(); Func<IPostToBot> makeInner = () => { var task = cc.Resolve<DialogTask>(); IDialogStack stack = task; IPostToBot post = task; post = new ReactiveDialogTask(post, stack, cc.Resolve<IStore<IFiberLoop<DialogTask>>>(), cc.Resolve<Func<IDialog<object>>>()); post = new LocalizedDialogTask(post); post = new ScoringDialogTask<double>(post, stack, cc.Resolve<IComparer<double>>(), cc.Resolve<ITraits<double>>(), cc.Resolve<IScorable<double>[]>()); return post; }; var outer = new PersistentDialogTask(makeInner, cc.Resolve<IMessageActivity>(), cc.Resolve<IConnectorClient>(), cc.Resolve<IBotToUser>(), cc.Resolve<IBotData>()); return outer; }) .As<IPostToBot>() .InstancePerLifetimeScope(); builder .RegisterType<AlwaysSendDirect_BotToUser>() .AsSelf() .As<IBotToUser>() .InstancePerLifetimeScope(); builder .RegisterType<DialogContext>() .As<IDialogContext>() .InstancePerLifetimeScope(); }
protected override void Load(ContainerBuilder builder) { base.Load(builder); builder.RegisterModule(new FiberModule<DialogTask>()); // every lifetime scope is driven by a message builder .Register((c, p) => p.TypedAs<Message>()) .AsSelf() .InstancePerMatchingLifetimeScope(LifetimeScopeTag); // components not marked as [Serializable] builder .RegisterType<ConnectorClientCredentials>() .AsSelf() .SingleInstance(); builder .Register(c => new DetectEmulatorFactory(c.Resolve<Message>(), new Uri("http://localhost:9000"), c.Resolve<ConnectorClientCredentials>())) .As<IConnectorClientFactory>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve<IConnectorClientFactory>().Make()) .As<IConnectorClient>() .InstancePerLifetimeScope(); builder .Register(c => new DetectChannelCapability(c.Resolve<Message>())) .As<IDetectChannelCapability>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve<IDetectChannelCapability>().Detect()) .As<IChannelCapability>() .InstancePerLifetimeScope(); builder.RegisterType<MessageBackedStore>() .As<IBotDataStore>() .InstancePerLifetimeScope(); builder .RegisterType<JObjectBotData>() .As<IBotData>() .InstancePerLifetimeScope(); builder .Register(c => new BotDataBagStream(c.Resolve<IBotData>().PerUserInConversationData, BlobKey)) .As<Stream>() .InstancePerLifetimeScope(); builder .RegisterType<DialogTask>() .AsSelf() .As<IDialogStack>() .InstancePerLifetimeScope(); builder .Register(c => { var cc = c.Resolve<IComponentContext>(); Func<IPostToBot> makeInner = () => { var task = cc.Resolve<DialogTask>(); IDialogStack stack = task; IPostToBot post = task; post = new ReactiveDialogTask(post, stack, cc.Resolve<IStore<IFiberLoop<DialogTask>>>(), cc.Resolve<Func<IDialog<object>>>()); post = new LocalizedDialogTask(post); post = new ScoringDialogTask<double>(post, stack, cc.Resolve<IComparer<double>>(), cc.Resolve<ITraits<double>>(), cc.Resolve<IScorable<double>[]>()); return post; }; var outer = new PersistentDialogTask(makeInner, cc.Resolve<Message>(), cc.Resolve<IConnectorClient>(), cc.Resolve<IBotToUser>(), cc.Resolve<IBotData>()); return outer; }) .As<IPostToBot>() .InstancePerLifetimeScope(); builder .RegisterType<SendLastInline_BotToUser>() .AsSelf() .As<IBotToUser>() .InstancePerLifetimeScope(); builder .RegisterType<DialogContext>() .As<IDialogContext>() .InstancePerLifetimeScope(); }