fix tests
Some checks failed
SonarQube / Build and analyze (push) Failing after 1m44s
Unit Tests / Run Tests (push) Failing after 1m7s

This commit is contained in:
Leonid Pershin
2025-10-20 10:39:58 +03:00
parent f4892efbb5
commit 1d0ebfeeb7
10 changed files with 73 additions and 74 deletions

View File

@@ -392,7 +392,7 @@ public class AIResponseConstantsTests
_ => typeof(object),
};
emptyMarkerType.Should().Be(typeof(string));
emptyMarkerType.Should().Be<string>();
}
[Fact]

View File

@@ -345,28 +345,28 @@ public class ChatTypesTests
"private" => typeof(string),
_ => typeof(object),
};
privateType.Should().Be(typeof(string));
privateType.Should().Be<string>();
var groupType = ChatTypes.Group switch
{
"group" => typeof(string),
_ => typeof(object),
};
groupType.Should().Be(typeof(string));
groupType.Should().Be<string>();
var superGroupType = ChatTypes.SuperGroup switch
{
"supergroup" => typeof(string),
_ => typeof(object),
};
superGroupType.Should().Be(typeof(string));
superGroupType.Should().Be<string>();
var channelType = ChatTypes.Channel switch
{
"channel" => typeof(string),
_ => typeof(object),
};
channelType.Should().Be(typeof(string));
channelType.Should().Be<string>();
}
[Fact]

View File

