public static string ToFullLocationString(this GeoCity geoCity)
        {
            string cityName          = geoCity != null ? geoCity.Name : String.Empty;
            string stateAbbreviation = geoCity != null && geoCity.GeoState != null ? geoCity.GeoState.Abbreviation : String.Empty;
            string countryName       = geoCity != null && geoCity.GeoState != null && geoCity.GeoState.GeoCountry != null ? geoCity.GeoState.GeoCountry.Name : String.Empty;

            return(ToFullLocationString(cityName, stateAbbreviation, countryName));
        }
        public async Task GetGeoCity_ShouldReturnGeoCityDetails()
        {
            // Arrange
            var id      = 1;
            var geoCity = new GeoCity {
                CityName = "Belrose"
            };

            Mock.Mock <IGeoLocationService>().Setup(x => x.GetGeoCity(id)).ReturnsAsync(geoCity);

            // Act
            var results = await Controller.GetGeoCity(id);

            // Assert
            Assert.That(results, Is.Not.Null);
            Assert.That(results, Is.TypeOf <OkNegotiatedContentResult <GeoCityViewModel> >());
            var content = ((OkNegotiatedContentResult <GeoCityViewModel>)results).Content;

            Assert.That(content.CityName, Is.EqualTo(geoCity.CityName));
        }
Beispiel #3
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;
            var E        = activity.Entities;

            if (E != null && E.Count > 0)
            {
                var lat = double.Parse(E[0].Properties["geo"]["latitude"].ToString());
                var lng = double.Parse(E[0].Properties["geo"]["longitude"].ToString());
                var res = GeoCity.GetClosestCities(Cities, lat, lng);

                if (res.Length <= 0)
                {
                    await context.PostAsync("Городов не найдено. Попробуйте ещё раз.");

                    context.Wait(MessageReceivedAsync);
                }
                else if (res.Length == 1)
                {
                    context.Done(res[0].Name);
                }
                else
                {
                    context.Call(new ClarifyDialog("Уточните город", res.Select(x => x.Name)), async(ctx, aw) =>
                    {
                        var r = await aw;
                        if (r == "")
                        {
                            ctx.Wait(MessageReceivedAsync);
                        }
                        else
                        {
                            ctx.Done(r);
                        }
                    });
                }
            } // end geoposition attached
            else
            {
                var res = GeoCity.GetSimilarCities(Cities, activity.Text);
                if (res == null || res.Length == 0)
                {
                    await context.PostAsync("Городов не найдено. Попробуйте ещё раз.");

                    context.Wait(MessageReceivedAsync);
                }
                else if (res.Length == 1)
                {
                    context.Done(res[0].Name);
                }
                else if (res.Length > 5)
                {
                    await context.PostAsync("Слишком много вариантов. Уточните.");

                    context.Wait(MessageReceivedAsync);
                }
                else
                {
                    context.Call(new ClarifyDialog("Уточните город", res.Select(x => x.Name)), async(ctx, aw) =>
                    {
                        var r = await aw;
                        if (r == "")
                        {
                            await ctx.PostAsync("Введите город");
                            ctx.Wait(MessageReceivedAsync);
                        }
                        else
                        {
                            ctx.Done(r);
                        }
                    });
                }
            }
        }