add more tests
Some checks failed
SonarQube / Build and analyze (push) Failing after 2m56s
Unit Tests / Run Tests (push) Failing after 2m28s

This commit is contained in:
Leonid Pershin
2025-10-20 07:02:12 +03:00
parent af9773e7d6
commit 1647fe19d3
12 changed files with 3714 additions and 21 deletions

View File

@@ -0,0 +1,440 @@
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(typeof(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("Извините, произошла ошибка при генерации ответа.");
}
}

View File

@@ -0,0 +1,581 @@
using ChatBot.Common.Constants;
using FluentAssertions;
namespace ChatBot.Tests.Common.Constants;
public class ChatTypesTests
{
[Fact]
public void Private_ShouldHaveCorrectValue()
{
// Act & Assert
ChatTypes.Private.Should().Be("private");
}
[Fact]
public void Group_ShouldHaveCorrectValue()
{
// Act & Assert
ChatTypes.Group.Should().Be("group");
}
[Fact]
public void SuperGroup_ShouldHaveCorrectValue()
{
// Act & Assert
ChatTypes.SuperGroup.Should().Be("supergroup");
}
[Fact]
public void Channel_ShouldHaveCorrectValue()
{
// Act & Assert
ChatTypes.Channel.Should().Be("channel");
}
[Fact]
public void AllConstants_ShouldNotBeNull()
{
// Act & Assert
ChatTypes.Private.Should().NotBeNull();
ChatTypes.Group.Should().NotBeNull();
ChatTypes.SuperGroup.Should().NotBeNull();
ChatTypes.Channel.Should().NotBeNull();
}
[Fact]
public void AllConstants_ShouldNotBeEmpty()
{
// Act & Assert
ChatTypes.Private.Should().NotBeEmpty();
ChatTypes.Group.Should().NotBeEmpty();
ChatTypes.SuperGroup.Should().NotBeEmpty();
ChatTypes.Channel.Should().NotBeEmpty();
}
[Fact]
public void AllConstants_ShouldBeReadOnly()
{
// Act & Assert
var privateValue1 = ChatTypes.Private;
var privateValue2 = ChatTypes.Private;
privateValue1.Should().Be(privateValue2);
var groupValue1 = ChatTypes.Group;
var groupValue2 = ChatTypes.Group;
groupValue1.Should().Be(groupValue2);
var superGroupValue1 = ChatTypes.SuperGroup;
var superGroupValue2 = ChatTypes.SuperGroup;
superGroupValue1.Should().Be(superGroupValue2);
var channelValue1 = ChatTypes.Channel;
var channelValue2 = ChatTypes.Channel;
channelValue1.Should().Be(channelValue2);
}
[Fact]
public void AllConstants_ShouldBeImmutable()
{
// Act & Assert
var privateValue1 = ChatTypes.Private;
var privateValue2 = ChatTypes.Private;
ReferenceEquals(privateValue1, privateValue2).Should().BeTrue();
var groupValue1 = ChatTypes.Group;
var groupValue2 = ChatTypes.Group;
ReferenceEquals(groupValue1, groupValue2).Should().BeTrue();
var superGroupValue1 = ChatTypes.SuperGroup;
var superGroupValue2 = ChatTypes.SuperGroup;
ReferenceEquals(superGroupValue1, superGroupValue2).Should().BeTrue();
var channelValue1 = ChatTypes.Channel;
var channelValue2 = ChatTypes.Channel;
ReferenceEquals(channelValue1, channelValue2).Should().BeTrue();
}
[Fact]
public void AllConstants_ShouldBeLowerCase()
{
// Act & Assert
ChatTypes.Private.Should().BeLowerCased();
ChatTypes.Group.Should().BeLowerCased();
ChatTypes.SuperGroup.Should().BeLowerCased();
ChatTypes.Channel.Should().BeLowerCased();
}
[Fact]
public void AllConstants_ShouldNotContainSpaces()
{
// Act & Assert
ChatTypes.Private.Should().NotContain(" ");
ChatTypes.Group.Should().NotContain(" ");
ChatTypes.SuperGroup.Should().NotContain(" ");
ChatTypes.Channel.Should().NotContain(" ");
}
[Fact]
public void AllConstants_ShouldNotContainSpecialCharacters()
{
// Act & Assert
var specialChars = new[]
{
"@",
"#",
"$",
"%",
"^",
"&",
"*",
"(",
")",
"-",
"_",
"+",
"=",
"[",
"]",
"{",
"}",
"|",
"\\",
":",
";",
"\"",
"'",
"<",
">",
",",
".",
"?",
"/",
};
foreach (var specialChar in specialChars)
{
ChatTypes.Private.Should().NotContain(specialChar);
ChatTypes.Group.Should().NotContain(specialChar);
ChatTypes.SuperGroup.Should().NotContain(specialChar);
ChatTypes.Channel.Should().NotContain(specialChar);
}
}
[Fact]
public void AllConstants_ShouldHaveCorrectLengths()
{
// Act & Assert
ChatTypes.Private.Length.Should().Be(7);
ChatTypes.Group.Length.Should().Be(5);
ChatTypes.SuperGroup.Length.Should().Be(10);
ChatTypes.Channel.Length.Should().Be(7);
}
[Fact]
public void AllConstants_ShouldBeUsableInStringOperations()
{
// Act & Assert
var privateString = "Chat type: " + ChatTypes.Private;
privateString.Should().Be("Chat type: private");
var groupString = "Chat type: " + ChatTypes.Group;
groupString.Should().Be("Chat type: group");
var superGroupString = "Chat type: " + ChatTypes.SuperGroup;
superGroupString.Should().Be("Chat type: supergroup");
var channelString = "Chat type: " + ChatTypes.Channel;
channelString.Should().Be("Chat type: channel");
}
[Fact]
public void AllConstants_ShouldBeUsableInConditionalLogic()
{
// Act & Assert
var isPrivate = ChatTypes.Private == "private";
isPrivate.Should().BeTrue();
var isGroup = ChatTypes.Group == "group";
isGroup.Should().BeTrue();
var isSuperGroup = ChatTypes.SuperGroup == "supergroup";
isSuperGroup.Should().BeTrue();
var isChannel = ChatTypes.Channel == "channel";
isChannel.Should().BeTrue();
}
[Fact]
public void AllConstants_ShouldBeUsableInSwitchStatements()
{
// Act & Assert
var privateResult = ChatTypes.Private switch
{
"private" => "IsPrivate",
_ => "NotPrivate",
};
privateResult.Should().Be("IsPrivate");
var groupResult = ChatTypes.Group switch
{
"group" => "IsGroup",
_ => "NotGroup",
};
groupResult.Should().Be("IsGroup");
var superGroupResult = ChatTypes.SuperGroup switch
{
"supergroup" => "IsSuperGroup",
_ => "NotSuperGroup",
};
superGroupResult.Should().Be("IsSuperGroup");
var channelResult = ChatTypes.Channel switch
{
"channel" => "IsChannel",
_ => "NotChannel",
};
channelResult.Should().Be("IsChannel");
}
[Fact]
public void AllConstants_ShouldBeUsableInDictionaryKeys()
{
// Arrange
var dictionary = new Dictionary<string, string>
{
{ ChatTypes.Private, "Private chat description" },
{ ChatTypes.Group, "Group chat description" },
{ ChatTypes.SuperGroup, "Super group chat description" },
{ ChatTypes.Channel, "Channel chat description" },
};
// Act & Assert
dictionary.ContainsKey(ChatTypes.Private).Should().BeTrue();
dictionary.ContainsKey(ChatTypes.Group).Should().BeTrue();
dictionary.ContainsKey(ChatTypes.SuperGroup).Should().BeTrue();
dictionary.ContainsKey(ChatTypes.Channel).Should().BeTrue();
dictionary[ChatTypes.Private].Should().Be("Private chat description");
dictionary[ChatTypes.Group].Should().Be("Group chat description");
dictionary[ChatTypes.SuperGroup].Should().Be("Super group chat description");
dictionary[ChatTypes.Channel].Should().Be("Channel chat description");
}
[Fact]
public void AllConstants_ShouldBeUsableInListOperations()
{
// Arrange
var list = new List<string>
{
ChatTypes.Private,
ChatTypes.Group,
ChatTypes.SuperGroup,
ChatTypes.Channel,
};
// Act & Assert
list.Contains(ChatTypes.Private).Should().BeTrue();
list.Contains(ChatTypes.Group).Should().BeTrue();
list.Contains(ChatTypes.SuperGroup).Should().BeTrue();
list.Contains(ChatTypes.Channel).Should().BeTrue();
list.Count.Should().Be(4);
list.Should().Contain(ChatTypes.Private);
list.Should().Contain(ChatTypes.Group);
list.Should().Contain(ChatTypes.SuperGroup);
list.Should().Contain(ChatTypes.Channel);
}
[Fact]
public void AllConstants_ShouldBeUsableInStringFormatting()
{
// Act & Assert
var privateFormatted = string.Format("Chat type: {0}", ChatTypes.Private);
privateFormatted.Should().Be("Chat type: private");
var groupFormatted = string.Format("Chat type: {0}", ChatTypes.Group);
groupFormatted.Should().Be("Chat type: group");
var superGroupFormatted = string.Format("Chat type: {0}", ChatTypes.SuperGroup);
superGroupFormatted.Should().Be("Chat type: supergroup");
var channelFormatted = string.Format("Chat type: {0}", ChatTypes.Channel);
channelFormatted.Should().Be("Chat type: channel");
}
[Fact]
public void AllConstants_ShouldBeUsableInStringInterpolation()
{
// Act & Assert
var privateInterpolated = $"Chat type: {ChatTypes.Private}";
privateInterpolated.Should().Be("Chat type: private");
var groupInterpolated = $"Chat type: {ChatTypes.Group}";
groupInterpolated.Should().Be("Chat type: group");
var superGroupInterpolated = $"Chat type: {ChatTypes.SuperGroup}";
superGroupInterpolated.Should().Be("Chat type: supergroup");
var channelInterpolated = $"Chat type: {ChatTypes.Channel}";
channelInterpolated.Should().Be("Chat type: channel");
}
[Fact]
public void AllConstants_ShouldBeAccessibleFromDifferentAssemblies()
{
// Act & Assert
var privateType = ChatTypes.Private;
var groupType = ChatTypes.Group;
var superGroupType = ChatTypes.SuperGroup;
var channelType = ChatTypes.Channel;
privateType.Should().NotBeNull();
groupType.Should().NotBeNull();
superGroupType.Should().NotBeNull();
channelType.Should().NotBeNull();
}
[Fact]
public void AllConstants_ShouldBeCompileTimeConstants()
{
// Act & Assert
var privateType = ChatTypes.Private switch
{
"private" => typeof(string),
_ => typeof(object),
};
privateType.Should().Be(typeof(string));
var groupType = ChatTypes.Group switch
{
"group" => typeof(string),
_ => typeof(object),
};
groupType.Should().Be(typeof(string));
var superGroupType = ChatTypes.SuperGroup switch
{
"supergroup" => typeof(string),
_ => typeof(object),
};
superGroupType.Should().Be(typeof(string));
var channelType = ChatTypes.Channel switch
{
"channel" => typeof(string),
_ => typeof(object),
};
channelType.Should().Be(typeof(string));
}
[Fact]
public void AllConstants_ShouldBeUsableInReflection()
{
// Act & Assert
var type = typeof(ChatTypes);
var privateField = type.GetField("Private");
var groupField = type.GetField("Group");
var superGroupField = type.GetField("SuperGroup");
var channelField = type.GetField("Channel");
privateField.Should().NotBeNull();
groupField.Should().NotBeNull();
superGroupField.Should().NotBeNull();
channelField.Should().NotBeNull();
privateField!.GetValue(null).Should().Be("private");
groupField!.GetValue(null).Should().Be("group");
superGroupField!.GetValue(null).Should().Be("supergroup");
channelField!.GetValue(null).Should().Be("channel");
}
[Fact]
public void AllConstants_ShouldBeUsableInDefaultParameterValues()
{
// Act & Assert
var type = typeof(ChatTypes);
var privateField = type.GetField("Private");
var groupField = type.GetField("Group");
var superGroupField = type.GetField("SuperGroup");
var channelField = type.GetField("Channel");
privateField!.IsLiteral.Should().BeTrue();
groupField!.IsLiteral.Should().BeTrue();
superGroupField!.IsLiteral.Should().BeTrue();
channelField!.IsLiteral.Should().BeTrue();
privateField.IsInitOnly.Should().BeFalse();
groupField.IsInitOnly.Should().BeFalse();
superGroupField.IsInitOnly.Should().BeFalse();
channelField.IsInitOnly.Should().BeFalse();
}
[Fact]
public void AllConstants_ShouldBeUsableInAttributeParameters()
{
// Act & Assert
var testClass = typeof(ChatTypes);
testClass.Should().NotBeNull();
testClass.IsClass.Should().BeTrue();
testClass.IsPublic.Should().BeTrue();
}
[Fact]
public void AllConstants_ShouldBeUsableInComparisons()
{
// Act & Assert
(ChatTypes.Private == "private")
.Should()
.BeTrue();
(ChatTypes.Private != "group").Should().BeTrue();
(ChatTypes.Group == "group").Should().BeTrue();
(ChatTypes.Group != "private").Should().BeTrue();
(ChatTypes.SuperGroup == "supergroup").Should().BeTrue();
(ChatTypes.SuperGroup != "group").Should().BeTrue();
(ChatTypes.Channel == "channel").Should().BeTrue();
(ChatTypes.Channel != "private").Should().BeTrue();
}
[Fact]
public void AllConstants_ShouldBeUsableInContainsOperations()
{
// Arrange
var allTypes = new[]
{
ChatTypes.Private,
ChatTypes.Group,
ChatTypes.SuperGroup,
ChatTypes.Channel,
};
// Act & Assert
allTypes.Should().Contain(ChatTypes.Private);
allTypes.Should().Contain(ChatTypes.Group);
allTypes.Should().Contain(ChatTypes.SuperGroup);
allTypes.Should().Contain(ChatTypes.Channel);
}
[Fact]
public void AllConstants_ShouldBeUsableInDistinctOperations()
{
// Arrange
var typesWithDuplicates = new[]
{
ChatTypes.Private,
ChatTypes.Group,
ChatTypes.Private,
ChatTypes.SuperGroup,
ChatTypes.Channel,
ChatTypes.Group,
};
// Act
var distinctTypes = typesWithDuplicates.Distinct().ToArray();
// Assert
distinctTypes.Should().HaveCount(4);
distinctTypes.Should().Contain(ChatTypes.Private);
distinctTypes.Should().Contain(ChatTypes.Group);
distinctTypes.Should().Contain(ChatTypes.SuperGroup);
distinctTypes.Should().Contain(ChatTypes.Channel);
}
[Fact]
public void AllConstants_ShouldBeUsableInWhereOperations()
{
// Arrange
var allTypes = new[]
{
ChatTypes.Private,
ChatTypes.Group,
ChatTypes.SuperGroup,
ChatTypes.Channel,
};
// Act
var privateTypes = allTypes.Where(t => t == ChatTypes.Private).ToArray();
var groupTypes = allTypes.Where(t => t == ChatTypes.Group).ToArray();
// Assert
privateTypes.Should().HaveCount(1);
privateTypes[0].Should().Be(ChatTypes.Private);
groupTypes.Should().HaveCount(1);
groupTypes[0].Should().Be(ChatTypes.Group);
}
[Fact]
public void AllConstants_ShouldBeUsableInSelectOperations()
{
// Arrange
var allTypes = new[]
{
ChatTypes.Private,
ChatTypes.Group,
ChatTypes.SuperGroup,
ChatTypes.Channel,
};
// Act
var descriptions = allTypes.Select(t => $"Chat type: {t}").ToArray();
// Assert
descriptions.Should().HaveCount(4);
descriptions.Should().Contain("Chat type: private");
descriptions.Should().Contain("Chat type: group");
descriptions.Should().Contain("Chat type: supergroup");
descriptions.Should().Contain("Chat type: channel");
}
[Fact]
public void AllConstants_ShouldBeUsableInOrderByOperations()
{
// Arrange
var allTypes = new[]
{
ChatTypes.Channel,
ChatTypes.Private,
ChatTypes.SuperGroup,
ChatTypes.Group,
};
// Act
var orderedTypes = allTypes.OrderBy(t => t).ToArray();
// Assert
orderedTypes[0].Should().Be(ChatTypes.Channel);
orderedTypes[1].Should().Be(ChatTypes.Group);
orderedTypes[2].Should().Be(ChatTypes.Private);
orderedTypes[3].Should().Be(ChatTypes.SuperGroup);
}
[Fact]
public void AllConstants_ShouldBeUsableInGroupByOperations()
{
// Arrange
var typesWithDuplicates = new[]
{
ChatTypes.Private,
ChatTypes.Group,
ChatTypes.Private,
ChatTypes.SuperGroup,
ChatTypes.Channel,
ChatTypes.Group,
};
// Act
var groupedTypes = typesWithDuplicates
.GroupBy(t => t)
.ToDictionary(g => g.Key, g => g.Count());
// Assert
groupedTypes[ChatTypes.Private].Should().Be(2);
groupedTypes[ChatTypes.Group].Should().Be(2);
groupedTypes[ChatTypes.SuperGroup].Should().Be(1);
groupedTypes[ChatTypes.Channel].Should().Be(1);
}
}