-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreAiEventsEditModeTests.cs
More file actions
94 lines (75 loc) · 2.85 KB
/
CoreAiEventsEditModeTests.cs
File metadata and controls
94 lines (75 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using CoreAI.Ai;
using NUnit.Framework;
namespace CoreAI.Tests.EditMode
{
public sealed class CoreAiEventsEditModeTests
{
[SetUp]
public void SetUp()
{
CoreAiEvents.ClearAll();
}
[TearDown]
public void TearDown()
{
CoreAiEvents.ClearAll();
}
[Test]
public void CoreAiEvents_SubscribeAndPublish_NoPayload_TriggersCallback()
{
bool triggered = false;
CoreAiEvents.Subscribe("my_event", () => triggered = true);
CoreAiEvents.Publish("my_event");
Assert.IsTrue(triggered);
}
[Test]
public void CoreAiEvents_SubscribeAndPublish_WithPayload_TriggersCallbackWithPayload()
{
string receivedPayload = null;
CoreAiEvents.Subscribe("my_payload_event", (payload) => receivedPayload = payload);
CoreAiEvents.Publish("my_payload_event", "Hello World");
Assert.AreEqual("Hello World", receivedPayload);
}
[Test]
public void CoreAiEvents_Unsubscribe_StopsTriggering()
{
int triggerCount = 0;
Action handler = () => triggerCount++;
CoreAiEvents.Subscribe("once_event", handler);
CoreAiEvents.Publish("once_event");
CoreAiEvents.Unsubscribe("once_event", handler);
CoreAiEvents.Publish("once_event");
Assert.AreEqual(1, triggerCount);
}
[Test]
public void AgentBuilder_WithEventTool_StoresDelegateToolSuccessfully()
{
AgentConfig config = new AgentBuilder("tester")
.WithEventTool("test_event", "Triggers a test event")
.WithEventTool("test_payload_event", "Triggers with payload", true)
.Build();
Assert.AreEqual(2, config.Tools.Count);
Assert.IsInstanceOf<DelegateLlmTool>(config.Tools[0]);
Assert.IsInstanceOf<DelegateLlmTool>(config.Tools[1]);
Assert.AreEqual("test_event", config.Tools[0].Name);
Assert.AreEqual("test_payload_event", config.Tools[1].Name);
}
[Test]
public void AgentBuilder_WithAction_StoresDelegateSuccessfully()
{
int value = 0;
Action<int> addAction = (amount) => value += amount;
AgentConfig config = new AgentBuilder("action_tester")
.WithAction("add_value", "Adds value", addAction)
.Build();
Assert.AreEqual(1, config.Tools.Count);
DelegateLlmTool delTool = config.Tools[0] as DelegateLlmTool;
Assert.IsNotNull(delTool);
Assert.AreEqual("add_value", delTool.Name);
// Invoke delegate directly
delTool.ActionDelegate.DynamicInvoke(5);
Assert.AreEqual(5, value);
}
}
}