Skip to content

Commit b2334de

Browse files
committed
tried to fix the unit tests
1 parent f78425c commit b2334de

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

tests/UnitTest/MainTest.cs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using BotSharp.Abstraction.Conversations;
3-
using BotSharp.Core.Evaluations;
4-
using BotSharp.Plugin.ChatHub.Hooks;
53

64
namespace UnitTest
75
{
@@ -13,18 +11,53 @@ public void TestConversationHookProvider()
1311
{
1412
var services = new ServiceCollection();
1513

16-
services.AddSingleton<IConversationHook, EvaluationConversationHook>();
17-
services.AddSingleton<IConversationHook, WelcomeHook>();
18-
services.AddSingleton<IConversationHook, ChatHubConversationHook>();
14+
services.AddSingleton<IConversationHook, TestHookC>();
15+
services.AddSingleton<IConversationHook, TestHookA>();
16+
services.AddSingleton<IConversationHook, TestHookB>();
17+
1918
services.AddSingleton<ConversationHookProvider>();
2019

2120
var serviceProvider = services.BuildServiceProvider();
2221
var conversationHookProvider = serviceProvider.GetService<ConversationHookProvider>();
23-
22+
2423
Assert.AreEqual(3, conversationHookProvider.Hooks.Count());
2524

26-
// ChatHubConversationHook has the top priority
27-
Assert.IsInstanceOfType<ChatHubConversationHook>(conversationHookProvider.HooksOrderByPriority.FirstOrDefault());
25+
var prevHook = default(IConversationHook);
26+
27+
// Assert priority
28+
foreach (var hook in conversationHookProvider.HooksOrderByPriority)
29+
{
30+
if (prevHook != null)
31+
{
32+
Assert.IsTrue(prevHook.Priority < hook.Priority);
33+
}
34+
35+
prevHook = hook;
36+
}
37+
}
38+
39+
class TestHookA : ConversationHookBase
40+
{
41+
public TestHookA()
42+
{
43+
Priority = 1;
44+
}
45+
}
46+
47+
class TestHookB : ConversationHookBase
48+
{
49+
public TestHookA()
50+
{
51+
Priority = 2;
52+
}
53+
}
54+
55+
class TestHookC : ConversationHookBase
56+
{
57+
public TestHookA()
58+
{
59+
Priority = 3;
60+
}
2861
}
2962
}
3063
}

tests/UnitTest/UnitTest.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@
2222
</ItemGroup>
2323
<ItemGroup>
2424
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
25-
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
26-
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.ChatHub\BotSharp.Plugin.ChatHub.csproj" />
2725
</ItemGroup>
2826
</Project>

0 commit comments

Comments
 (0)