Beispiel #1
0
        protected override string GetAnswer(DialogContext context)
        {
            GetConnectedClients getConnectedClients = context.GetItem <GetConnectedClients>();

            if (getConnectedClients == null)
            {
                return("Я не знаю.");
            }

            string[] clients = getConnectedClients();
            if (clients.Length == 0)
            {
                return("Нет присоединенных пользователей в чате.");
            }

            var names            = clients.Where(n => !string.IsNullOrWhiteSpace(n));
            int anonClientsCount = clients.Count(n => string.IsNullOrWhiteSpace(n));

            if (anonClientsCount > 0)
            {
                string anons = (anonClientsCount == 1
          ? "1 анонимный пользователь"
          : $"{anonClientsCount} анонимных пользователя");

                names = names.Concat(new[] { anons });
            }
            return("\n" + string.Join('\n', names.Select(n => " - " + n)));
        }
Beispiel #2
0
        protected override string GetPhrase(DialogContext context)
        {
            ClientName clientName = context.GetItem <ClientName>();

            return(clientName != null && !clientName.IsAnonymous ?
                   $"Пока, {clientName.Value}!" :
                   "Пока!");
        }
Beispiel #3
0
        public void TestAsking(string response, string expectedName)
        {
            WhatsYourName dialogUnit = new WhatsYourName();
            DialogContext context    = new DialogContext();

            DialogUnitTestUtils.TestInitiating(dialogUnit, context, "Как тебя зовут?", response);
            ClientName clientName = context.GetItem <ClientName>();

            Assert.NotNull(clientName);
            Assert.Equal(expectedName, clientName.Value);
        }
Beispiel #4
0
        protected override string GetStatement(DialogContext context)
        {
            ClientName clientName = context.GetItem <ClientName>();
            bool       hasName    = clientName != null && !clientName.IsAnonymous;
            string     pre        = hasName ? $"{clientName.Value}, ты" : "Ты";

            return($@"{pre} можешь спросить меня:
 - Как меня зовут
 - Как дела
 - Сколько сейчас времени
 - Список пользователей в чате");
        }