예제 #1
0
        public async Task QueryByTelegramUsername()
        {
            var backendService   = Substitute.For <IBackendService>();
            var minetokenService = Substitute.For <IMinetokenService>();
            var userService      = Substitute.For <IUserService>();
            var matatakiService  = Substitute.For <IMatatakiService>();

            userService.GetIdByUsernameAsync("inm").Returns(1);
            backendService.GetUserByTelegramIdAsync(1).Returns(new UserInfo()
            {
                Id            = 1,
                Name          = "User",
                WalletAddress = "0x1919",
            });
            backendService.GetTokenAsync("INM").Returns(new TokenInfo()
            {
                Id              = 1919,
                Name            = "银票",
                ContractAddress = "0x114514",
            });
            minetokenService.GetBalanceAsync("0x114514", "0x1919").Returns(11.4514m);
            matatakiService.GetTokenPageUrl(Arg.Any <int>()).Returns(info => "https://matataki/token/" + info[0]);

            var command = new QueryCommand(backendService, minetokenService, userService, matatakiService);

            var response = command.QueryByTelegramUsername(new Message(), "inm", "INM").GetAsyncEnumerator();

            Assert.True(await response.MoveNextAsync());
            Assert.Equal("查询中……", response.Current.Content);

            Assert.True(await response.MoveNextAsync());
            Assert.Equal("11.4514 [INM](https://matataki/token/1919)", response.Current.Content);

            Assert.False(await response.MoveNextAsync());
        }