Add promt fix tests
All checks were successful
SonarQube / Build and analyze (push) Successful in 2m54s
All checks were successful
SonarQube / Build and analyze (push) Successful in 2m54s
This commit is contained in:
@@ -19,41 +19,41 @@ public class ISessionStorageTests : UnitTestBase
|
||||
// Assert
|
||||
methods.Should().HaveCount(6);
|
||||
|
||||
// GetOrCreate method
|
||||
var getOrCreateMethod = methods.FirstOrDefault(m => m.Name == "GetOrCreate");
|
||||
// GetOrCreateAsync method
|
||||
var getOrCreateMethod = methods.FirstOrDefault(m => m.Name == "GetOrCreateAsync");
|
||||
getOrCreateMethod.Should().NotBeNull();
|
||||
getOrCreateMethod!.ReturnType.Should().Be<ChatSession>();
|
||||
getOrCreateMethod!.ReturnType.Should().Be(typeof(Task<ChatSession>));
|
||||
getOrCreateMethod.GetParameters().Should().HaveCount(3);
|
||||
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");
|
||||
// GetAsync method
|
||||
var getMethod = methods.FirstOrDefault(m => m.Name == "GetAsync");
|
||||
getMethod.Should().NotBeNull();
|
||||
getMethod!.ReturnType.Should().Be<ChatSession>();
|
||||
getMethod!.ReturnType.Should().Be(typeof(Task<ChatSession?>));
|
||||
getMethod.GetParameters().Should().HaveCount(1);
|
||||
getMethod.GetParameters()[0].ParameterType.Should().Be<long>();
|
||||
|
||||
// Remove method
|
||||
var removeMethod = methods.FirstOrDefault(m => m.Name == "Remove");
|
||||
// RemoveAsync method
|
||||
var removeMethod = methods.FirstOrDefault(m => m.Name == "RemoveAsync");
|
||||
removeMethod.Should().NotBeNull();
|
||||
removeMethod!.ReturnType.Should().Be<bool>();
|
||||
removeMethod!.ReturnType.Should().Be(typeof(Task<bool>));
|
||||
removeMethod.GetParameters().Should().HaveCount(1);
|
||||
removeMethod.GetParameters()[0].ParameterType.Should().Be<long>();
|
||||
|
||||
// GetActiveSessionsCount method
|
||||
// GetActiveSessionsCountAsync method
|
||||
var getActiveSessionsCountMethod = methods.FirstOrDefault(m =>
|
||||
m.Name == "GetActiveSessionsCount"
|
||||
m.Name == "GetActiveSessionsCountAsync"
|
||||
);
|
||||
getActiveSessionsCountMethod.Should().NotBeNull();
|
||||
getActiveSessionsCountMethod!.ReturnType.Should().Be<int>();
|
||||
getActiveSessionsCountMethod!.ReturnType.Should().Be(typeof(Task<int>));
|
||||
getActiveSessionsCountMethod.GetParameters().Should().BeEmpty();
|
||||
|
||||
// CleanupOldSessions method
|
||||
var cleanupOldSessionsMethod = methods.FirstOrDefault(m => m.Name == "CleanupOldSessions");
|
||||
// CleanupOldSessionsAsync method
|
||||
var cleanupOldSessionsMethod = methods.FirstOrDefault(m => m.Name == "CleanupOldSessionsAsync");
|
||||
cleanupOldSessionsMethod.Should().NotBeNull();
|
||||
cleanupOldSessionsMethod!.ReturnType.Should().Be<int>();
|
||||
cleanupOldSessionsMethod!.ReturnType.Should().Be(typeof(Task<int>));
|
||||
cleanupOldSessionsMethod.GetParameters().Should().HaveCount(1);
|
||||
cleanupOldSessionsMethod.GetParameters()[0].ParameterType.Should().Be<int>();
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ISessionStorageTests : UnitTestBase
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ISessionStorage_GetOrCreate_ShouldReturnChatSession()
|
||||
public async Task ISessionStorage_GetOrCreateAsync_ShouldReturnChatSession()
|
||||
{
|
||||
// Arrange
|
||||
var mock = new Mock<ISessionStorage>();
|
||||
@@ -97,120 +97,120 @@ public class ISessionStorageTests : UnitTestBase
|
||||
var chatTitle = "Test Chat";
|
||||
var expectedSession = TestDataBuilder.ChatSessions.CreateBasicSession(chatId, chatType);
|
||||
|
||||
mock.Setup(x => x.GetOrCreate(It.IsAny<long>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(expectedSession);
|
||||
mock.Setup(x => x.GetOrCreateAsync(It.IsAny<long>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.ReturnsAsync(expectedSession);
|
||||
|
||||
// Act
|
||||
var result = mock.Object.GetOrCreate(chatId, chatType, chatTitle);
|
||||
var result = await mock.Object.GetOrCreateAsync(chatId, chatType, chatTitle);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedSession);
|
||||
mock.Verify(x => x.GetOrCreate(chatId, chatType, chatTitle), Times.Once);
|
||||
mock.Verify(x => x.GetOrCreateAsync(chatId, chatType, chatTitle), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ISessionStorage_Get_ShouldReturnChatSessionOrNull()
|
||||
public async Task ISessionStorage_GetAsync_ShouldReturnChatSessionOrNull()
|
||||
{
|
||||
// Arrange
|
||||
var mock = new Mock<ISessionStorage>();
|
||||
var chatId = 12345L;
|
||||
var expectedSession = TestDataBuilder.ChatSessions.CreateBasicSession(chatId, "private");
|
||||
|
||||
mock.Setup(x => x.Get(It.IsAny<long>())).Returns(expectedSession);
|
||||
mock.Setup(x => x.GetAsync(It.IsAny<long>())).ReturnsAsync(expectedSession);
|
||||
|
||||
// Act
|
||||
var result = mock.Object.Get(chatId);
|
||||
var result = await mock.Object.GetAsync(chatId);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedSession);
|
||||
mock.Verify(x => x.Get(chatId), Times.Once);
|
||||
mock.Verify(x => x.GetAsync(chatId), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ISessionStorage_Get_ShouldReturnNullWhenSessionNotFound()
|
||||
public async Task ISessionStorage_GetAsync_ShouldReturnNullWhenSessionNotFound()
|
||||
{
|
||||
// Arrange
|
||||
var mock = new Mock<ISessionStorage>();
|
||||
var chatId = 12345L;
|
||||
|
||||
mock.Setup(x => x.Get(It.IsAny<long>())).Returns((ChatSession?)null);
|
||||
mock.Setup(x => x.GetAsync(It.IsAny<long>())).ReturnsAsync((ChatSession?)null);
|
||||
|
||||
// Act
|
||||
var result = mock.Object.Get(chatId);
|
||||
var result = await mock.Object.GetAsync(chatId);
|
||||
|
||||
// Assert
|
||||
result.Should().BeNull();
|
||||
mock.Verify(x => x.Get(chatId), Times.Once);
|
||||
mock.Verify(x => x.GetAsync(chatId), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ISessionStorage_Remove_ShouldReturnBoolean()
|
||||
public async Task ISessionStorage_RemoveAsync_ShouldReturnBoolean()
|
||||
{
|
||||
// Arrange
|
||||
var mock = new Mock<ISessionStorage>();
|
||||
var chatId = 12345L;
|
||||
var expectedResult = true;
|
||||
|
||||
mock.Setup(x => x.Remove(It.IsAny<long>())).Returns(expectedResult);
|
||||
mock.Setup(x => x.RemoveAsync(It.IsAny<long>())).ReturnsAsync(expectedResult);
|
||||
|
||||
// Act
|
||||
var result = mock.Object.Remove(chatId);
|
||||
var result = await mock.Object.RemoveAsync(chatId);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedResult);
|
||||
mock.Verify(x => x.Remove(chatId), Times.Once);
|
||||
mock.Verify(x => x.RemoveAsync(chatId), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ISessionStorage_GetActiveSessionsCount_ShouldReturnInt()
|
||||
public async Task ISessionStorage_GetActiveSessionsCountAsync_ShouldReturnInt()
|
||||
{
|
||||
// Arrange
|
||||
var mock = new Mock<ISessionStorage>();
|
||||
var expectedCount = 5;
|
||||
|
||||
mock.Setup(x => x.GetActiveSessionsCount()).Returns(expectedCount);
|
||||
mock.Setup(x => x.GetActiveSessionsCountAsync()).ReturnsAsync(expectedCount);
|
||||
|
||||
// Act
|
||||
var result = mock.Object.GetActiveSessionsCount();
|
||||
var result = await mock.Object.GetActiveSessionsCountAsync();
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedCount);
|
||||
mock.Verify(x => x.GetActiveSessionsCount(), Times.Once);
|
||||
mock.Verify(x => x.GetActiveSessionsCountAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ISessionStorage_CleanupOldSessions_ShouldReturnInt()
|
||||
public async Task ISessionStorage_CleanupOldSessionsAsync_ShouldReturnInt()
|
||||
{
|
||||
// Arrange
|
||||
var mock = new Mock<ISessionStorage>();
|
||||
var hoursOld = 24;
|
||||
var expectedCleanedCount = 3;
|
||||
|
||||
mock.Setup(x => x.CleanupOldSessions(It.IsAny<int>())).Returns(expectedCleanedCount);
|
||||
mock.Setup(x => x.CleanupOldSessionsAsync(It.IsAny<int>())).ReturnsAsync(expectedCleanedCount);
|
||||
|
||||
// Act
|
||||
var result = mock.Object.CleanupOldSessions(hoursOld);
|
||||
var result = await mock.Object.CleanupOldSessionsAsync(hoursOld);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedCleanedCount);
|
||||
mock.Verify(x => x.CleanupOldSessions(hoursOld), Times.Once);
|
||||
mock.Verify(x => x.CleanupOldSessionsAsync(hoursOld), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ISessionStorage_CleanupOldSessions_ShouldUseDefaultValue()
|
||||
public async Task ISessionStorage_CleanupOldSessionsAsync_ShouldUseDefaultValue()
|
||||
{
|
||||
// Arrange
|
||||
var mock = new Mock<ISessionStorage>();
|
||||
var expectedCleanedCount = 2;
|
||||
|
||||
mock.Setup(x => x.CleanupOldSessions(It.IsAny<int>())).Returns(expectedCleanedCount);
|
||||
mock.Setup(x => x.CleanupOldSessionsAsync(It.IsAny<int>())).ReturnsAsync(expectedCleanedCount);
|
||||
|
||||
// Act
|
||||
var result = mock.Object.CleanupOldSessions();
|
||||
var result = await mock.Object.CleanupOldSessionsAsync();
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedCleanedCount);
|
||||
mock.Verify(x => x.CleanupOldSessions(24), Times.Once); // Default value is 24
|
||||
mock.Verify(x => x.CleanupOldSessionsAsync(24), Times.Once); // Default value is 24
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -230,22 +230,22 @@ public class ISessionStorageTests : UnitTestBase
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ISessionStorage_GetOrCreate_ShouldUseDefaultValues()
|
||||
public async Task ISessionStorage_GetOrCreateAsync_ShouldUseDefaultValues()
|
||||
{
|
||||
// Arrange
|
||||
var mock = new Mock<ISessionStorage>();
|
||||
var chatId = 12345L;
|
||||
var expectedSession = TestDataBuilder.ChatSessions.CreateBasicSession(chatId, "private");
|
||||
|
||||
mock.Setup(x => x.GetOrCreate(It.IsAny<long>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(expectedSession);
|
||||
mock.Setup(x => x.GetOrCreateAsync(It.IsAny<long>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.ReturnsAsync(expectedSession);
|
||||
|
||||
// Act
|
||||
var result = mock.Object.GetOrCreate(chatId);
|
||||
var result = await mock.Object.GetOrCreateAsync(chatId);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedSession);
|
||||
mock.Verify(x => x.GetOrCreate(chatId, "private", ""), Times.Once); // Default values
|
||||
mock.Verify(x => x.GetOrCreateAsync(chatId, "private", ""), Times.Once); // Default values
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -280,15 +280,15 @@ public class ISessionStorageTests : UnitTestBase
|
||||
// All methods should be public
|
||||
methods.All(m => m.IsPublic).Should().BeTrue();
|
||||
|
||||
// GetOrCreate should have default parameters
|
||||
var getOrCreateMethod = methods.First(m => m.Name == "GetOrCreate");
|
||||
// GetOrCreateAsync should have default parameters
|
||||
var getOrCreateMethod = methods.First(m => m.Name == "GetOrCreateAsync");
|
||||
getOrCreateMethod.GetParameters()[1].HasDefaultValue.Should().BeTrue();
|
||||
getOrCreateMethod.GetParameters()[1].DefaultValue.Should().Be("private");
|
||||
getOrCreateMethod.GetParameters()[2].HasDefaultValue.Should().BeTrue();
|
||||
getOrCreateMethod.GetParameters()[2].DefaultValue.Should().Be("");
|
||||
|
||||
// CleanupOldSessions should have default parameter
|
||||
var cleanupMethod = methods.First(m => m.Name == "CleanupOldSessions");
|
||||
// CleanupOldSessionsAsync should have default parameter
|
||||
var cleanupMethod = methods.First(m => m.Name == "CleanupOldSessionsAsync");
|
||||
cleanupMethod.GetParameters()[0].HasDefaultValue.Should().BeTrue();
|
||||
cleanupMethod.GetParameters()[0].DefaultValue.Should().Be(24);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user