Esempio n. 1
0
        private async Task <SkillResponse> SearchForTrips(Destination start, Destination end)
        {
            context.Logger.LogLine($"Start search for {start} -> {end}");

            await progResponse.SendSpeech(
                string.Format(Properties.Speech.SearchingForTrips, start.Name, end.Name)
                );

            // get correct time for user's timezone
            var instant  = SystemClock.Instance.GetCurrentInstant();
            var timezone = await settingsClient.TimeZone();

            var zone = DateTimeZoneProviders.Tzdb[timezone];
            var time = instant.InZone(zone)
                       .ToDateTimeUnspecified();

            var trips = (await searcher.SearchForTripsAsync(start.Name, end.Name, time))
                        .OrderBy(t => t.StartTime)
                        .ThenBy(t => t.Duration)
                        .ToList();

            context.Logger.LogLine($"Finish search for {start} -> {end}: Found {trips.Count()}, Best: {trips.FirstOrDefault()}");

            if (trips.Any())
            {
                var bestTrip = trips.First();
                return(ResponseBuilder.TellWithCard(
                           string.Format(Properties.Speech.FoundBestTrip,
                                         bestTrip.StartLocation, bestTrip.EndLocation,
                                         bestTrip.StartTime.ToString("HH:mm"),
                                         bestTrip.Provider),
                           string.Format(Properties.Speech.FoundTripsTitle,
                                         bestTrip.StartLocation,
                                         bestTrip.EndLocation),
                           BuildTripsCard(trips)
                           ));
            }
            else
            {
                return(ResponseBuilder.TellWithCard(
                           string.Format(Properties.Speech.NoTripsFound, start.Name, end.Name),
                           string.Format(Properties.Speech.NoTripsFound, start.Name, end.Name),
                           ""
                           ));
            }
        }
Esempio n. 2
0
        public async Task GetTimeZoneGeneratesCorrectRequest()
        {
            const string expectedResult = "Africa/Abidjan";
            string       fullNamePath   = $"/v2/devices/{DeviceId}/settings/System.timeZone";
            var          runHandler     = false;
            var          httpClient     = new HttpClient(new ActionMessageHandler(req =>
            {
                runHandler = true;
                Assert.Equal(req.RequestUri.PathAndQuery, fullNamePath);
                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)
                {
                    Content = new StringContent(Utility.GetExampleJson("TimeZone.json"))
                });
            }))
            {
                BaseAddress = new Uri("https://testclient.com", UriKind.Absolute)
            };

            var client     = new SettingsClient(httpClient, DeviceId);
            var nameResult = await client.TimeZone();

            Assert.True(runHandler);
            Assert.Equal(expectedResult, nameResult);
        }