private string HandleAmILateIntent()
        {
            var apiResult = _septaClient.GetNextToArriveFromHomeToDestinationAsync().GetAwaiter().GetResult();

            // the trains in apiResult may not have been ordered by the original departure time
            // sort apiResult before iterating.

            var nextToArriveList = new List <TrainInfo>();

            foreach (var trainInApiResult in apiResult)
            {
                var temp = new TrainInfo();
                temp.MapFrom(trainInApiResult);
                nextToArriveList.Add(temp);
            }

            return(_speechGenerator.GenerateSpeechForAlexa(nextToArriveList, DateTime.UtcNow));
        }
示例#2
0
        public void WhenIsLateForTrain_ShouldGenerateExpectedSpeech()
        {
            //Given
            IList <NextToArriveTrainDto> apiReturnedResult = new List <NextToArriveTrainDto>()
            {
                new NextToArriveTrainDto()
                {
                    OriginalDelay         = "On Time",
                    OriginalDepartureTime = "5:25PM"
                },
                new NextToArriveTrainDto()
                {
                    OriginalDelay         = "3 mins",
                    OriginalDepartureTime = "5:15PM"
                }
            };

            var arrivingTrainList = new List <TrainInfo>();

            foreach (var trainsDto in apiReturnedResult)
            {
                var tmp = new TrainInfo();
                tmp.MapFrom(trainsDto);
                arrivingTrainList.Add(tmp);
            }
            //When
            var speechGenerator = new SpetaSpeechGenerator(new BoringAlexaSpeakStrategy());
            //Then
            var speech = speechGenerator.GenerateSpeechForAlexa(arrivingTrainList, DateTime.Parse("5:13PM").ToUniversalTime());

            var expectedSpeech = "5:15 Train is delayed by 3 minutes and is leaving in 5 minutes." +
                                 " You are not going to make it. Consider taking the next one." +
                                 " 5:25 Train is ontime and is leaving in 12 minutes.";


            Assert.Equal(expectedSpeech, speech);
        }