Add promt fix tests
All checks were successful
SonarQube / Build and analyze (push) Successful in 2m54s

This commit is contained in:
Leonid Pershin
2025-10-21 12:07:56 +03:00
parent ef71568579
commit 1996fec14f
18 changed files with 398 additions and 333 deletions

View File

@@ -152,25 +152,23 @@ public static class TestDataBuilder
var mock = new Mock<ISessionStorage>();
var sessions = new Dictionary<long, ChatSession>();
mock.Setup(x => x.GetOrCreate(It.IsAny<long>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns<long, string, string>(
(chatId, chatType, chatTitle) =>
mock.Setup(x => x.GetOrCreateAsync(It.IsAny<long>(), It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync((long chatId, string chatType, string chatTitle) =>
{
if (!sessions.TryGetValue(chatId, out var session))
{
if (!sessions.TryGetValue(chatId, out var session))
{
session = TestDataBuilder.ChatSessions.CreateBasicSession(
chatId,
chatType
);
session.ChatTitle = chatTitle;
sessions[chatId] = session;
}
return session;
session = TestDataBuilder.ChatSessions.CreateBasicSession(
chatId,
chatType
);
session.ChatTitle = chatTitle;
sessions[chatId] = session;
}
);
return session;
});
mock.Setup(x => x.Get(It.IsAny<long>()))
.Returns<long>(chatId =>
mock.Setup(x => x.GetAsync(It.IsAny<long>()))
.ReturnsAsync((long chatId) =>
sessions.TryGetValue(chatId, out var session) ? session : null
);
@@ -181,12 +179,12 @@ public static class TestDataBuilder
return Task.CompletedTask;
});
mock.Setup(x => x.Remove(It.IsAny<long>()))
.Returns<long>(chatId => sessions.Remove(chatId));
mock.Setup(x => x.RemoveAsync(It.IsAny<long>()))
.ReturnsAsync((long chatId) => sessions.Remove(chatId));
mock.Setup(x => x.GetActiveSessionsCount()).Returns(() => sessions.Count);
mock.Setup(x => x.GetActiveSessionsCountAsync()).ReturnsAsync(() => sessions.Count);
mock.Setup(x => x.CleanupOldSessions(It.IsAny<int>())).Returns<int>(hoursOld => 0);
mock.Setup(x => x.CleanupOldSessionsAsync(It.IsAny<int>())).ReturnsAsync((int hoursOld) => 0);
return mock;
}