Skip to content

Commit

Permalink
Merge branch 'beta/2.0' into polling-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
voed authored Oct 31, 2023
2 parents 6a84e6d + cbf4589 commit 21ab75e
Show file tree
Hide file tree
Showing 20 changed files with 475 additions and 563 deletions.
126 changes: 10 additions & 116 deletions TGBotFramework/BotFramework.Tests/Attributes/CommandAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public class CommandAttributeTest
[Fact]
public void CanFilterUserName()
{
var commandInChat = new ParametrizedCommandAttribute(InChat.All,"test", CommandParseMode.Both);
var commandInChat = new ParametrizedCommandAttribute("test", CommandParseMode.Both);
var command = new ParametrizedCommandAttribute("test", CommandParseMode.Both);

var message = new Message
{
{
Chat = new Chat() { Type = ChatType.Group },
Text = "/test@testbot",
Entities = new MessageEntity[]
Expand All @@ -44,13 +44,13 @@ public void CanFilterUserName()
Assert.True(commandInChat.CanHandleInternal(paramses));
Assert.True(command.CanHandleInternal(paramses));

commandInChat = new ParametrizedCommandAttribute(InChat.All,"test", CommandParseMode.WithUsername);
commandInChat = new ParametrizedCommandAttribute("test", CommandParseMode.WithUsername);
command = new ParametrizedCommandAttribute("test", CommandParseMode.WithUsername);

Assert.True(commandInChat.CanHandleInternal(paramses));
Assert.True(command.CanHandleInternal(paramses));

commandInChat = new ParametrizedCommandAttribute(InChat.All,"test", CommandParseMode.WithoutUsername);
commandInChat = new ParametrizedCommandAttribute("test", CommandParseMode.WithoutUsername);
command = new ParametrizedCommandAttribute("test", CommandParseMode.WithoutUsername);

Assert.False(commandInChat.CanHandleInternal(paramses));
Expand All @@ -73,11 +73,11 @@ public void CanFilterUserName()
[Fact]
public void CanHandleInCaption()
{
var command = new ParametrizedCommandAttribute("test");
var command = new ParametrizedCommandAttribute("test", TextContent.Caption);
var paramses = new HandlerParams(null, new Update
{
{
Message = new Message
{
{
Chat = new Chat() { Type = ChatType.Group },
Caption = "/test"
,
Expand All @@ -101,8 +101,9 @@ public void CanHandleInCaption()
public void CanHandleByText()
{
var command = new ParametrizedCommandAttribute("test");
var paramses = new HandlerParams(null, new Update { Message = new Message
{
var paramses = new HandlerParams(null, new Update
{ Message = new Message
{
Chat = new Chat() { Type = ChatType.Group },
Text = "/test"
,
Expand Down Expand Up @@ -141,112 +142,5 @@ public void CanHandleByTextWithUsername()
Assert.True(command.CanHandleInternal(paramses));
}

[Fact]
public void CanHandleInChannel()
{
var command = new ParametrizedCommandAttribute(InChat.Channel, "test");
var update = new Update
{
Message = new Message
{
Text = "/test@testbot",
Chat = new Chat { Type = ChatType.Channel },
Entities = new MessageEntity[]
{
new MessageEntity()
{
Length = 5, Offset = 0, Type = MessageEntityType.BotCommand
}
}
}
};

var paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(command.CanHandleInternal(paramses));

update.Message.Chat.Type = ChatType.Group;
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(command.CanHandleInternal(paramses));

update.Message.Chat.Type = ChatType.Supergroup;
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(command.CanHandleInternal(paramses));

update.Message.Chat.Type = ChatType.Private;
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(command.CanHandleInternal(paramses));
}

[Fact]
public void CanHandleInPrivateChat()
{
var command = new ParametrizedCommandAttribute(InChat.Private, "test");
var update = new Update
{
Message = new Message
{
Text = "/test@testbot",
Chat = new Chat { Type = ChatType.Channel },
Entities = new MessageEntity[]
{
new MessageEntity()
{
Length = 5, Offset = 0, Type = MessageEntityType.BotCommand
}
}
}
};

var paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(command.CanHandleInternal(paramses));

update.Message.Chat.Type = ChatType.Group;
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(command.CanHandleInternal(paramses));

update.Message.Chat.Type = ChatType.Supergroup;
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(command.CanHandleInternal(paramses));

update.Message.Chat.Type = ChatType.Private;
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(command.CanHandleInternal(paramses));
}

[Fact]
public void CanHandleInPublicChat()
{
var command = new ParametrizedCommandAttribute(InChat.Public, "test");
var update = new Update
{
Message = new Message
{
Text = "/test@testbot",
Chat = new Chat { Type = ChatType.Channel },
Entities = new MessageEntity[]
{
new MessageEntity()
{
Length = 5, Offset = 0, Type = MessageEntityType.BotCommand
}
}
}
};

var paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(command.CanHandleInternal(paramses));

update.Message.Chat.Type = ChatType.Group;
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(command.CanHandleInternal(paramses));

update.Message.Chat.Type = ChatType.Supergroup;
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(command.CanHandleInternal(paramses));

update.Message.Chat.Type = ChatType.Private;
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(command.CanHandleInternal(paramses));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public void CanHandleMultiContent()
}

[Fact]
public void CanHandleCaptionMessages()
public void CanHandleCaptionTextMessages()
{
var paramses = new HandlerParams(null, new Update { Message = new Message { Caption = "Blah", Voice = new Voice() } },
_serviceProvider, "testbot", _userProvider);

var attribute = new MessageAttribute(MessageFlag.HasCaption);
var attribute = new TextMessageAttribute(TextContent.Caption);

Assert.True(attribute.CanHandleInternal(paramses));

attribute = new MessageAttribute("Foo");
attribute = new TextMessageAttribute("Foo", TextContent.Caption);
Assert.False(attribute.CanHandleInternal(paramses));

attribute = new MessageAttribute("/test");
attribute = new TextMessageAttribute("/test", TextContent.Caption);
Assert.False(attribute.CanHandleInternal(paramses));
}

Expand Down
136 changes: 1 addition & 135 deletions TGBotFramework/BotFramework.Tests/Attributes/UpdateAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,140 +38,6 @@ public void CanHandleFlags()
paramses = new HandlerParams(null, new Update(), _serviceProvider, "test", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));
}

[Fact]
public void CanHandleInChannel()
{
var updateAttr = new UpdateAttribute { InChatFlags = InChat.Channel };

var chat = new Chat { Type = ChatType.Channel };
var update = new Update {Message = new Message { Text = "Blah", Chat = chat } };

var paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Group};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Private};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Supergroup};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(updateAttr.CanHandleInternal(paramses));
}

[Fact]
public void CanHandleInPrivate()
{
var updateAttr = new UpdateAttribute { InChatFlags = InChat.Private };

var chat = new Chat { Type = ChatType.Channel };
var update = new Update {Message = new Message { Text = "Blah", Chat = chat } };

var paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Group};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Private};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Supergroup};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(updateAttr.CanHandleInternal(paramses));
}

[Fact]
public void CanHandleInPublic()
{
var updateAttr = new UpdateAttribute { InChatFlags = InChat.Public };

var chat = new Chat { Type = ChatType.Channel };
var update = new Update {Message = new Message { Text = "Blah", Chat = chat } };

var paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Group};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Private};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Supergroup};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));
}

[Fact]
public void CanHandleInPublicAndPrivate()
{
var updateAttr = new UpdateAttribute { InChatFlags = InChat.Public | InChat.Private };

var chat = new Chat { Type = ChatType.Channel };
var update = new Update { Message = new Message { Text = "Blah", Chat = chat } };

var paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.False(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Group };
update = new Update { Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Private };
update = new Update { Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Supergroup };
update = new Update { Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));
}

[Fact]
public void CanHandleAll()
{
var updateAttr = new UpdateAttribute { InChatFlags = InChat.All };

var chat = new Chat { Type = ChatType.Channel };
var update = new Update {Message = new Message { Text = "Blah", Chat = chat } };

var paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Group};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Private};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));

chat = new Chat { Type = ChatType.Supergroup};
update = new Update {Message = new Message { Text = "Blah", Chat = chat } };
paramses = new HandlerParams(null, update, _serviceProvider, "testbot", _userProvider);
Assert.True(updateAttr.CanHandleInternal(paramses));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override int GetHashCode()
#endif
}

public override bool Equals(object? obj)
public override bool Equals(object obj)
{
if(obj is BotUser another)
{
Expand Down
Loading

0 comments on commit 21ab75e

Please sign in to comment.