text-matcher/tests/Nocr.TextMatcher.AppServices.UnitTests/TextMatchTests.cs
Sergey Nazarov 2692f549f4 Add rebus (#1)
Reviewed-on: #1
Co-authored-by: Sergey Nazarov <insight.appdev@gmail.com>
Co-committed-by: Sergey Nazarov <insight.appdev@gmail.com>
2024-03-21 18:57:29 +00:00

68 lines
2.0 KiB
C#

using Nocr.TextMatcher.AppServices.Contracts.TextMatches;
using Nocr.TextMatcher.AppServices.TextMatches;
using Xunit;
namespace Nocr.TextMatcher.AppServices.UnitTests;
public class TextMatchTests
{
private const long UserId = 1;
private const long ChatId = 1;
private static DateTimeOffset CreatedDateTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);
[Fact]
public void IsMatches_SameChatId_FullRule_MatchesText()
{
// Arrange
var match = TextMatch.Initialize(UserId, ChatId, "велосипед", TextMatchRule.Full, CreatedDateTime);
var text = "Продам снежный велосипед 100 лари. Гудаури.";
// Act
var result = match.IsMatches(ChatId, text);
// Assert
Assert.True(result);
}
[Fact]
public void IsMatches_SameChatId_AnyWord_MatchesText()
{
// Arrange
var match = TextMatch.Initialize(UserId, ChatId, "iphone айфон", TextMatchRule.AnyWord, CreatedDateTime);
var text = "Продам айфон велосипед 100 лари. Гудаури.";
// Act
var result = match.IsMatches(ChatId, text);
// Assert
Assert.True(result);
}
[Fact]
public void IsMatches_SameChatId_AllWords_MatchesText()
{
// Arrange
var match = TextMatch.Initialize(UserId, ChatId, "iphone айфон", TextMatchRule.AnyWord, CreatedDateTime);
var text = "Гомарджоба. Продам iphone (айфон) 1000 лари. Гудаури.";
// Act
var result = match.IsMatches(ChatId, text);
// Assert
Assert.True(result);
}
[Fact]
public void IsMatches_DifferentChatId_NotMatchesText()
{
// Arrange
var match = TextMatch.Initialize(UserId, ChatId, "iphone", TextMatchRule.Full, CreatedDateTime);
// Act
var result = match.IsMatches(ChatId, string.Empty);
// Assert
Assert.False(result);
}
}