tried to fix the unit tests
This commit is contained in:
parent
f78425cffa
commit
b2334decff
|
|
@ -1,7 +1,5 @@
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using BotSharp.Abstraction.Conversations;
|
using BotSharp.Abstraction.Conversations;
|
||||||
using BotSharp.Core.Evaluations;
|
|
||||||
using BotSharp.Plugin.ChatHub.Hooks;
|
|
||||||
|
|
||||||
namespace UnitTest
|
namespace UnitTest
|
||||||
{
|
{
|
||||||
|
|
@ -13,18 +11,53 @@ namespace UnitTest
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
|
|
||||||
services.AddSingleton<IConversationHook, EvaluationConversationHook>();
|
services.AddSingleton<IConversationHook, TestHookC>();
|
||||||
services.AddSingleton<IConversationHook, WelcomeHook>();
|
services.AddSingleton<IConversationHook, TestHookA>();
|
||||||
services.AddSingleton<IConversationHook, ChatHubConversationHook>();
|
services.AddSingleton<IConversationHook, TestHookB>();
|
||||||
|
|
||||||
services.AddSingleton<ConversationHookProvider>();
|
services.AddSingleton<ConversationHookProvider>();
|
||||||
|
|
||||||
var serviceProvider = services.BuildServiceProvider();
|
var serviceProvider = services.BuildServiceProvider();
|
||||||
var conversationHookProvider = serviceProvider.GetService<ConversationHookProvider>();
|
var conversationHookProvider = serviceProvider.GetService<ConversationHookProvider>();
|
||||||
|
|
||||||
Assert.AreEqual(3, conversationHookProvider.Hooks.Count());
|
Assert.AreEqual(3, conversationHookProvider.Hooks.Count());
|
||||||
|
|
||||||
// ChatHubConversationHook has the top priority
|
var prevHook = default(IConversationHook);
|
||||||
Assert.IsInstanceOfType<ChatHubConversationHook>(conversationHookProvider.HooksOrderByPriority.FirstOrDefault());
|
|
||||||
|
// Assert priority
|
||||||
|
foreach (var hook in conversationHookProvider.HooksOrderByPriority)
|
||||||
|
{
|
||||||
|
if (prevHook != null)
|
||||||
|
{
|
||||||
|
Assert.IsTrue(prevHook.Priority < hook.Priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
prevHook = hook;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestHookA : ConversationHookBase
|
||||||
|
{
|
||||||
|
public TestHookA()
|
||||||
|
{
|
||||||
|
Priority = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestHookB : ConversationHookBase
|
||||||
|
{
|
||||||
|
public TestHookA()
|
||||||
|
{
|
||||||
|
Priority = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestHookC : ConversationHookBase
|
||||||
|
{
|
||||||
|
public TestHookA()
|
||||||
|
{
|
||||||
|
Priority = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +22,5 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
||||||
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
|
||||||
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.ChatHub\BotSharp.Plugin.ChatHub.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue