441 lines
14 KiB
C#
441 lines
14 KiB
C#
using ChatBot.Common.Constants;
|
|
using FluentAssertions;
|
|
|
|
namespace ChatBot.Tests.Common.Constants;
|
|
|
|
public class AIResponseConstantsTests
|
|
{
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldHaveCorrectValue()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Should().Be("{empty}");
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldHaveCorrectValue()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants
|
|
.DefaultErrorMessage.Should()
|
|
.Be("Извините, произошла ошибка при генерации ответа.");
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldNotBeNull()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldNotBeNull()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.DefaultErrorMessage.Should().NotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldNotBeEmpty()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldNotBeEmpty()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.DefaultErrorMessage.Should().NotBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeReadOnly()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Should().Be("{empty}");
|
|
|
|
// Verify it's a constant by checking it doesn't change
|
|
var firstValue = AIResponseConstants.EmptyResponseMarker;
|
|
var secondValue = AIResponseConstants.EmptyResponseMarker;
|
|
firstValue.Should().Be(secondValue);
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeReadOnly()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants
|
|
.DefaultErrorMessage.Should()
|
|
.Be("Извините, произошла ошибка при генерации ответа.");
|
|
|
|
// Verify it's a constant by checking it doesn't change
|
|
var firstValue = AIResponseConstants.DefaultErrorMessage;
|
|
var secondValue = AIResponseConstants.DefaultErrorMessage;
|
|
firstValue.Should().Be(secondValue);
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldContainBraces()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Should().StartWith("{");
|
|
AIResponseConstants.EmptyResponseMarker.Should().EndWith("}");
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldContainRussianText()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.DefaultErrorMessage.Should().Contain("Извините");
|
|
AIResponseConstants.DefaultErrorMessage.Should().Contain("ошибка");
|
|
AIResponseConstants.DefaultErrorMessage.Should().Contain("генерации");
|
|
AIResponseConstants.DefaultErrorMessage.Should().Contain("ответа");
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldHaveCorrectLength()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Length.Should().Be(7);
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldHaveCorrectLength()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.DefaultErrorMessage.Length.Should().Be(48);
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeImmutable()
|
|
{
|
|
// Act & Assert
|
|
var value1 = AIResponseConstants.EmptyResponseMarker;
|
|
var value2 = AIResponseConstants.EmptyResponseMarker;
|
|
|
|
value1.Should().Be(value2);
|
|
ReferenceEquals(value1, value2).Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeImmutable()
|
|
{
|
|
// Act & Assert
|
|
var value1 = AIResponseConstants.DefaultErrorMessage;
|
|
var value2 = AIResponseConstants.DefaultErrorMessage;
|
|
|
|
value1.Should().Be(value2);
|
|
ReferenceEquals(value1, value2).Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldNotContainSpaces()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotContain(" ");
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldContainSpaces()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.DefaultErrorMessage.Should().Contain(" ");
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeLowerCase()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Should().BeLowerCased();
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldStartWithCapitalLetter()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.DefaultErrorMessage.Should().StartWith("И");
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldEndWithPeriod()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Should().EndWith("}");
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldEndWithPeriod()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.DefaultErrorMessage.Should().EndWith(".");
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldNotContainSpecialCharacters()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotContain("@");
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotContain("#");
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotContain("$");
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotContain("%");
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotContain("^");
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotContain("&");
|
|
AIResponseConstants.EmptyResponseMarker.Should().NotContain("*");
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldContainPunctuation()
|
|
{
|
|
// Act & Assert
|
|
AIResponseConstants.DefaultErrorMessage.Should().Contain(",");
|
|
AIResponseConstants.DefaultErrorMessage.Should().Contain(".");
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeValidForComparison()
|
|
{
|
|
// Act & Assert
|
|
(AIResponseConstants.EmptyResponseMarker == "{empty}")
|
|
.Should()
|
|
.BeTrue();
|
|
(AIResponseConstants.EmptyResponseMarker != "empty").Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeValidForComparison()
|
|
{
|
|
// Act & Assert
|
|
(
|
|
AIResponseConstants.DefaultErrorMessage
|
|
== "Извините, произошла ошибка при генерации ответа."
|
|
)
|
|
.Should()
|
|
.BeTrue();
|
|
(AIResponseConstants.DefaultErrorMessage != "Some other message").Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeUsableInStringOperations()
|
|
{
|
|
// Act & Assert
|
|
var testString = "Response: " + AIResponseConstants.EmptyResponseMarker;
|
|
testString.Should().Be("Response: {empty}");
|
|
|
|
var containsMarker = testString.Contains(AIResponseConstants.EmptyResponseMarker);
|
|
containsMarker.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeUsableInStringOperations()
|
|
{
|
|
// Act & Assert
|
|
var testString = "Error: " + AIResponseConstants.DefaultErrorMessage;
|
|
testString.Should().Be("Error: Извините, произошла ошибка при генерации ответа.");
|
|
|
|
var containsMessage = testString.Contains(AIResponseConstants.DefaultErrorMessage);
|
|
containsMessage.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeUsableInConditionalLogic()
|
|
{
|
|
// Act & Assert
|
|
var isMarker = AIResponseConstants.EmptyResponseMarker == "{empty}";
|
|
isMarker.Should().BeTrue();
|
|
|
|
var isNotMarker = AIResponseConstants.EmptyResponseMarker != "empty";
|
|
isNotMarker.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeUsableInConditionalLogic()
|
|
{
|
|
// Act & Assert
|
|
var isErrorMessage = AIResponseConstants.DefaultErrorMessage.Contains("ошибка");
|
|
isErrorMessage.Should().BeTrue();
|
|
|
|
var isNotEmpty = !string.IsNullOrEmpty(AIResponseConstants.DefaultErrorMessage);
|
|
isNotEmpty.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeUsableInSwitchStatements()
|
|
{
|
|
// Act & Assert
|
|
var result = AIResponseConstants.EmptyResponseMarker switch
|
|
{
|
|
"{empty}" => "IsEmptyMarker",
|
|
_ => "NotEmptyMarker",
|
|
};
|
|
|
|
result.Should().Be("IsEmptyMarker");
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeUsableInSwitchStatements()
|
|
{
|
|
// Act & Assert
|
|
var result = AIResponseConstants.DefaultErrorMessage switch
|
|
{
|
|
"Извините, произошла ошибка при генерации ответа." => "IsDefaultError",
|
|
_ => "NotDefaultError",
|
|
};
|
|
|
|
result.Should().Be("IsDefaultError");
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeUsableInDictionaryKeys()
|
|
{
|
|
// Arrange
|
|
var dictionary = new Dictionary<string, string>
|
|
{
|
|
{ AIResponseConstants.EmptyResponseMarker, "Empty response value" },
|
|
};
|
|
|
|
// Act & Assert
|
|
dictionary.ContainsKey(AIResponseConstants.EmptyResponseMarker).Should().BeTrue();
|
|
dictionary[AIResponseConstants.EmptyResponseMarker].Should().Be("Empty response value");
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeUsableInDictionaryKeys()
|
|
{
|
|
// Arrange
|
|
var dictionary = new Dictionary<string, string>
|
|
{
|
|
{ AIResponseConstants.DefaultErrorMessage, "Error response value" },
|
|
};
|
|
|
|
// Act & Assert
|
|
dictionary.ContainsKey(AIResponseConstants.DefaultErrorMessage).Should().BeTrue();
|
|
dictionary[AIResponseConstants.DefaultErrorMessage].Should().Be("Error response value");
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeUsableInListOperations()
|
|
{
|
|
// Arrange
|
|
var list = new List<string> { AIResponseConstants.EmptyResponseMarker };
|
|
|
|
// Act & Assert
|
|
list.Contains(AIResponseConstants.EmptyResponseMarker).Should().BeTrue();
|
|
list.Count.Should().Be(1);
|
|
list[0].Should().Be(AIResponseConstants.EmptyResponseMarker);
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeUsableInListOperations()
|
|
{
|
|
// Arrange
|
|
var list = new List<string> { AIResponseConstants.DefaultErrorMessage };
|
|
|
|
// Act & Assert
|
|
list.Contains(AIResponseConstants.DefaultErrorMessage).Should().BeTrue();
|
|
list.Count.Should().Be(1);
|
|
list[0].Should().Be(AIResponseConstants.DefaultErrorMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeUsableInStringFormatting()
|
|
{
|
|
// Act & Assert
|
|
var formatted = string.Format("Response: {0}", AIResponseConstants.EmptyResponseMarker);
|
|
formatted.Should().Be("Response: {empty}");
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeUsableInStringFormatting()
|
|
{
|
|
// Act & Assert
|
|
var formatted = string.Format("Error: {0}", AIResponseConstants.DefaultErrorMessage);
|
|
formatted.Should().Be("Error: Извините, произошла ошибка при генерации ответа.");
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyResponseMarker_ShouldBeUsableInStringInterpolation()
|
|
{
|
|
// Act & Assert
|
|
var interpolated = $"Response: {AIResponseConstants.EmptyResponseMarker}";
|
|
interpolated.Should().Be("Response: {empty}");
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultErrorMessage_ShouldBeUsableInStringInterpolation()
|
|
{
|
|
// Act & Assert
|
|
var interpolated = $"Error: {AIResponseConstants.DefaultErrorMessage}";
|
|
interpolated.Should().Be("Error: Извините, произошла ошибка при генерации ответа.");
|
|
}
|
|
|
|
[Fact]
|
|
public void Constants_ShouldBeAccessibleFromDifferentAssemblies()
|
|
{
|
|
// Act & Assert
|
|
// This test verifies that constants are public and accessible
|
|
var emptyMarker = AIResponseConstants.EmptyResponseMarker;
|
|
var errorMessage = AIResponseConstants.DefaultErrorMessage;
|
|
|
|
emptyMarker.Should().NotBeNull();
|
|
errorMessage.Should().NotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Constants_ShouldBeCompileTimeConstants()
|
|
{
|
|
// Act & Assert
|
|
// This test verifies that constants can be used in switch expressions
|
|
var emptyMarkerType = AIResponseConstants.EmptyResponseMarker switch
|
|
{
|
|
"{empty}" => typeof(string),
|
|
_ => typeof(object),
|
|
};
|
|
|
|
emptyMarkerType.Should().Be<string>();
|
|
}
|
|
|
|
[Fact]
|
|
public void Constants_ShouldBeUsableInAttributeParameters()
|
|
{
|
|
// Act & Assert
|
|
// This test verifies that constants can be used in attributes
|
|
var testClass = typeof(AIResponseConstants);
|
|
testClass.Should().NotBeNull();
|
|
testClass.IsClass.Should().BeTrue();
|
|
testClass.IsPublic.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Constants_ShouldBeUsableInDefaultParameterValues()
|
|
{
|
|
// Act & Assert
|
|
// This test verifies that constants can be used as default parameter values
|
|
var method = typeof(AIResponseConstants).GetMethod("EmptyResponseMarker");
|
|
method.Should().BeNull(); // It's a field, not a method
|
|
|
|
var field = typeof(AIResponseConstants).GetField("EmptyResponseMarker");
|
|
field.Should().NotBeNull();
|
|
field!.IsLiteral.Should().BeTrue();
|
|
field.IsInitOnly.Should().BeFalse(); // Constants are not init-only
|
|
}
|
|
|
|
[Fact]
|
|
public void Constants_ShouldBeUsableInReflection()
|
|
{
|
|
// Act & Assert
|
|
var type = typeof(AIResponseConstants);
|
|
var emptyMarkerField = type.GetField("EmptyResponseMarker");
|
|
var errorMessageField = type.GetField("DefaultErrorMessage");
|
|
|
|
emptyMarkerField.Should().NotBeNull();
|
|
errorMessageField.Should().NotBeNull();
|
|
|
|
emptyMarkerField!.GetValue(null).Should().Be("{empty}");
|
|
errorMessageField!
|
|
.GetValue(null)
|
|
.Should()
|
|
.Be("Извините, произошла ошибка при генерации ответа.");
|
|
}
|
|
}
|