@@ -22,72 +22,72 @@ public class IChatSessionRepositoryTests : UnitTestBase
// GetOrCreateAsync method
var getOrCreateAsyncMethod = methods.FirstOrDefault(m => m.Name == "GetOrCreateAsync");
getOrCreateAsyncMethod.Should().NotBeNull();
getOrCreateAsyncMethod!.ReturnType.Should().Be(typeof(Task<ChatSessionEntity>));
getOrCreateAsyncMethod!.ReturnType.Should().Be<Task<ChatSessionEntity>>();
getOrCreateAsyncMethod.GetParameters().Should().HaveCount(3);
getOrCreateAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(long));
getOrCreateAsyncMethod.GetParameters()[1].ParameterType.Should().Be(typeof(string));
getOrCreateAsyncMethod.GetParameters()[2].ParameterType.Should().Be(typeof(string));
getOrCreateAsyncMethod.GetParameters()[0].ParameterType.Should().Be<long>();
getOrCreateAsyncMethod.GetParameters()[1].ParameterType.Should().Be<string>();
getOrCreateAsyncMethod.GetParameters()[2].ParameterType.Should().Be<string>();
// GetByChatIdAsync method
var getByChatIdAsyncMethod = methods.FirstOrDefault(m => m.Name == "GetByChatIdAsync");
getByChatIdAsyncMethod.Should().NotBeNull();
getByChatIdAsyncMethod!.ReturnType.Should().Be(typeof(Task<ChatSessionEntity?>));
getByChatIdAsyncMethod!.ReturnType.Should().Be<Task<ChatSessionEntity?>>();
getByChatIdAsyncMethod.GetParameters().Should().HaveCount(1);
getByChatIdAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(long));
getByChatIdAsyncMethod.GetParameters()[0].ParameterType.Should().Be<long>();
// GetBySessionIdAsync method
var getBySessionIdAsyncMethod = methods.FirstOrDefault(m =>
m.Name == "GetBySessionIdAsync"
);
getBySessionIdAsyncMethod.Should().NotBeNull();
getBySessionIdAsyncMethod!.ReturnType.Should().Be(typeof(Task<ChatSessionEntity?>));
getBySessionIdAsyncMethod!.ReturnType.Should().Be<Task<ChatSessionEntity?>>();
getBySessionIdAsyncMethod.GetParameters().Should().HaveCount(1);
getBySessionIdAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(string));
getBySessionIdAsyncMethod.GetParameters()[0].ParameterType.Should().Be<string>();
// UpdateAsync method
var updateAsyncMethod = methods.FirstOrDefault(m => m.Name == "UpdateAsync");
updateAsyncMethod.Should().NotBeNull();
updateAsyncMethod!.ReturnType.Should().Be(typeof(Task<ChatSessionEntity>));
updateAsyncMethod!.ReturnType.Should().Be<Task<ChatSessionEntity>>();
updateAsyncMethod.GetParameters().Should().HaveCount(1);
updateAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(ChatSessionEntity));
updateAsyncMethod.GetParameters()[0].ParameterType.Should().Be<ChatSessionEntity>();
// DeleteAsync method
var deleteAsyncMethod = methods.FirstOrDefault(m => m.Name == "DeleteAsync");
deleteAsyncMethod.Should().NotBeNull();
deleteAsyncMethod!.ReturnType.Should().Be(typeof(Task<bool>));
deleteAsyncMethod!.ReturnType.Should().Be<Task<bool>>();
deleteAsyncMethod.GetParameters().Should().HaveCount(1);
deleteAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(long));
deleteAsyncMethod.GetParameters()[0].ParameterType.Should().Be<long>();
// GetMessagesAsync method
var getMessagesAsyncMethod = methods.FirstOrDefault(m => m.Name == "GetMessagesAsync");
getMessagesAsyncMethod.Should().NotBeNull();
getMessagesAsyncMethod!.ReturnType.Should().Be(typeof(Task<List<ChatMessageEntity>>));
getMessagesAsyncMethod!.ReturnType.Should().Be<Task<List<ChatMessageEntity>>>();
getMessagesAsyncMethod.GetParameters().Should().HaveCount(1);
getMessagesAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(int));
getMessagesAsyncMethod.GetParameters()[0].ParameterType.Should().Be<int>();
// AddMessageAsync method
var addMessageAsyncMethod = methods.FirstOrDefault(m => m.Name == "AddMessageAsync");
addMessageAsyncMethod.Should().NotBeNull();
addMessageAsyncMethod!.ReturnType.Should().Be(typeof(Task<ChatMessageEntity>));
addMessageAsyncMethod!.ReturnType.Should().Be<Task<ChatMessageEntity>>();
addMessageAsyncMethod.GetParameters().Should().HaveCount(4);
addMessageAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(int));
addMessageAsyncMethod.GetParameters()[1].ParameterType.Should().Be(typeof(string));
addMessageAsyncMethod.GetParameters()[2].ParameterType.Should().Be(typeof(string));
addMessageAsyncMethod.GetParameters()[3].ParameterType.Should().Be(typeof(int));
addMessageAsyncMethod.GetParameters()[0].ParameterType.Should().Be<int>();
addMessageAsyncMethod.GetParameters()[1].ParameterType.Should().Be<string>();
addMessageAsyncMethod.GetParameters()[2].ParameterType.Should().Be<string>();
addMessageAsyncMethod.GetParameters()[3].ParameterType.Should().Be<int>();
// ClearMessagesAsync method
var clearMessagesAsyncMethod = methods.FirstOrDefault(m => m.Name == "ClearMessagesAsync");
clearMessagesAsyncMethod.Should().NotBeNull();
clearMessagesAsyncMethod!.ReturnType.Should().Be(typeof(Task));
clearMessagesAsyncMethod!.ReturnType.Should().Be<Task>();
clearMessagesAsyncMethod.GetParameters().Should().HaveCount(1);
clearMessagesAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(int));
clearMessagesAsyncMethod.GetParameters()[0].ParameterType.Should().Be<int>();
// GetActiveSessionsCountAsync method
var getActiveSessionsCountAsyncMethod = methods.FirstOrDefault(m =>
m.Name == "GetActiveSessionsCountAsync"
);
getActiveSessionsCountAsyncMethod.Should().NotBeNull();
getActiveSessionsCountAsyncMethod!.ReturnType.Should().Be(typeof(Task<int>));
getActiveSessionsCountAsyncMethod!.ReturnType.Should().Be<Task<int>>();
getActiveSessionsCountAsyncMethod.GetParameters().Should().BeEmpty();
// CleanupOldSessionsAsync method
@@ -95,20 +95,18 @@ public class IChatSessionRepositoryTests : UnitTestBase
m.Name == "CleanupOldSessionsAsync"
);
cleanupOldSessionsAsyncMethod.Should().NotBeNull();
cleanupOldSessionsAsyncMethod!.ReturnType.Should().Be(typeof(Task<int>));
cleanupOldSessionsAsyncMethod!.ReturnType.Should().Be<Task<int>>();
cleanupOldSessionsAsyncMethod.GetParameters().Should().HaveCount(1);
cleanupOldSessionsAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(int));
cleanupOldSessionsAsyncMethod.GetParameters()[0].ParameterType.Should().Be<int>();
// GetSessionsForCleanupAsync method
var getSessionsForCleanupAsyncMethod = methods.FirstOrDefault(m =>
m.Name == "GetSessionsForCleanupAsync"
);
getSessionsForCleanupAsyncMethod.Should().NotBeNull();
getSessionsForCleanupAsyncMethod!
.ReturnType.Should()
.Be(typeof(Task<List<ChatSessionEntity>>));
getSessionsForCleanupAsyncMethod!.ReturnType.Should().Be<Task<List<ChatSessionEntity>>>();
getSessionsForCleanupAsyncMethod.GetParameters().Should().HaveCount(1);
getSessionsForCleanupAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(int));
getSessionsForCleanupAsyncMethod.GetParameters()[0].ParameterType.Should().Be<int>();
}
[Fact]

View File

@@ -160,10 +160,10 @@ public class MigrationsTests : IDisposable
var foreignKeys = chatMessageEntity.GetForeignKeys();
foreignKeys.Should().HaveCount(1);
var foreignKey = foreignKeys.First();
var foreignKey = foreignKeys[0];
foreignKey.PrincipalEntityType.Should().Be(chatSessionEntity);
foreignKey.Properties.Should().HaveCount(1);
foreignKey.Properties.First().Name.Should().Be("SessionId");
foreignKey.Properties[0].Name.Should().Be("SessionId");
foreignKey.DeleteBehavior.Should().Be(DeleteBehavior.Cascade);
}
@@ -330,5 +330,6 @@ public class MigrationsTests : IDisposable
{
_dbContext?.Dispose();
_serviceProvider?.Dispose();
GC.SuppressFinalize(this);
}
}

View File

@@ -22,31 +22,31 @@ public class IAIServiceTests : UnitTestBase
m.Name == "GenerateChatCompletionAsync"
);
generateChatCompletionMethod.Should().NotBeNull();
generateChatCompletionMethod!.ReturnType.Should().Be(typeof(Task<string>));
generateChatCompletionMethod!.ReturnType.Should().Be<Task<string>>();
generateChatCompletionMethod.GetParameters().Should().HaveCount(2);
generateChatCompletionMethod
.GetParameters()[0]
.ParameterType.Should()
.Be(typeof(List<ChatMessage>));
.Be<List<ChatMessage>>();
generateChatCompletionMethod
.GetParameters()[1]
.ParameterType.Should()
.Be(typeof(CancellationToken));
.Be<CancellationToken>();
var generateChatCompletionWithCompressionMethod = methods.FirstOrDefault(m =>
m.Name == "GenerateChatCompletionWithCompressionAsync"
);
generateChatCompletionWithCompressionMethod.Should().NotBeNull();
generateChatCompletionWithCompressionMethod!.ReturnType.Should().Be(typeof(Task<string>));
generateChatCompletionWithCompressionMethod!.ReturnType.Should().Be<Task<string>>();
generateChatCompletionWithCompressionMethod.GetParameters().Should().HaveCount(2);
generateChatCompletionWithCompressionMethod
.GetParameters()[0]
.ParameterType.Should()
.Be(typeof(List<ChatMessage>));
.Be<List<ChatMessage>>();
generateChatCompletionWithCompressionMethod
.GetParameters()[1]
.ParameterType.Should()
.Be(typeof(CancellationToken));
.Be<CancellationToken>();
}
[Fact]

View File

@@ -24,25 +24,25 @@ public class IHistoryCompressionServiceTests : UnitTestBase
m.Name == "CompressHistoryAsync"
);
compressHistoryAsyncMethod.Should().NotBeNull();
compressHistoryAsyncMethod!.ReturnType.Should().Be(typeof(Task<List<ChatMessage>>));
compressHistoryAsyncMethod!.ReturnType.Should().Be<Task<List<ChatMessage>>>();
compressHistoryAsyncMethod.GetParameters().Should().HaveCount(3);
compressHistoryAsyncMethod
.GetParameters()[0]
.ParameterType.Should()
.Be(typeof(List<ChatMessage>));
compressHistoryAsyncMethod.GetParameters()[1].ParameterType.Should().Be(typeof(int));
.Be<List<ChatMessage>>();
compressHistoryAsyncMethod.GetParameters()[1].ParameterType.Should().Be<int>();
compressHistoryAsyncMethod
.GetParameters()[2]
.ParameterType.Should()
.Be(typeof(CancellationToken));
.Be<CancellationToken>();
// ShouldCompress method
var shouldCompressMethod = methods.FirstOrDefault(m => m.Name == "ShouldCompress");
shouldCompressMethod.Should().NotBeNull();
shouldCompressMethod!.ReturnType.Should().Be(typeof(bool));
shouldCompressMethod!.ReturnType.Should().Be<bool>();
shouldCompressMethod.GetParameters().Should().HaveCount(2);
shouldCompressMethod.GetParameters()[0].ParameterType.Should().Be(typeof(int));
shouldCompressMethod.GetParameters()[1].ParameterType.Should().Be(typeof(int));
shouldCompressMethod.GetParameters()[0].ParameterType.Should().Be<int>();
shouldCompressMethod.GetParameters()[1].ParameterType.Should().Be<int>();
}
[Fact]

View File

@@ -25,23 +25,23 @@ public class IOllamaClientTests : UnitTestBase
// SelectedModel property
var selectedModelProperty = properties.FirstOrDefault(p => p.Name == "SelectedModel");
selectedModelProperty.Should().NotBeNull();
selectedModelProperty!.PropertyType.Should().Be(typeof(string));
selectedModelProperty!.PropertyType.Should().Be<string>();
selectedModelProperty.CanRead.Should().BeTrue();
selectedModelProperty.CanWrite.Should().BeTrue();
// ChatAsync method
var chatAsyncMethod = methods.FirstOrDefault(m => m.Name == "ChatAsync");
chatAsyncMethod.Should().NotBeNull();
chatAsyncMethod!.ReturnType.Should().Be(typeof(IAsyncEnumerable<ChatResponseStream?>));
chatAsyncMethod!.ReturnType.Should().Be<IAsyncEnumerable<ChatResponseStream?>>();
chatAsyncMethod.GetParameters().Should().HaveCount(1);
chatAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(ChatRequest));
chatAsyncMethod.GetParameters()[0].ParameterType.Should().Be<ChatRequest>();
// ListLocalModelsAsync method
var listLocalModelsAsyncMethod = methods.FirstOrDefault(m =>
m.Name == "ListLocalModelsAsync"
);
listLocalModelsAsyncMethod.Should().NotBeNull();
listLocalModelsAsyncMethod!.ReturnType.Should().Be(typeof(Task<IEnumerable<Model>>));
listLocalModelsAsyncMethod!.ReturnType.Should().Be<Task<IEnumerable<Model>>>();
listLocalModelsAsyncMethod.GetParameters().Should().BeEmpty();
}

View File

@@ -22,47 +22,47 @@ public class ISessionStorageTests : UnitTestBase
// GetOrCreate method
var getOrCreateMethod = methods.FirstOrDefault(m => m.Name == "GetOrCreate");
getOrCreateMethod.Should().NotBeNull();
getOrCreateMethod!.ReturnType.Should().Be(typeof(ChatSession));
getOrCreateMethod!.ReturnType.Should().Be<ChatSession>();
getOrCreateMethod.GetParameters().Should().HaveCount(3);
getOrCreateMethod.GetParameters()[0].ParameterType.Should().Be(typeof(long));
getOrCreateMethod.GetParameters()[1].ParameterType.Should().Be(typeof(string));
getOrCreateMethod.GetParameters()[2].ParameterType.Should().Be(typeof(string));
getOrCreateMethod.GetParameters()[0].ParameterType.Should().Be<long>();
getOrCreateMethod.GetParameters()[1].ParameterType.Should().Be<string>();
getOrCreateMethod.GetParameters()[2].ParameterType.Should().Be<string>();
// Get method
var getMethod = methods.FirstOrDefault(m => m.Name == "Get");
getMethod.Should().NotBeNull();
getMethod!.ReturnType.Should().Be(typeof(ChatSession));
getMethod!.ReturnType.Should().Be<ChatSession>();
getMethod.GetParameters().Should().HaveCount(1);
getMethod.GetParameters()[0].ParameterType.Should().Be(typeof(long));
getMethod.GetParameters()[0].ParameterType.Should().Be<long>();
// Remove method
var removeMethod = methods.FirstOrDefault(m => m.Name == "Remove");
removeMethod.Should().NotBeNull();
removeMethod!.ReturnType.Should().Be(typeof(bool));
removeMethod!.ReturnType.Should().Be<bool>();
removeMethod.GetParameters().Should().HaveCount(1);
removeMethod.GetParameters()[0].ParameterType.Should().Be(typeof(long));
removeMethod.GetParameters()[0].ParameterType.Should().Be<long>();
// GetActiveSessionsCount method
var getActiveSessionsCountMethod = methods.FirstOrDefault(m =>
m.Name == "GetActiveSessionsCount"
);
getActiveSessionsCountMethod.Should().NotBeNull();
getActiveSessionsCountMethod!.ReturnType.Should().Be(typeof(int));
getActiveSessionsCountMethod!.ReturnType.Should().Be<int>();
getActiveSessionsCountMethod.GetParameters().Should().BeEmpty();
// CleanupOldSessions method
var cleanupOldSessionsMethod = methods.FirstOrDefault(m => m.Name == "CleanupOldSessions");
cleanupOldSessionsMethod.Should().NotBeNull();
cleanupOldSessionsMethod!.ReturnType.Should().Be(typeof(int));
cleanupOldSessionsMethod!.ReturnType.Should().Be<int>();
cleanupOldSessionsMethod.GetParameters().Should().HaveCount(1);
cleanupOldSessionsMethod.GetParameters()[0].ParameterType.Should().Be(typeof(int));
cleanupOldSessionsMethod.GetParameters()[0].ParameterType.Should().Be<int>();
// SaveSessionAsync method
var saveSessionAsyncMethod = methods.FirstOrDefault(m => m.Name == "SaveSessionAsync");
saveSessionAsyncMethod.Should().NotBeNull();
saveSessionAsyncMethod!.ReturnType.Should().Be(typeof(Task));
saveSessionAsyncMethod!.ReturnType.Should().Be<Task>();
saveSessionAsyncMethod.GetParameters().Should().HaveCount(1);
saveSessionAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(ChatSession));
saveSessionAsyncMethod.GetParameters()[0].ParameterType.Should().Be<ChatSession>();
}
[Fact]

