Пример #1
0
        public void GetGyms_Should_ReturnSingleMatch(string searchTerm, string groupName)
        {
            var results = GymApi.GetGyms(searchTerm, groupName);

            results.Should()
            .NotBeNullOrEmpty()
            .And
            .SatisfyRespectively(result => result.Should().BeEquivalentTo(FREE_LITTLE_LIBRARY));
        }
Пример #2
0
        public void GetGyms_ShouldReturnMultipleMatches(string searchTerm, string groupName)
        {
            var results = GymApi.GetGyms(searchTerm, groupName);

            results.Should()
            .NotBeNullOrEmpty()
            .And
            .SatisfyRespectively(
                resultA => resultA.Should().BeEquivalentTo(HEIGHTS_LIBRARY),
                resultB => resultB.Should().BeEquivalentTo(SCHOOLHOUSE)
                );
        }
Пример #3
0
        private static async Task HandleWhereIsInvocation(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            Regex whereIsRegex = new Regex($"^!whereis \"?([^\"]+)\"?$", RegexOptions.IgnoreCase);
            Match gymNameMatch = whereIsRegex.Match(turnContext.Activity.Text);
            var   searchTerm   = (gymNameMatch.Success && gymNameMatch.Groups.Count >= 2) ? gymNameMatch.Groups[1].Value : "";

            if (string.IsNullOrEmpty(searchTerm))
            {
                await turnContext.SendActivityAsync(MessageFactory.Text(Constants.WhereisNoGymNameMessage), cancellationToken);
            }
            else
            {
                var gymMatches = GymApi.GetGyms(searchTerm, VariableResources.GroupName, 3);
                if (gymMatches.Any())
                {
                    if (gymMatches.Count > 1)
                    {
                        await turnContext.SendActivityAsync(MessageFactory.Text($"I found more than one gym with names similar to \"{searchTerm}\":"), cancellationToken);
                    }
                    foreach (var gym in gymMatches)
                    {
                        var messageText = $"Here's the location of {gym.Name}.";
                        if (gym.Territory.Any(groupName => !groupName.Equals(VariableResources.GroupName)))
                        {
                            messageText += gym.Territory.Any(name => name.Equals(VariableResources.GroupName)) ?
                                           " It's " :
                                           " It's outside this group's territory, ";
                            messageText += $"in an area where the {gym.Territory.CommaSeparateWithAnd()} {(gym.Territory.Count() == 1 ? "group raids" : "groups may raid")}.";
                        }
                        if (gym.IsEXEligible)
                        {
                            messageText += " It's an EX Raid eligible gym!";
                        }

                        #region - This is a temporary hack to send the Location attachment while waiting for a fix for https://github.com/microsoft/BotFramework-Services/issues/101
                        var botId   = VariableResources.GroupMeBotId;
                        var message = JObject.FromObject(new
                        {
                            text        = messageText,
                            bot_id      = botId,
                            attachments = new[] {
                                new GroupMeLocationAttachment
                                {
                                    Latitude  = gym.Location.Latitude,
                                    Longitude = gym.Location.Longitude,
                                    Name      = gym.Name
                                }
                            }
                        });

                        if (!string.IsNullOrEmpty(botId))
                        {
                            var messageJson = new StringContent(message.ToString(), Encoding.UTF8, "application/json");
                            _ = httpClient.PostAsync("v3/bots/post", messageJson);
                        }
                        else if (turnContext.Activity.ChannelId == "emulator")
                        {
                            await turnContext.SendActivityAsync(MessageFactory.Text("Unable to send attachment via emulator. Message content below:"));

                            await turnContext.SendActivityAsync(MessageFactory.Text(message.ToString()));
                        }
                        #endregion
                        if (!string.IsNullOrEmpty(gym.Description))
                        {
                            await turnContext.SendActivityAsync(MessageFactory.Text(gym.Description), cancellationToken);
                        }
                    }
                    if (gymMatches.Count > 1)
                    {
                        await turnContext.SendActivityAsync(MessageFactory.Text($"If I didn't find what you were looking for, feel free to try again with a different search term."), cancellationToken);
                    }
                }
                else
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text($"Sorry, but I couldn't find a gym called \"{searchTerm}\"."), cancellationToken);
                }
            }
        }
Пример #4
0
        public void GetGyms_Should_ReturnNoMatches()
        {
            var results = GymApi.GetGyms("A string which does not match any gym name", "Near East Side");

            results.Should().BeEmpty("because the search term should not match any gym name");
        }