Skip to content

Commit 7c7e7ed

Browse files
committed
tests: fix tests
- register test model before each test
1 parent af92205 commit 7c7e7ed

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/MaIN.Core.UnitTests/AgentContextTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using MaIN.Domain.Entities.Agents;
44
using MaIN.Domain.Entities.Agents.Knowledge;
55
using MaIN.Domain.Exceptions.Agents;
6+
using MaIN.Domain.Models.Abstract;
67
using MaIN.Services.Services.Abstract;
78
using MaIN.Services.Services.Models;
89
using Moq;
@@ -13,11 +14,14 @@ public class AgentContextTests
1314
{
1415
private readonly Mock<IAgentService> _mockAgentService;
1516
private readonly AgentContext _agentContext;
17+
private readonly string _testModelId = "test-model";
1618

1719
public AgentContextTests()
1820
{
1921
_mockAgentService = new Mock<IAgentService>();
2022
_agentContext = new AgentContext(_mockAgentService.Object);
23+
var testModel = new GenericLocalModel(_testModelId);
24+
ModelRegistry.RegisterOrReplace(testModel);
2125
}
2226

2327
[Fact]
@@ -159,7 +163,7 @@ public async Task ProcessAsync_WithStringMessage_ShouldReturnChatResult()
159163
{
160164
// Arrange
161165
var message = "Hello, agent!";
162-
var chat = new Chat { Id = _agentContext.GetAgentId(), Messages = new List<Message>(), Name = "test", ModelId = "default"};
166+
var chat = new Chat { Id = _agentContext.GetAgentId(), Messages = new List<Message>(), Name = "test", ModelId = _testModelId};
163167
var chatResult = new ChatResult { Done = true, Model = "test-model", Message = new Message
164168
{
165169
Role = "Assistant",

src/MaIN.Core.UnitTests/ChatContextTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ public class ChatContextTests
1212
{
1313
private readonly Mock<IChatService> _mockChatService;
1414
private readonly ChatContext _chatContext;
15+
private readonly string _testModelId = "test-model";
1516

1617
public ChatContextTests()
1718
{
1819
_mockChatService = new Mock<IChatService>();
1920
_chatContext = new ChatContext(_mockChatService.Object);
21+
var testModel = new GenericLocalModel(_testModelId);
22+
ModelRegistry.RegisterOrReplace(testModel);
2023
}
2124

2225
[Fact]
@@ -103,7 +106,7 @@ public async Task CompleteAsync_ShouldCallChatService()
103106
public async Task GetCurrentChat_ShouldCallChatService()
104107
{
105108
// Arrange
106-
var chat = new Chat { Id = _chatContext.GetChatId(), ModelId = "default", Name = "test"};
109+
var chat = new Chat { Id = _chatContext.GetChatId(), ModelId = _testModelId , Name = "test"};
107110
_mockChatService.Setup(s => s.GetById(chat.Id)).ReturnsAsync(chat);
108111

109112
// Act
@@ -117,14 +120,14 @@ public async Task GetCurrentChat_ShouldCallChatService()
117120
public async Task WithModel_ShouldSetModelIdAndInstance()
118121
{
119122
// Arrange
120-
var model = new GenericLocalModel("default");
123+
var model = new GenericLocalModel(_testModelId);
121124

122125
// Act
123126
await _chatContext.WithModel(model)
124127
.WithMessage("User message")
125128
.CompleteAsync();
126129

127130
// Assert
128-
_mockChatService.Verify(s => s.Completions(It.Is<Chat>(c => c.ModelId == "default" && c.ModelInstance == model), It.IsAny<bool>(), It.IsAny<bool>(), null), Times.Once);
131+
_mockChatService.Verify(s => s.Completions(It.Is<Chat>(c => c.ModelId == _testModelId && c.ModelInstance == model), It.IsAny<bool>(), It.IsAny<bool>(), null), Times.Once);
129132
}
130133
}

src/MaIN.Core.UnitTests/FlowContextTests.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using MaIN.Core.Hub.Contexts;
22
using MaIN.Domain.Entities;
33
using MaIN.Domain.Entities.Agents;
4-
using MaIN.Services.Services.Abstract;
5-
using Moq;
64
using MaIN.Domain.Entities.Agents.AgentSource;
75
using MaIN.Domain.Entities.Agents.Knowledge;
86
using MaIN.Domain.Exceptions.Flows;
7+
using MaIN.Domain.Models.Abstract;
8+
using MaIN.Services.Services.Abstract;
9+
using Moq;
910

1011
namespace MaIN.Core.UnitTests;
1112

@@ -14,12 +15,15 @@ public class FlowContextTests
1415
private readonly Mock<IAgentFlowService> _mockFlowService;
1516
private readonly Mock<IAgentService> _mockAgentService;
1617
private FlowContext _flowContext;
18+
private readonly string _testModelId = "test-model";
1719

1820
public FlowContextTests()
1921
{
2022
_mockFlowService = new Mock<IAgentFlowService>();
2123
_mockAgentService = new Mock<IAgentService>();
2224
_flowContext = new FlowContext(_mockFlowService.Object, _mockAgentService.Object);
25+
var testModel = new GenericLocalModel(_testModelId);
26+
ModelRegistry.RegisterOrReplace(testModel);
2327
}
2428

2529
[Fact]
@@ -92,7 +96,7 @@ public async Task ProcessAsync_WithStringMessage_ShouldReturnChatResult()
9296
_flowContext.AddAgent(firstAgent);
9397

9498
var message = "Hello, flow!";
95-
var chat = new Chat { Id = firstAgent.Id, Messages = new List<Message>(), ModelId = "default", Name = "test"};
99+
var chat = new Chat { Id = firstAgent.Id, Messages = new List<Message>(), ModelId = _testModelId, Name = "test"};
96100

97101
_mockAgentService
98102
.Setup(s => s.GetChatByAgent(firstAgent.Id))
@@ -101,7 +105,7 @@ public async Task ProcessAsync_WithStringMessage_ShouldReturnChatResult()
101105
_mockAgentService
102106
.Setup(s => s.Process(It.IsAny<Chat>(), firstAgent.Id, It.IsAny<Knowledge>(), It.IsAny<bool>(), null, null))
103107
.ReturnsAsync(new Chat {
104-
ModelId = "test-model",
108+
ModelId = _testModelId,
105109
Name = "test",
106110
Messages = new List<Message> {
107111
new() { Content = "Response", Role = "Assistant", Type = MessageType.LocalLLM}
@@ -113,7 +117,7 @@ public async Task ProcessAsync_WithStringMessage_ShouldReturnChatResult()
113117

114118
// Assert
115119
Assert.True(result.Done);
116-
Assert.Equal("test-model", result.Model);
120+
Assert.Equal(_testModelId, result.Model);
117121
Assert.NotNull(result.Message);
118122
}
119123

0 commit comments

Comments
 (0)