Пример #1
0
        public void Constructor()
        {
            var accounts = new List <string> {
                "Account1", "Account2"
            };

            var target = new AccountsCard(accounts);

            target.Buttons.Should().HaveCount(2);
            target.Buttons[0].Title.Should().Be("Account1");
            target.Buttons[0].Type.Should().Be(ActionTypes.ImBack);
            target.Buttons[0].Value.Should().Be("Account1");
            target.Buttons[1].Title.Should().Be("Account2");
            target.Buttons[1].Type.Should().Be(ActionTypes.ImBack);
            target.Buttons[1].Value.Should().Be("Account2");
        }
Пример #2
0
        public virtual async Task SelectAccountAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            context.UserData.TryGetValue("userData", out UserData data);

            var resultService = await this.profileService.GetAccounts(data.User.Token, data.User.Id);

            var accounts = resultService.ToDictionary(a => a.AccountId.ToString(), a => a.AccountName);

            data.User.Accounts = accounts;

            context.UserData.SetValue("userData", data);

            var reply = context.MakeMessage();

            if (!accounts.Any())
            {
                reply.Text = Labels.NoAccounts;

                await context.PostAsync(reply);

                context.Done(reply);
                return;
            }

            var accountsCard = new AccountsCard(accounts);

            reply.Text = Labels.ConnectToAccount;
            reply.Attachments.Add(accountsCard.ToAttachment());

            await context.PostAsync(reply);

            context.Wait(this.AccountReceivedAsync);
        }