View File

@@ -22,9 +22,9 @@ public class ITelegramBotClientWrapperTests : UnitTestBase
// GetMeAsync method
var getMeAsyncMethod = methods.FirstOrDefault(m => m.Name == "GetMeAsync");
getMeAsyncMethod.Should().NotBeNull();
getMeAsyncMethod!.ReturnType.Should().Be(typeof(Task<User>));
getMeAsyncMethod!.ReturnType.Should().Be<Task<User>>();
getMeAsyncMethod.GetParameters().Should().HaveCount(1);
getMeAsyncMethod.GetParameters()[0].ParameterType.Should().Be(typeof(CancellationToken));
getMeAsyncMethod.GetParameters()[0].ParameterType.Should().Be<CancellationToken>();
}
[Fact]

View File

@@ -61,11 +61,11 @@ public class TelegramBotClientWrapperTests : UnitTestBase
// Act & Assert
var method = typeof(TelegramBotClientWrapper).GetMethod("GetMeAsync");
method.Should().NotBeNull();
method!.ReturnType.Should().Be(typeof(Task<User>));
method!.ReturnType.Should().Be<Task<User>>();
var parameters = method.GetParameters();
parameters.Should().HaveCount(1);
parameters[0].ParameterType.Should().Be(typeof(CancellationToken));
parameters[0].ParameterType.Should().Be<CancellationToken>();
parameters[0].HasDefaultValue.Should().BeTrue();
}
@@ -142,7 +142,7 @@ public class TelegramBotClientWrapperTests : UnitTestBase
var constructor = constructors[0];
var parameters = constructor.GetParameters();
parameters.Should().HaveCount(1);
parameters[0].ParameterType.Should().Be(typeof(ITelegramBotClient));
parameters[0].ParameterType.Should().Be<ITelegramBotClient>();
parameters[0].Name.Should().Be("botClient");
}
@@ -153,7 +153,7 @@ public class TelegramBotClientWrapperTests : UnitTestBase
var wrapper = new TelegramBotClientWrapper(_botClientMock.Object);
// Act & Assert
wrapper.GetType().BaseType.Should().Be(typeof(object));
wrapper.GetType().BaseType.Should().Be<object>();
}
[Fact]
@@ -179,11 +179,11 @@ public class TelegramBotClientWrapperTests : UnitTestBase
// Assert
interfaceMethods.Should().HaveCount(1);
interfaceMethods[0].Name.Should().Be("GetMeAsync");
interfaceMethods[0].ReturnType.Should().Be(typeof(Task<User>));
interfaceMethods[0].ReturnType.Should().Be<Task<User>>();
var parameters = interfaceMethods[0].GetParameters();
parameters.Should().HaveCount(1);
parameters[0].ParameterType.Should().Be(typeof(CancellationToken));
parameters[0].ParameterType.Should().Be<CancellationToken>();
parameters[0].HasDefaultValue.Should().BeTrue();
}
@@ -324,7 +324,7 @@ public class TelegramBotClientWrapperTests : UnitTestBase
// Act & Assert
getMeMethod.Should().NotBeNull();
var returnType = getMeMethod!.ReturnType;
returnType.Should().Be(typeof(Task<User>));
returnType.Should().Be<Task<User>>();
var attributes = returnType.GetCustomAttributes(false);
attributes.Should().NotBeNull();