text-matcher/tests/Nocr.TextMatcher.AppServices.UnitTests/TextSubscriptionTests.cs
Sergey Nazarov ced8c15efb DRAFT: nazarovsa/persistence (#2)
Reviewed-on: #2
Co-authored-by: Sergey Nazarov <insight.appdev@gmail.com>
Co-committed-by: Sergey Nazarov <insight.appdev@gmail.com>
2024-03-29 13:24:04 +00:00

69 lines
2.1 KiB
C#

using Nocr.TextMatcher.AppServices.TextMatches;
using Nocr.TextMatcher.Contracts;
using Xunit;
namespace Nocr.TextMatcher.AppServices.UnitTests;
public class TextSubscriptionTests
{
private const long UserId = 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 = TextSubscription.Initialize(UserId, "Барахолка", "велосипед", TextSubscriptionRule.Full, CreatedDateTime);
var text = "Продам снежный велосипед 100 лари. Гудаури.";
// Act
var result = match.IsMatches("Барахолка", text);
// Assert
Assert.True(result);
}
[Fact]
public void IsMatches_SameChatId_AnyWord_MatchesText()
{
// Arrange
var match = TextSubscription.Initialize(UserId, "Барахолка", "iphone айфон", TextSubscriptionRule.AnyWord,
CreatedDateTime);
var text = "Продам айфон велосипед 100 лари. Гудаури.";
// Act
var result = match.IsMatches("Барахолка", text);
// Assert
Assert.True(result);
}
[Fact]
public void IsMatches_SameChatId_AllWords_MatchesText()
{
// Arrange
var match = TextSubscription.Initialize(UserId, "Барахолка", "iphone айфон", TextSubscriptionRule.AnyWord,
CreatedDateTime);
var text = "Гомарджоба. Продам iphone (айфон) 1000 лари. Гудаури.";
// Act
var result = match.IsMatches("Барахолка", text);
// Assert
Assert.True(result);
}
[Fact]
public void IsMatches_DifferentChatIdAndUserName_NotMatchesText()
{
// Arrange
var match = TextSubscription.Initialize(UserId, "Барахолка", "iphone", TextSubscriptionRule.Full, CreatedDateTime);
// Act
var result = match.IsMatches(string.Empty, "iphone");
// Assert
Assert.False(result);
}
}