text-matcher/tests/Nocr.TextMatcher.AppServices.UnitTests/TextMatchTests.cs
2024-03-26 10:13:53 +03:00

70 lines
2.2 KiB
C#

using Nocr.TextMatcher.Api.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, "Барахолка", "велосипед", TextMatchRule.Full, CreatedDateTime, ChatId);
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, "Барахолка", "iphone айфон", TextMatchRule.AnyWord,
CreatedDateTime, ChatId);
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, "Барахолка", "iphone айфон", TextMatchRule.AnyWord,
CreatedDateTime, ChatId);
var text = "Гомарджоба. Продам iphone (айфон) 1000 лари. Гудаури.";
// Act
var result = match.IsMatches(ChatId, "Барахолка", text);
// Assert
Assert.True(result);
}
[Fact]
public void IsMatches_DifferentChatIdAndUserName_NotMatchesText()
{
// Arrange
var match = TextMatch.Initialize(UserId, "Барахолка", "iphone", TextMatchRule.Full, CreatedDateTime, ChatId);
// Act
var result = match.IsMatches(0, string.Empty, "iphone");
// Assert
Assert.False(result);
}
}